def start_response(status, headers, exc_info=None): if self.complete and not exc_info: raise AssertionError("start_response called a second time " "without providing exc_info.") if exc_info: try: if self.wrote_header: # higher levels will catch and handle raised exception: # 1. "service" method in task.py # 2. "service" method in channel.py # 3. "handler_thread" method in task.py reraise(exc_info[0], exc_info[1], exc_info[2]) else: # As per WSGI spec existing headers must be cleared self.response_headers = [] finally: exc_info = None self.complete = True if not status.__class__ is str: raise AssertionError('status %s is not a string' % status) if '\n' in status or '\r' in status: raise ValueError("carriage return/line " "feed character present in status") self.status = status # Prepare the headers for output for k, v in headers: if not isinstance(k, basestring): raise AssertionError( 'Header name %r is not a string in %r' % (k, (k, v)) ) if not isinstance(v, basestring): raise AssertionError( 'Header value %r is not a string in %r' % (v, (k, v)) ) if '\n' in v or '\r' in v: raise ValueError("carriage return/line " "feed character present in header value") if '\n' in k or '\r' in k: raise ValueError("carriage return/line " "feed character present in header name") kl = k.lower() if kl == 'content-length': self.content_length = int(v) elif kl in hop_by_hop: raise AssertionError( '%s is a "hop-by-hop" header; it cannot be used by ' 'a WSGI application (see PEP 3333)' % k) self.response_headers.extend(headers) # Return a method used to write the response data. return self.write
def start_response(status, headers, exc_info=None): if self.complete and not exc_info: raise AssertionError("start_response called a second time " "without providing exc_info.") if exc_info: try: if self.wrote_header: # higher levels will catch and handle raised exception: # 1. "service" method in task.py # 2. "service" method in channel.py # 3. "handler_thread" method in task.py reraise(exc_info[0], exc_info[1], exc_info[2]) else: # As per WSGI spec existing headers must be cleared self.response_headers = [] finally: exc_info = None self.complete = True if not status.__class__ is str: raise AssertionError('status %s is not a string' % status) if '\n' in status or '\r' in status: raise ValueError("carriage return/line " "feed character present in status") self.status = status # Prepare the headers for output for k, v in headers: if not k.__class__ is str: raise AssertionError( 'Header name %r is not a string in %r' % (k, (k, v)) ) if not v.__class__ is str: raise AssertionError( 'Header value %r is not a string in %r' % (v, (k, v)) ) if '\n' in v or '\r' in v: raise ValueError("carriage return/line " "feed character present in header value") if '\n' in k or '\r' in k: raise ValueError("carriage return/line " "feed character present in header name") kl = k.lower() if kl == 'content-length': self.content_length = int(v) elif kl in hop_by_hop: raise AssertionError( '%s is a "hop-by-hop" header; it cannot be used by ' 'a WSGI application (see PEP 3333)' % k) self.response_headers.extend(headers) # Return a method used to write the response data. return self.write
def start_response(status, headers, exc_info=None): if self.complete and not exc_info: raise AssertionError("start_response called a second time " "without providing exc_info.") if exc_info: try: if self.wrote_header: # higher levels will catch and handle raised exception: # 1. "service" method in task.py # 2. "service" method in channel.py # 3. "handler_thread" method in task.py reraise(exc_info[0], exc_info[1], exc_info[2]) else: # As per WSGI spec existing headers must be cleared self.response_headers = [] finally: exc_info = None self.complete = True if not status.__class__ is str: raise AssertionError("status %s is not a string" % status) self.status = status # Prepare the headers for output for k, v in headers: if not k.__class__ is str: raise AssertionError("Header name %r is not a string in %r" % (k, (k, v))) if not v.__class__ is str: raise AssertionError("Header value %r is not a string in %r" % (v, (k, v))) kl = k.lower() if kl == "content-length": self.content_length = int(v) elif kl in hop_by_hop: raise AssertionError( '%s is a "hop-by-hop" header; it cannot be used by ' "a WSGI application (see PEP 3333)" % k ) self.response_headers.extend(headers) # Return a method used to write the response data. return self.write