Esempio n. 1
0
 def get_env(self, req):
     env = self._ENV.copy()
     (path, params, query, fragment) = req.split_uri()
     if params:
         path = path + params  # undo medusa bug
     while path and path[0] == '/':
         path = path[1:]
     if '%' in path:
         path = unquote(path)
     if query:
         # ZPublisher doesn't want the leading '?'
         query = query[1:]
     env['PATH_INFO'] = '/' + path
     env['PATH_TRANSLATED'] = posixpath.normpath(
         posixpath.join(os.getcwd(), env['PATH_INFO']))
     if query:
         env['QUERY_STRING'] = query
     env['channel.creation_time'] = time.time()
     for header in req.header:
         key, value = header.split(":", 1)
         key = key.upper()
         value = value.strip()
         key = 'HTTP_%s' % ("_".join(key.split("-")))
         if value:
             env[key] = value
     return env
Esempio n. 2
0
 def get_env(self, req):
     env = self._ENV.copy()
     (path, params, query, fragment) = req.split_uri()
     if params:
         path = path + params  # undo medusa bug
     while path and path[0] == '/':
         path = path[1:]
     if '%' in path:
         path = unquote(path)
     if query:
         # ZPublisher doesn't want the leading '?'
         query = query[1:]
     env['PATH_INFO'] = '/' + path
     env['PATH_TRANSLATED'] = posixpath.normpath(
         posixpath.join(os.getcwd(), env['PATH_INFO']))
     if query:
         env['QUERY_STRING'] = query
     env['channel.creation_time'] = time.time()
     for header in req.header:
         key, value = header.split(":", 1)
         key = key.upper()
         value = value.strip()
         key = 'HTTP_%s' % ("_".join(key.split("-")))
         if value:
             env[key] = value
     return env
Esempio n. 3
0
def make_env(req, method='GET'):
    (path, params, query, fragment) = req.split_uri()
    if params:
        path = path + params  # Undo Medusa bug.
    while path and path[0] == '/':
        path = path[1:]
    if '%' in path:
        path = unquote(path)
    if query:
        # ZPublisher doesn't want the leading '?'.
        query = query[1:]

    env = dict(
        GATEWAY_INTERFACE='CGI/1.1',
        REMOTE_ADDR='0',
        REQUEST_METHOD=method,
        SCRIPT_NAME='',
        SERVER_NAME='nohost',
        SERVER_PORT='',
        SERVER_PROTOCOL='HTTP/1.1',
        SERVER_SOFTWARE='Zope',
        HTTP_USER_AGENT=TASK_QUEUE_SERVER_IDENT)
    env['PATH_INFO'] = '/' + path
    env['PATH_TRANSLATED'] = posixpath.normpath(
        posixpath.join(os.getcwd(), env['PATH_INFO']))
    if query:
        env['QUERY_STRING'] = query
    env['channel.creation_time'] = time.time()

    for header in req.header:
        key, value = header.split(':', 1)
        key = key.upper()
        value = value.strip()
        if key.startswith('CONTENT-'):
            key = '{0:s}'.format('_'.join(key.split('-')))
        else:
            key = 'HTTP_{0:s}'.format('_'.join(key.split('-')))
        if value:
            env[key] = value

    return env
Esempio n. 4
0
def make_env(req, method='GET'):
    (path, params, query, fragment) = req.split_uri()
    if params:
        path = path + params  # Undo Medusa bug.
    while path and path[0] == '/':
        path = path[1:]
    if '%' in path:
        path = unquote(path)
    if query:
        # ZPublisher doesn't want the leading '?'.
        query = query[1:]

    env = dict(GATEWAY_INTERFACE='CGI/1.1',
               REMOTE_ADDR='0',
               REQUEST_METHOD=method,
               SCRIPT_NAME='',
               SERVER_NAME='nohost',
               SERVER_PORT='',
               SERVER_PROTOCOL='HTTP/1.1',
               SERVER_SOFTWARE='Zope',
               HTTP_USER_AGENT=TASK_QUEUE_SERVER_IDENT)
    env['PATH_INFO'] = '/' + path
    env['PATH_TRANSLATED'] = posixpath.normpath(
        posixpath.join(os.getcwd(), env['PATH_INFO']))
    if query:
        env['QUERY_STRING'] = query
    env['channel.creation_time'] = time.time()

    for header in req.header:
        key, value = header.split(':', 1)
        key = key.upper()
        value = value.strip()
        if key.startswith('CONTENT-'):
            key = '{0:s}'.format('_'.join(key.split('-')))
        else:
            key = 'HTTP_{0:s}'.format('_'.join(key.split('-')))
        if value:
            env[key] = value

    return env
