Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.support.werkzeug.serving.BaseRequestHandler Class Reference
Inheritance diagram for MoinMoin.support.werkzeug.serving.BaseRequestHandler:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.werkzeug.serving.BaseRequestHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def make_environ
def run_wsgi
def connection_dropped
def handle_one_request
def send_response
def version_string
def address_string

Public Attributes

 close_connection
 raw_requestline

Static Public Attributes

string server_version = 'Werkzeug/'

Detailed Description

Definition at line 62 of file serving.py.


Member Function Documentation

Definition at line 195 of file serving.py.

00195 
00196     def address_string(self):
00197         return self.client_address[0]
00198 

Here is the caller graph for this function:

Called if the connection was closed by the client.  By default
nothing happens.

Definition at line 170 of file serving.py.

00170 
00171     def connection_dropped(self, error, environ):
00172         """Called if the connection was closed by the client.  By default
00173         nothing happens.
00174         """

Handle a single HTTP request.

Definition at line 175 of file serving.py.

00175 
00176     def handle_one_request(self):
00177         """Handle a single HTTP request."""
00178         self.raw_requestline = self.rfile.readline()
00179         if not self.raw_requestline:
00180             self.close_connection = 1
00181         elif self.parse_request():
00182             return self.run_wsgi()

Definition at line 65 of file serving.py.

00065 
00066     def make_environ(self):
00067         path_info, query = urlparse(self.path)[2::2]
00068         environ = {
00069             'wsgi.version':         (1, 0),
00070             'wsgi.url_scheme':      'http',
00071             'wsgi.input':           self.rfile,
00072             'wsgi.errors':          sys.stderr,
00073             'wsgi.multithread':     self.server.multithread,
00074             'wsgi.multiprocess':    self.server.multiprocess,
00075             'wsgi.run_once':        False,
00076             'REQUEST_METHOD':       self.command,
00077             'SCRIPT_NAME':          '',
00078             'PATH_INFO':            unquote(path_info),
00079             'QUERY_STRING':         query,
00080             'CONTENT_TYPE':         self.headers.get('Content-Type', ''),
00081             'CONTENT_LENGTH':       self.headers.get('Content-Length', ''),
00082             'REMOTE_ADDR':          self.client_address[0],
00083             'REMOTE_PORT':          self.client_address[1],
00084             'SERVER_NAME':          self.server.server_address[0],
00085             'SERVER_PORT':          str(self.server.server_address[1]),
00086             'SERVER_PROTOCOL':      self.request_version
00087         }
00088 
00089         for key, value in self.headers.items():
00090             key = 'HTTP_' + key.upper().replace('-', '_')
00091             if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'):
00092                 environ[key] = value
00093 
00094         return environ

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 95 of file serving.py.

00095 
00096     def run_wsgi(self):
00097         app = self.server.app
00098         environ = self.make_environ()
00099         headers_set = []
00100         headers_sent = []
00101 
00102         def write(data):
00103             assert headers_set, 'write() before start_response'
00104             if not headers_sent:
00105                 status, response_headers = headers_sent[:] = headers_set
00106                 code, msg = status.split(None, 1)
00107                 self.send_response(int(code), msg)
00108                 header_keys = set()
00109                 for key, value in response_headers:
00110                     self.send_header(key, value)
00111                     key = key.lower()
00112                     header_keys.add(key)
00113                 if 'content-length' not in header_keys:
00114                     self.close_connection = True
00115                     self.send_header('Connection', 'close')
00116                 if 'server' not in header_keys:
00117                     self.send_header('Server', self.version_string())
00118                 if 'date' not in header_keys:
00119                     self.send_header('Date', self.date_time_string())
00120                 self.end_headers()
00121 
00122             assert type(data) is str, 'applications must write bytes'
00123             self.wfile.write(data)
00124             self.wfile.flush()
00125 
00126         def start_response(status, response_headers, exc_info=None):
00127             if exc_info:
00128                 try:
00129                     if headers_sent:
00130                         raise exc_info[0], exc_info[1], exc_info[2]
00131                 finally:
00132                     exc_info = None
00133             elif headers_set:
00134                 raise AssertionError('Headers already set')
00135             headers_set[:] = [status, response_headers]
00136             return write
00137 
00138         def execute(app):
00139             application_iter = app(environ, start_response)
00140             try:
00141                 for data in application_iter:
00142                     write(data)
00143                 # make sure the headers are sent
00144                 if not headers_sent:
00145                     write('')
00146             finally:
00147                 if hasattr(application_iter, 'close'):
00148                     application_iter.close()
00149                 application_iter = None
00150 
00151         try:
00152             execute(app)
00153         except (socket.error, socket.timeout), e:
00154             self.connection_dropped(e, environ)
00155         except:
00156             if self.server.passthrough_errors:
00157                 raise
00158             from werkzeug.debug.tbtools import get_current_traceback
00159             traceback = get_current_traceback(ignore_system_exceptions=True)
00160             try:
00161                 # if we haven't yet sent the headers but they are set
00162                 # we roll back to be able to set them again.
00163                 if not headers_sent:
00164                     del headers_set[:]
00165                 execute(InternalServerError())
00166             except:
00167                 pass
00168             self.server.log('error', 'Error on request:\n%s',
00169                             traceback.plaintext)

Here is the call graph for this function:

def MoinMoin.support.werkzeug.serving.BaseRequestHandler.send_response (   self,
  code,
  message = None 
)
Send the response header and log the response code.

Definition at line 183 of file serving.py.

00183 
00184     def send_response(self, code, message=None):
00185         """Send the response header and log the response code."""
00186         self.log_request(code)
00187         if message is None:
00188             message = code in self.responses and self.responses[code][0] or ''
00189         if self.request_version != 'HTTP/0.9':
00190             self.wfile.write("%s %d %s\r\n" %
00191                              (self.protocol_version, code, message))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 192 of file serving.py.

00192 
00193     def version_string(self):
00194         return BaseHTTPRequestHandler.version_string(self).strip()


Member Data Documentation

Definition at line 113 of file serving.py.

Definition at line 177 of file serving.py.

Definition at line 63 of file serving.py.


The documentation for this class was generated from the following file: