Exemple #1
0
    def __init__(self, app, store, initializer=None):
        self.store = store
        self._initializer = initializer
        self._last_cleanup_time = 0
        self._config = storage()
        self._data = threadeddict()
        self._loadconfig()
        
        self.__getitem__ = self._data.__getitem__
        self.__setitem__ = self._data.__setitem__
        self.__delitem__ = self._data.__delitem__

        if app:
            app.add_processor(self._processor)
Exemple #2
0
    def load(self, env):
        """Initializes request using env."""
        request = http.request
        request.clear()
        request.headers = []
        request.output = ''
        request.environ = request.env = request.META = storage(**env)
        request.host = env.get('HTTP_HOST')

        if env.get('wsgi.url_scheme') in ['http', 'https']:
            request.protocol = env['wsgi.url_scheme']
        elif env.get('HTTPS', '').lower() in ['on', 'true', '1']:
            request.protocol = 'https'
        else:
            request.protocol = 'http'
        request.homedomain = request.protocol + '://' + env.get('HTTP_HOST', '[unknown]')
        request.homepath = env.get('REAL_SCRIPT_NAME', env.get('SCRIPT_NAME', ''))
        request.home = request.homedomain + request.homepath
        request.realhome = request.home
        request.ip = env.get('HTTP_X_REAL_IP', env.get('REMOTE_ADDR'))
        request.method = env.get('REQUEST_METHOD')
        request.path = env.get('PATH_INFO')
        if env.get('SERVER_SOFTWARE', '').startswith('lighttpd/'):
            request.path = lstrips(env.get('REQUEST_URI').split('?')[0], request.homepath)
            request.path = urllib.unquote(request.path)

        if env.get('QUERY_STRING'):
            request.query = '?' + env.get('QUERY_STRING', '')
        else:
            request.query = ''

        request.fullpath = request.path + request.query
        
        for k, v in request.iteritems():
            if isinstance(v, str):
                request[k] = v.decode('utf-8', 'replace') 

        request.status = '200 OK'