Changeset 391 for python/trunk/Lib/wsgiref
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/wsgiref/handlers.py
r2 r391 40 40 41 41 42 43 42 class BaseHandler: 44 43 """Manage the invocation of a WSGI application""" … … 65 64 # Error handling (also per-subclass or per-instance) 66 65 traceback_limit = None # Print entire traceback to self.get_stderr() 67 error_status = "500 Dude, this is whack!"66 error_status = "500 Internal Server Error" 68 67 error_headers = [('Content-Type','text/plain')] 69 68 error_body = "A server error occurred. Please contact the administrator." … … 74 73 headers = None 75 74 bytes_sent = 0 76 77 78 79 80 81 82 83 75 84 76 def run(self, application): … … 131 123 'self.close()' once the response is finished. 132 124 """ 133 if not self.result_is_file() or not self.sendfile(): 134 for data in self.result: 135 self.write(data) 136 self.finish_content() 137 self.close() 125 try: 126 if not self.result_is_file() or not self.sendfile(): 127 for data in self.result: 128 self.write(data) 129 self.finish_content() 130 finally: 131 self.close() 138 132 139 133 … … 161 155 Subclasses can extend this to add other defaults. 162 156 """ 163 if not self.headers.has_key('Content-Length'):157 if 'Content-Length' not in self.headers: 164 158 self.set_content_length() 165 159 … … 196 190 if self.client_is_modern(): 197 191 self._write('HTTP/%s %s\r\n' % (self.http_version,self.status)) 198 if not self.headers.has_key('Date'):192 if 'Date' not in self.headers: 199 193 self._write( 200 194 'Date: %s\r\n' % format_date_time(time.time()) 201 195 ) 202 if self.server_software and not self.headers.has_key('Server'):196 if self.server_software and 'Server' not in self.headers: 203 197 self._write('Server: %s\r\n' % self.server_software) 204 198 else: … … 249 243 """Ensure headers and content have both been sent""" 250 244 if not self.headers_sent: 251 self.headers['Content-Length'] = "0" 245 # Only zero Content-Length if not set by the application (so 246 # that HEAD requests can be satisfied properly, see #3839) 247 self.headers.setdefault('Content-Length', "0") 252 248 self.send_headers() 253 249 else: … … 360 356 361 357 362 363 364 365 366 367 368 369 370 371 358 class SimpleHandler(BaseHandler): 372 359 """Handler that's just initialized with streams, environment, etc. … … 434 421 435 422 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 423 class CGIHandler(BaseCGIHandler): 454 424 … … 479 449 multithread=False, multiprocess=True 480 450 ) 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 # -
python/trunk/Lib/wsgiref/headers.py
r2 r391 26 26 else: 27 27 return param 28 29 30 31 32 33 34 35 36 37 38 39 40 28 41 29 … … 77 65 return self.get(name) 78 66 79 80 81 82 83 67 def has_key(self, name): 84 68 """Return true if the message contains the header.""" … … 118 102 """ 119 103 return [k for k, v in self._headers] 120 121 122 123 104 124 105 def values(self): … … 162 143 return result 163 144 164 165 145 def add_header(self, _name, _value, **_params): 166 146 """Extended header setting. … … 188 168 parts.append(_formatparam(k.replace('_', '-'), v)) 189 169 self._headers.append((_name, "; ".join(parts))) 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 # -
python/trunk/Lib/wsgiref/simple_server.py
r2 r391 38 38 39 39 40 41 42 40 class WSGIServer(HTTPServer): 43 41 … … 66 64 def set_app(self,application): 67 65 self.application = application 68 69 70 71 72 73 74 75 76 77 78 79 80 66 81 67 … … 140 126 141 127 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 128 def demo_app(environ,start_response): 166 129 from StringIO import StringIO … … 191 154 webbrowser.open('http://localhost:8000/xyz?abc') 192 155 httpd.handle_request() # serve one request, then exit 193 194 195 196 197 198 199 200 201 202 203 204 205 # 156 httpd.server_close() -
python/trunk/Lib/wsgiref/util.py
r2 r391 33 33 raise StopIteration 34 34 35 36 37 38 39 40 41 42 35 def guess_scheme(environ): 43 36 """Return a guess for whether 'wsgi.url_scheme' should be 'http' or 'https' … … 72 65 url = application_uri(environ) 73 66 from urllib import quote 74 path_info = quote(environ.get('PATH_INFO','') )67 path_info = quote(environ.get('PATH_INFO',''),safe='/;=,') 75 68 if not environ.get('SCRIPT_NAME'): 76 69 url += path_info[1:] … … 162 155 163 156 164 165 157 _hoppish = { 166 158 'connection':1, 'keep-alive':1, 'proxy-authenticate':1, … … 172 164 """Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header""" 173 165 return _hoppish(header_name.lower()) 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 # -
python/trunk/Lib/wsgiref/validate.py
r2 r391 135 135 middleware will check for WSGI compliancy on a number of levels. 136 136 This middleware does not modify the request or response in any 137 way, but will throwan AssertionError if anything seems off137 way, but will raise an AssertionError if anything seems off 138 138 (except for a failure to close the application iterator, which 139 will be printed to stderr -- there's no way to throwan exception139 will be printed to stderr -- there's no way to raise an exception 140 140 at that point). 141 141 """ … … 346 346 347 347 if not environ.get('SCRIPT_NAME'): 348 assert_( environ.has_key('PATH_INFO'),348 assert_('PATH_INFO' in environ, 349 349 "One of SCRIPT_NAME or PATH_INFO are required (PATH_INFO " 350 350 "should at least be '/' if SCRIPT_NAME is empty)")
Note:
See TracChangeset
for help on using the changeset viewer.