Esempio n. 5
0
    def get_environment(
            self,
            request,
            # These are strictly performance hackery...
            h2ehas=header2env.has_key,
            h2eget=header2env.get,
            workdir=os.getcwd(),
            ospath=os.path,
    ):

        (path, params, query, fragment) = request.split_uri()

        if params:
            path = path + params  # undo medusa bug!

        while path and path[0] == '/':
            path = path[1:]
        if '%' in path:
            path = unquote(path)
        if query:
            # ZPublisher doesn't want the leading '?'
            query = query[1:]

        server = request.channel.server
        env = {}
        env['REQUEST_METHOD'] = request.command.upper()
        env['SERVER_PORT'] = str(server.port)
        env['SERVER_NAME'] = server.request_server_name
        env['SERVER_SOFTWARE'] = server.SERVER_IDENT
        env['SERVER_PROTOCOL'] = "HTTP/" + request.version
        env['channel.creation_time'] = request.channel.creation_time
        if self.uri_base == '/':
            env['SCRIPT_NAME'] = ''
            env['PATH_INFO'] = '/' + path
        else:
            env['SCRIPT_NAME'] = self.uri_base
            try:
                path_info = path.split(self.uri_base[1:], 1)[1]
            except:
                path_info = ''
            env['PATH_INFO'] = path_info
        env['PATH_TRANSLATED'] = ospath.normpath(
            ospath.join(workdir, env['PATH_INFO']))
        if query:
            env['QUERY_STRING'] = query
        env['GATEWAY_INTERFACE'] = 'CGI/1.1'
        env['REMOTE_ADDR'] = request.channel.addr[0]

        # This is a really bad hack to support WebDAV
        # clients accessing documents through GET
        # on the HTTP port. We check if your WebDAV magic
        # machinery is enabled and if the client is recognized
        # as WebDAV client. If yes, we fake the environment
        # to pretend the ZPublisher to have a WebDAV request.
        # This sucks like hell but it works pretty fine ;-)

        if env['REQUEST_METHOD'] == 'GET' and self._wdav_client_reg:
            self._munge_webdav_source_port(request, env)

        # If we're using a resolving logger, try to get the
        # remote host from the resolver's cache.
        if hasattr(server.logger, 'resolver'):
            dns_cache = server.logger.resolver.cache
            if env['REMOTE_ADDR'] in dns_cache:
                remote_host = dns_cache[env['REMOTE_ADDR']][2]
                if remote_host is not None:
                    env['REMOTE_HOST'] = remote_host

        env_has = env.has_key
        for header in request.header:
            key, value = header.split(":", 1)
            key = key.lower()
            value = value.strip()
            if h2ehas(key) and value:
                env[h2eget(key)] = value
            else:
                key = 'HTTP_%s' % ("_".join(key.split("-"))).upper()
                if value and not env_has(key):
                    env[key] = value
        env.update(self.env_override)
        return env
Esempio n. 6
0
    def get_environment(self, request,
                        # These are strictly performance hackery...
                        h2ehas=header2env.has_key,
                        h2eget=header2env.get,
                        workdir=os.getcwd(),
                        ospath=os.path,
                        ):

        (path, params, query, fragment) = request.split_uri()

        if params:
            path = path + params  # undo medusa bug!

        while path and path[0] == '/':
            path = path[1:]
        if '%' in path:
            path = unquote(path)
        if query:
            # ZPublisher doesn't want the leading '?'
            query = query[1:]

        server = request.channel.server
        env = {}
        env['REQUEST_METHOD'] = request.command.upper()
        env['SERVER_PORT'] = str(server.port)
        env['SERVER_NAME'] = server.request_server_name
        env['SERVER_SOFTWARE'] = server.SERVER_IDENT
        env['SERVER_PROTOCOL'] = "HTTP/" + request.version
        env['channel.creation_time'] = request.channel.creation_time
        if self.uri_base == '/':
            env['SCRIPT_NAME'] = ''
            env['PATH_INFO'] = '/' + path
        else:
            env['SCRIPT_NAME'] = self.uri_base
            try:
                path_info = path.split(self.uri_base[1:], 1)[1]
            except:
                path_info = ''
            env['PATH_INFO'] = path_info
        env['PATH_TRANSLATED'] = ospath.normpath(ospath.join(
            workdir, env['PATH_INFO']))
        if query:
            env['QUERY_STRING'] = query
        env['GATEWAY_INTERFACE'] = 'CGI/1.1'
        env['REMOTE_ADDR'] = request.channel.addr[0]

        # This is a really bad hack to support WebDAV
        # clients accessing documents through GET
        # on the HTTP port. We check if your WebDAV magic
        # machinery is enabled and if the client is recognized
        # as WebDAV client. If yes, we fake the environment
        # to pretend the ZPublisher to have a WebDAV request.
        # This sucks like hell but it works pretty fine ;-)

        if env['REQUEST_METHOD'] == 'GET' and self._wdav_client_reg:
            self._munge_webdav_source_port(request, env)

        # If we're using a resolving logger, try to get the
        # remote host from the resolver's cache.
        if hasattr(server.logger, 'resolver'):
            dns_cache = server.logger.resolver.cache
            if env['REMOTE_ADDR'] in dns_cache:
                remote_host = dns_cache[env['REMOTE_ADDR']][2]
                if remote_host is not None:
                    env['REMOTE_HOST'] = remote_host

        env_has = env.has_key
        for header in request.header:
            key, value = header.split(":", 1)
            key = key.lower()
            value = value.strip()
            if h2ehas(key) and value:
                env[h2eget(key)] = value
            else:
                key = 'HTTP_%s' % ("_".join(key.split("-"))).upper()
                if value and not env_has(key):
                    env[key] = value
        env.update(self.env_override)
        return env