Exemplo n.º 1
0
    def __init__(self, env):
        """Initialize attributes based on a WSGI environment dict

        Note: Request is not meant to be instantiated directory by responders.

        Args:
            env: A WSGI environment dict passed in from the server. See also
                the PEP-3333 spec.

        """
        self.env = env

        self._wsgierrors = env['wsgi.errors']
        self.stream = env['wsgi.input']
        self.method = env['REQUEST_METHOD']

        # Normalize path
        path = env['PATH_INFO']
        if path:
            if len(path) != 1 and path.endswith('/'):
                self.path = path[:-1]
            else:
                self.path = path
        else:
            self.path = '/'

        # QUERY_STRING isn't required to be in env, so let's check
        # PERF: if...in is faster than using env.get(...)
        if 'QUERY_STRING' in env:
            self.query_string = env['QUERY_STRING']
        else:
            self.query_string = ''

        # PERF: Don't parse it if we don't have to!
        if self.query_string:
            self._params = helpers.parse_query_string(self.query_string)
        else:
            self._params = {}

        self._headers = helpers.parse_headers(env)

        # NOTE(kgriffs): Wrap wsgi.input if needed to make read() more robust,
        # normalizing semantics between, e.g., gunicorn and wsgiref.
        if isinstance(self.stream, NativeStream):  # pragma: nocover
            # NOTE(kgriffs): coverage can't detect that this *is* actually
            # covered since the test that does so uses multiprocessing.
            self.stream = helpers.Body(self.stream, self.content_length)
Exemplo n.º 2
0
    def __init__(self, env):
        """Initialize attributes based on a WSGI environment dict

        Note: Request is not meant to be instantiated directory by responders.

        Args:
            env: A WSGI environment dict passed in from the server. See also
                the PEP-3333 spec.

        """
        self.env = env

        self._wsgierrors = env['wsgi.errors']
        self.stream = env['wsgi.input']
        self.method = env['REQUEST_METHOD']

        # Normalize path
        path = env['PATH_INFO']
        if path:
            if len(path) != 1 and path.endswith('/'):
                self.path = path[:-1]
            else:
                self.path = path
        else:
            self.path = '/'

        # QUERY_STRING isn't required to be in env, so let's check
        # PERF: if...in is faster than using env.get(...)
        if 'QUERY_STRING' in env and env['QUERY_STRING']:
            self.query_string = util.percent_unescape(env['QUERY_STRING'])
        else:
            self.query_string = six.text_type()

        # PERF: Don't parse it if we don't have to!
        if self.query_string:
            self._params = helpers.parse_query_string(self.query_string)
        else:
            self._params = {}

        self._headers = helpers.parse_headers(env)

        # NOTE(kgriffs): Wrap wsgi.input if needed to make read() more robust,
        # normalizing semantics between, e.g., gunicorn and wsgiref.
        if isinstance(self.stream, NativeStream):  # pragma: nocover
            # NOTE(kgriffs): coverage can't detect that this *is* actually
            # covered since the test that does so uses multiprocessing.
            self.stream = helpers.Body(self.stream, self.content_length)
Exemplo n.º 3
0
    def __init__(self, env):
        """Initialize attributes based on a WSGI environment dict

        Note: Request is not meant to be instantiated directory by responders.

        Args:
            env: A WSGI environment dict passed in from the server. See also
                the PEP-3333 spec.

        """
        self.env = env

        self._wsgierrors = env['wsgi.errors']
        self.stream = env['wsgi.input']

        self.method = env['REQUEST_METHOD']

        # Normalize path
        path = env['PATH_INFO']
        if path:
            if len(path) != 1 and path.endswith('/'):
                self.path = path[:-1]
            else:
                self.path = path
        else:
            self.path = '/'

        # QUERY_STRING isn't required to be in env, so let's check
        # PERF: if...in is faster than using env.get(...)
        if 'QUERY_STRING' in env:
            self.query_string = env['QUERY_STRING']
        else:
            self.query_string = ''

        self._headers = helpers.parse_headers(env)

        # PERF: Don't parse it if we don't have to!
        if self.query_string:
            self._params = helpers.parse_query_string(self.query_string)
        else:
            self._params = {}

        if (self.content_type and self.content_type.split(';')[0]
                == 'application/x-www-form-urlencoded'):
            body = self.stream.read(self.content_length)
            self._params.update(helpers.parse_query_string(body))
Exemplo n.º 4
0
    def __init__(self, env):
        """Initialize attributes based on a WSGI environment dict

        Note: Request is not meant to be instantiated directory by responders.

        Args:
            env: A WSGI environment dict passed in from the server. See also
                the PEP-3333 spec.

        """
        self.env = env

        self._wsgierrors = env['wsgi.errors']
        self.stream = env['wsgi.input']

        self.method = env['REQUEST_METHOD']

        # Normalize path
        path = env['PATH_INFO']
        if path:
            if len(path) != 1 and path.endswith('/'):
                self.path = path[:-1]
            else:
                self.path = path
        else:
            self.path = '/'

        # QUERY_STRING isn't required to be in env, so let's check
        # PERF: if...in is faster than using env.get(...)
        if 'QUERY_STRING' in env:
            self.query_string = env['QUERY_STRING']
        else:
            self.query_string = ''

        self._headers = helpers.parse_headers(env)

        # PERF: Don't parse it if we don't have to!
        if self.query_string:
            self._params = helpers.parse_query_string(self.query_string)
        else:
            self._params = {}

        if (self.content_type and
            self.content_type.split(';')[0] == 'application/x-www-form-urlencoded'):
            body = self.stream.read(self.content_length)
            self._params.update(helpers.parse_query_string(body))
Exemplo n.º 5
0
    def __init__(self, env):
        """Initialize attributes based on a WSGI environment dict

        Note: Request is not meant to be instantiated directory by responders.

        Args:
            env: A WSGI environment dict passed in from the server. See also
                the PEP-333 spec.

        """

        self.env = env

        self._wsgierrors = env["wsgi.errors"]
        self.stream = env["wsgi.input"]

        self.method = env["REQUEST_METHOD"]

        # Normalize path
        path = env["PATH_INFO"]
        if path:
            if len(path) != 1 and path.endswith("/"):
                self.path = path[:-1]
            else:
                self.path = path
        else:
            self.path = "/"

        # QUERY_STRING isn't required to be in env, so let's check
        # PERF: if...in is faster than using env.get(...)
        if "QUERY_STRING" in env:
            self.query_string = env["QUERY_STRING"]
        else:
            self.query_string = ""

        # PERF: Don't parse it if we don't have to!
        if self.query_string:
            self._params = helpers.parse_query_string(self.query_string)
        else:
            self._params = {}

        self._headers = helpers.parse_headers(env)