Changeset 789 for asycamore

Show
Ignore:
Timestamp:
08/05/07 13:12:10 (1 year ago)
Author:
robin
Message:

more exc_string facilities

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • asycamore/trunk/asycamore/exc_string.py

    r733 r789  
    7171    return result 
    7272 
    73 def trace_string(tb = None): 
    74     return " <- ".join([ force_string("%s() (%s:%s)" % (m, path.split(f)[1], n)) 
    75                          for f, n, m, u in _reversed(tb or extract_stack()[:-1]) ]) 
     73def trace_strings(tb = None): 
     74    return [ force_string("[%s() %s:%s]" % (m, path.split(f)[1], n)) 
     75        for f, n, m, u in _reversed(tb or extract_stack()[:-1]) 
     76        ] 
    7677 
    77 def exc_string(einfo=None): 
     78def trace_string(tb = None, framejoin=' <= '): 
     79    return framejoin.join(trace_strings(tb)) 
    7880 
     81def exc_fmt(einfo, fmt, framejoin): 
    7982    try: 
    80  
    8183        t, v, tb = einfo or exc_info() 
    8284        if t is None: 
     
    9092        else: 
    9193            t = type(t).__name__ 
     94        return fmt % dict( 
     95                name = t, value = v, 
     96                trace = trace_string(extract_tb(tb), framejoin=framejoin) 
     97                ) 
     98    except: 
     99        return "exc_fmt() failed to extract exception string" 
    92100 
    93         return "%s(\"%s\") in %s" % (t, v, trace_string(extract_tb(tb))) 
     101def exc_lines(einfo=None, 
     102        fmt='%(name)s "%(value)s\n ^ %(trace)s', framejoin='\n ^ ' 
     103        ): 
     104    return exc_fmt(einfo, fmt, framejoin) 
    94105 
    95     except: 
    96         return "exc_string() failed to extract exception string" 
     106 
     107def exc_oneline(einfo=None, 
     108        fmt='%(name)s "%(value)s :=>\n => %(trace)s', framejoin=' => ' 
     109        ): 
     110    return exc_fmt(einfo, fmt, framejoin) 
     111 
     112exc_string = exc_oneline 
    97113# EOF 
  • asycamore/trunk/asycamore/httpservicecontext.py

    r741 r789  
    77import asycamore.requestresponse as requestresponse 
    88import asycamore.wsgienviron as wsgienviron 
    9 import asycamore.wsgistreams as wsgistreams 
    109 
    1110log = logging.getLogger(__name__) 
     
    1716    statuscode = int(status[:3]) 
    1817 
     18    sentinels = ( 
     19        environ['asycamore.read_sentinel'], 
     20        environ['asycamore.write_sentinel'], 
     21        environ['asycamore.deferred_sentinel'] 
     22        ) 
     23 
    1924    response_protocol = environ.pop('RESPONSE_PROTOCOL') 
    2025 
     
    2429    close_connection = environ.get('asycamore.close_connection', False) 
    2530 
     31    te_response_chunked = False 
    2632    if statuscode == 413: 
    2733        # Request Entity Too Large. Close conn to avoid garbage. 
     
    3743            if response_protocol == 'HTTP/1.1': 
    3844                # Use the chunked transfer-coding 
    39                 environ['asycamore.te_response_chunked'] = True 
     45                te_response_chunked = environ[ 
     46                        'asycamore.te_response_chunked'] = True 
    4047                response_headers.append( 
    41                         ("Transfer-Encoding", "chunked")) 
     48                        ("Transfer-Encoding", "chunked") 
     49                        ) 
    4250            else: 
    4351                # Closing the conn is the only way to determine len. 
     
    5058            + ['%s: %s\r\n' % h for h in response_headers] 
    5159            + ['\r\n']) 
    52  
    53     return chain([statusheaderdata], response) 
     60    log.debug(statusheaderdata.replace('\r\n', '\\r\\n')) 
     61    if not te_response_chunked: 
     62        return chain([statusheaderdata], response) 
     63    else: 
     64        def response_chunker(): 
     65            yield statusheaderdata 
     66            for v in response: 
     67                if not v or v in sentinels: 
     68                    yield v 
     69                    continue 
     70                cl = len(v) 
     71                xcl = hex(cl)[2:].replace('L', '') 
     72                yield xcl + '\r\n' 
     73                yield v 
     74                yield '\r\n' 
     75            yield '0\r\n\r\n\r\n' # last chunk CRLF *(entity hdrs) CRLF 
     76        return response_chunker() 
     77 
    5478 
    5579 
     
    250274 
    251275        statuslinecrlf, headerdatacrlfcrlf, d = v 
     276        log.debug(statuslinecrlf[:-2]) 
     277 
    252278        assert not self.pending_read 
    253279        self.pending_read = d 
    254280 
    255         environ = {
     281        environ = {'wsgi.url_scheme':'http'
    256282        result = wsgienviron.populate_server_environ( 
    257283                environ, 
     
    275301                False) 
    276302 
     303        environ['asycamore.servicemodel'] = self.model 
    277304        environ['asycamore.response_headers'] = response_headers 
    278305        environ['asycamore.read_sentinel'] = self.read_sentinel 
     306        environ['asycamore.write_sentinel'] = self.write_sentinel 
    279307        environ['asycamore.deferred_sentinel'] = self.deferred_sentinel 
    280308        environ['asycamore.thread_delegate'] = self.thread_delegate 
     
    487515    def wsgi_a_tardy_response(cls, environ, start_response): 
    488516 
    489         import time, random 
     517        import random 
    490518 
    491519        cls.default_app_ctr += 1