def __init__(self, snake, request, response, properties={}): self.snake=snake self.request=request self.response=response self.request_uri = request.getRequestURL() self.script_name = self.snake.getWebApp().getURLprefix()[:-1] # strip the trailing / self.path_info, self.query_string = self.splitURI(request.getRequestURL()) self.path_info = self.path_info[len(self.script_name):] self.saved_cookie = request.getCookie() self.request_method = request.getMethod() headers = request.getAllHeaders() self.remote_addr=request.getRemoteAddr() self.http_user_agent=request.getUserAgent() self.http_accept_language = headers.getheader('accept-language') self.setHttpReferer(headers.getheader('referer')) self.setHost(headers.getheader('host')) self.setURL(headers) self.if_modified_since=headers.getheader('If-modified-since') self.if_none_match=headers.getheader('If-none-match') self.server_port = str(request.getServerPort()) self.server_name = request.getServerName() if ':' in self.server_name: self.server_name=self.server_name.split(':')[0] self.headers = headers baseurl = request.getBaseURL() self.is_ssl = baseurl.startswith("https") or baseurl.startswith("HTTPS") RequestBase.__init__(self, properties)
def __init__(self, req, properties={}): """ Saves mod_pythons request and sets basic variables using the req.subprocess_env, cause this provides a standard way to access the values we need here. @param req: the mod_python request instance """ try: # flags if headers sent out contained content-type or status self._have_ct = 0 self._have_status = 0 req.add_common_vars() self.mpyreq = req # some mod_python 2.7.X has no get method for table objects, # so we make a real dict out of it first. if not hasattr(req.subprocess_env, "get"): env = dict(req.subprocess_env) else: env = req.subprocess_env self._setup_vars_from_std_env(env) RequestBase.__init__(self, properties) except Exception, err: self.fail(err)
def finish(self): """ Just return apache.OK. Status is set in req.status. """ RequestBase.finish(self) # is it possible that we need to return something else here? from mod_python import apache return apache.OK
def finish(self): RequestBase.finish(self) # flush the output, ignore errors caused by the user closing the socket try: sys.stdout.flush() except IOError, ex: import errno if ex.errno != errno.EPIPE: raise
def __init__(self, properties={}): try: # force input/output to binary if sys.platform == "win32": import msvcrt msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) self._setup_vars_from_std_env(os.environ) RequestBase.__init__(self, properties) except Exception, err: self.fail(err)
def __init__(self, twistedRequest, pagename, reactor, properties={}): try: self.twistd = twistedRequest self.reactor = reactor # Copy headers self.http_accept_language = self.twistd.getHeader('Accept-Language') self.saved_cookie = self.twistd.getHeader('Cookie') self.http_user_agent = self.twistd.getHeader('User-Agent') try: self.content_length = int(self.twistd.getHeader('Content-Length')) except (TypeError, ValueError): self.content_length = None self.if_modified_since = self.twistd.getHeader('If-Modified-Since') self.if_none_match = self.twistd.getHeader('If-None-Match') # Copy values from twisted request self.server_protocol = self.twistd.clientproto self.server_name = self.twistd.getRequestHostname().split(':')[0] self.server_port = str(self.twistd.getHost()[2]) self.is_ssl = self.twistd.isSecure() self.path_info = '/' + '/'.join([pagename] + self.twistd.postpath) self.request_method = self.twistd.method self.remote_addr = self.twistd.getClientIP() self.request_uri = self.twistd.uri self.script_name = "/" + '/'.join(self.twistd.prepath[:-1]) # Values that need more work self.query_string = self.splitURI(self.twistd.uri)[1] self.setHttpReferer(self.twistd.getHeader('Referer')) self.setHost() self.setURL(self.twistd.getAllHeaders()) ##self.debugEnvironment(twistedRequest.getAllHeaders()) RequestBase.__init__(self, properties) except MoinMoinFinish: # might be triggered by http_redirect self.emit_http_headers() # send headers (important for sending MOIN_ID cookie) self.finish() except Exception, err: # Wrap err inside an internal error if needed from MoinMoin import error if isinstance(err, error.FatalError): self.delayedError = err else: self.delayedError = error.InternalError(str(err))
def run(self, req): """ mod_python calls this with its request object. We don't need it cause its already passed to __init__. So ignore it and just return RequestBase.run. @param req: the mod_python request instance """ return RequestBase.run(self)
def __init__(self, fcgRequest, env, form, properties={}): """ Initializes variables from FastCGI environment and saves FastCGI request and form for further use. @param fcgRequest: the FastCGI request instance. @param env: environment passed by FastCGI. @param form: FieldStorage passed by FastCGI. """ try: self.fcgreq = fcgRequest self.fcgenv = env self.fcgform = form self._setup_vars_from_std_env(env) RequestBase.__init__(self, properties) except Exception, err: self.fail(err)
def __init__(self, sa, properties={}): """ @param sa: stand alone server object @param properties: ... """ try: self.sareq = sa self.wfile = sa.wfile self.rfile = sa.rfile self.headers = sa.headers self.is_ssl = 0 # Copy headers self.http_accept_language = (sa.headers.getheader('accept-language') or self.http_accept_language) self.http_user_agent = sa.headers.getheader('user-agent', '') try: self.content_length = int(sa.headers.getheader('content-length')) except (TypeError, ValueError): self.content_length = None co = [c for c in sa.headers.getheaders('cookie') if c] self.saved_cookie = ', '.join(co) or '' self.if_modified_since = sa.headers.getheader('if-modified-since') self.if_none_match = sa.headers.getheader('if-none-match') # Copy rest from standalone request self.server_name = sa.server.server_name self.server_port = str(sa.server.server_port) self.request_method = sa.command self.request_uri = sa.path self.remote_addr = sa.client_address[0] # Values that need more work self.path_info, self.query_string = self.splitURI(sa.path) self.setHttpReferer(sa.headers.getheader('referer')) self.setHost(sa.headers.getheader('host')) self.setURL(sa.headers) ##self.debugEnvironment(sa.headers) RequestBase.__init__(self, properties) except Exception, err: self.fail(err)
def __init__(self, url='CLI', pagename='', properties={}, given_config=None): self.saved_cookie = '' self.path_info = '/' + pagename self.query_string = '' self.remote_addr = '127.0.0.1' self.is_ssl = 0 self.http_user_agent = 'CLI/Script' self.url = url self.request_method = 'GET' self.request_uri = '/' + pagename # TODO check if /pagename works as URI for CLI usage self.http_host = 'localhost' self.http_referer = '' self.script_name = '.' self.content_length = None self.if_modified_since = None self.if_none_match = None RequestBase.__init__(self, properties, given_config) self.cfg.caching_formats = [] # don't spoil the cache self.initTheme() # usually request.run() does this, but we don't use it
def __init__(self, env): try: self.env = env self.hasContentType = False self.stdin = env['wsgi.input'] self.stdout = StringIO.StringIO() # used by MoinMoin.server.server_wsgi: self.status = '200 OK' self.headers = [] # used by send_file() self._send_file = None self._send_bufsize = None self._setup_vars_from_std_env(env) RequestBase.__init__(self, {}) except Exception, err: self.fail(err)
def fixURI(self, env): """ Fix problems with script_name and path_info using PythonOption directive to rewrite URI. This is needed when using Apache 1 or other server which does not support adding custom headers per request. With mod_python we can use the PythonOption directive: <Location /url/to/mywiki/> PythonOption X-Moin-Location /url/to/mywiki/ </location> Note that *neither* script_name *nor* path_info can be trusted when Moin is invoked as a mod_python handler with apache1, so we must build both using request_uri and the provided PythonOption. """ # Be compatible with release 1.3.5 "Location" option # TODO: Remove in later release, we should have one option only. old_location = "Location" options_table = self.mpyreq.get_options() if not hasattr(options_table, "get"): options = dict(options_table) else: options = options_table location = options.get(self.moin_location) or options.get(old_location) if location: env[self.moin_location] = location # Try to recreate script_name and path_info from request_uri. import urlparse scriptAndPath = urlparse.urlparse(self.request_uri)[2] self.script_name = location.rstrip("/") path = scriptAndPath.replace(self.script_name, "", 1) self.path_info = wikiutil.url_unquote(path, want_unicode=False) RequestBase.fixURI(self, env)
def finish(self): RequestBase.finish(self) self.flush()
def finish(self): """ Call finish method of FastCGI request to finish handling of this request. """ RequestBase.finish(self) self.fcgreq.finish()
def send_file(self, fileobj, bufsize=8192, do_flush=True): # as thfcgi buffers everything we write until we do a flush, we use # do_flush=True as default here (otherwise the sending of big file # attachments would consume lots of memory) return RequestBase.send_file(self, fileobj, bufsize, do_flush)
def _setup_args_from_cgi_form(self): """ Override to use FastCGI form """ # thfcgi used keep_blank_values=1 internally for fcgform return RequestBase._setup_args_from_cgi_form(self, self.fcgform)
def run(self): """ Handle delayed errors then invoke base class run """ if hasattr(self, 'delayedError'): self.fail(self.delayedError) return self.finish() RequestBase.run(self)
def _setup_args_from_cgi_form(self): """ Override to create cgi form """ form = cgi.FieldStorage(keep_blank_values=1) return RequestBase._setup_args_from_cgi_form(self, form)
def _setup_args_from_cgi_form(self): """ Override to create standalone form """ form = cgi.FieldStorage(self.rfile, headers=self.headers, environ={'REQUEST_METHOD': 'POST'}, keep_blank_values=1) return RequestBase._setup_args_from_cgi_form(self, form)
def finish(self): RequestBase.finish(self) self.reactor.callFromThread(self.twistd.finish)