- Timestamp:
- 08/05/07 13:12:10 (1 year ago)
- Files:
-
- asycamore/trunk/asycamore/exc_string.py (modified) (2 diffs)
- asycamore/trunk/asycamore/httpservicecontext.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
asycamore/trunk/asycamore/exc_string.py
r733 r789 71 71 return result 72 72 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]) ]) 73 def 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 ] 76 77 77 def exc_string(einfo=None): 78 def trace_string(tb = None, framejoin=' <= '): 79 return framejoin.join(trace_strings(tb)) 78 80 81 def exc_fmt(einfo, fmt, framejoin): 79 82 try: 80 81 83 t, v, tb = einfo or exc_info() 82 84 if t is None: … … 90 92 else: 91 93 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" 92 100 93 return "%s(\"%s\") in %s" % (t, v, trace_string(extract_tb(tb))) 101 def exc_lines(einfo=None, 102 fmt='%(name)s "%(value)s\n ^ %(trace)s', framejoin='\n ^ ' 103 ): 104 return exc_fmt(einfo, fmt, framejoin) 94 105 95 except: 96 return "exc_string() failed to extract exception string" 106 107 def exc_oneline(einfo=None, 108 fmt='%(name)s "%(value)s :=>\n => %(trace)s', framejoin=' => ' 109 ): 110 return exc_fmt(einfo, fmt, framejoin) 111 112 exc_string = exc_oneline 97 113 # EOF asycamore/trunk/asycamore/httpservicecontext.py
r741 r789 7 7 import asycamore.requestresponse as requestresponse 8 8 import asycamore.wsgienviron as wsgienviron 9 import asycamore.wsgistreams as wsgistreams10 9 11 10 log = logging.getLogger(__name__) … … 17 16 statuscode = int(status[:3]) 18 17 18 sentinels = ( 19 environ['asycamore.read_sentinel'], 20 environ['asycamore.write_sentinel'], 21 environ['asycamore.deferred_sentinel'] 22 ) 23 19 24 response_protocol = environ.pop('RESPONSE_PROTOCOL') 20 25 … … 24 29 close_connection = environ.get('asycamore.close_connection', False) 25 30 31 te_response_chunked = False 26 32 if statuscode == 413: 27 33 # Request Entity Too Large. Close conn to avoid garbage. … … 37 43 if response_protocol == 'HTTP/1.1': 38 44 # Use the chunked transfer-coding 39 environ['asycamore.te_response_chunked'] = True 45 te_response_chunked = environ[ 46 'asycamore.te_response_chunked'] = True 40 47 response_headers.append( 41 ("Transfer-Encoding", "chunked")) 48 ("Transfer-Encoding", "chunked") 49 ) 42 50 else: 43 51 # Closing the conn is the only way to determine len. … … 50 58 + ['%s: %s\r\n' % h for h in response_headers] 51 59 + ['\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 54 78 55 79 … … 250 274 251 275 statuslinecrlf, headerdatacrlfcrlf, d = v 276 log.debug(statuslinecrlf[:-2]) 277 252 278 assert not self.pending_read 253 279 self.pending_read = d 254 280 255 environ = { }281 environ = {'wsgi.url_scheme':'http'} 256 282 result = wsgienviron.populate_server_environ( 257 283 environ, … … 275 301 False) 276 302 303 environ['asycamore.servicemodel'] = self.model 277 304 environ['asycamore.response_headers'] = response_headers 278 305 environ['asycamore.read_sentinel'] = self.read_sentinel 306 environ['asycamore.write_sentinel'] = self.write_sentinel 279 307 environ['asycamore.deferred_sentinel'] = self.deferred_sentinel 280 308 environ['asycamore.thread_delegate'] = self.thread_delegate … … 487 515 def wsgi_a_tardy_response(cls, environ, start_response): 488 516 489 import time,random517 import random 490 518 491 519 cls.default_app_ctr += 1