Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/wsgiref/handlers.py

    r2 r391  
    4040
    4141
    42 
    4342class BaseHandler:
    4443    """Manage the invocation of a WSGI application"""
     
    6564    # Error handling (also per-subclass or per-instance)
    6665    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"
    6867    error_headers = [('Content-Type','text/plain')]
    6968    error_body = "A server error occurred.  Please contact the administrator."
     
    7473    headers = None
    7574    bytes_sent = 0
    76 
    77 
    78 
    79 
    80 
    81 
    82 
    8375
    8476    def run(self, application):
     
    131123        'self.close()' once the response is finished.
    132124        """
    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()
    138132
    139133
     
    161155        Subclasses can extend this to add other defaults.
    162156        """
    163         if not self.headers.has_key('Content-Length'):
     157        if 'Content-Length' not in self.headers:
    164158            self.set_content_length()
    165159
     
    196190            if self.client_is_modern():
    197191                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:
    199193                    self._write(
    200194                        'Date: %s\r\n' % format_date_time(time.time())
    201195                    )
    202                 if self.server_software and not self.headers.has_key('Server'):
     196                if self.server_software and 'Server' not in self.headers:
    203197                    self._write('Server: %s\r\n' % self.server_software)
    204198        else:
     
    249243        """Ensure headers and content have both been sent"""
    250244        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")
    252248            self.send_headers()
    253249        else:
     
    360356
    361357
    362 
    363 
    364 
    365 
    366 
    367 
    368 
    369 
    370 
    371358class SimpleHandler(BaseHandler):
    372359    """Handler that's just initialized with streams, environment, etc.
     
    434421
    435422
    436 
    437 
    438 
    439 
    440 
    441 
    442 
    443 
    444 
    445 
    446 
    447 
    448 
    449 
    450 
    451 
    452 
    453423class CGIHandler(BaseCGIHandler):
    454424
     
    479449            multithread=False, multiprocess=True
    480450        )
    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  
    2626    else:
    2727        return param
    28 
    29 
    30 
    31 
    32 
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    4028
    4129
     
    7765        return self.get(name)
    7866
    79 
    80 
    81 
    82 
    8367    def has_key(self, name):
    8468        """Return true if the message contains the header."""
     
    118102        """
    119103        return [k for k, v in self._headers]
    120 
    121 
    122 
    123104
    124105    def values(self):
     
    162143            return result
    163144
    164 
    165145    def add_header(self, _name, _value, **_params):
    166146        """Extended header setting.
     
    188168                parts.append(_formatparam(k.replace('_', '-'), v))
    189169        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  
    3838
    3939
    40 
    41 
    4240class WSGIServer(HTTPServer):
    4341
     
    6664    def set_app(self,application):
    6765        self.application = application
    68 
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    8066
    8167
     
    140126
    141127
    142 
    143 
    144 
    145 
    146 
    147 
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159 
    160 
    161 
    162 
    163 
    164 
    165128def demo_app(environ,start_response):
    166129    from StringIO import StringIO
     
    191154    webbrowser.open('http://localhost:8000/xyz?abc')
    192155    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  
    3333        raise StopIteration
    3434
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    4235def guess_scheme(environ):
    4336    """Return a guess for whether 'wsgi.url_scheme' should be 'http' or 'https'
     
    7265    url = application_uri(environ)
    7366    from urllib import quote
    74     path_info = quote(environ.get('PATH_INFO',''))
     67    path_info = quote(environ.get('PATH_INFO',''),safe='/;=,')
    7568    if not environ.get('SCRIPT_NAME'):
    7669        url += path_info[1:]
     
    162155
    163156
    164 
    165157_hoppish = {
    166158    'connection':1, 'keep-alive':1, 'proxy-authenticate':1,
     
    172164    """Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header"""
    173165    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  
    135135    middleware will check for WSGI compliancy on a number of levels.
    136136    This middleware does not modify the request or response in any
    137     way, but will throw an AssertionError if anything seems off
     137    way, but will raise an AssertionError if anything seems off
    138138    (except for a failure to close the application iterator, which
    139     will be printed to stderr -- there's no way to throw an exception
     139    will be printed to stderr -- there's no way to raise an exception
    140140    at that point).
    141141    """
     
    346346
    347347    if not environ.get('SCRIPT_NAME'):
    348         assert_(environ.has_key('PATH_INFO'),
     348        assert_('PATH_INFO' in environ,
    349349            "One of SCRIPT_NAME or PATH_INFO are required (PATH_INFO "
    350350            "should at least be '/' if SCRIPT_NAME is empty)")
Note: See TracChangeset for help on using the changeset viewer.