Example #1
0
    def get_environ(self):
        """Return the built environ."""
        input_stream = self.input_stream
        content_length = self.content_length
        content_type = self.content_type

        if input_stream is not None:
            start_pos = input_stream.tell()
            input_stream.seek(0, 2)
            end_pos = input_stream.tell()
            input_stream.seek(start_pos)
            content_length = end_pos - start_pos
        elif content_type == 'multipart/form-data':
            values = CombinedMultiDict([self.form, self.files])
            input_stream, content_length, boundary = \
                stream_encode_multipart(values, charset=self.charset)
            content_type += '; boundary="%s"' % boundary
        elif content_type == 'application/x-www-form-urlencoded':
            values = url_encode(self.form, charset=self.charset)
            content_length = len(values)
            input_stream = StringIO(values)
        else:
            input_stream = _empty_stream

        result = {}
        if self.environ_base:
            result.update(self.environ_base)

        def _path_encode(x):
            if isinstance(x, unicode):
                x = x.encode(self.charset)
            return _unquote(x)

        result.update({
            'REQUEST_METHOD': self.method,
            'SCRIPT_NAME': _path_encode(self.script_root),
            'PATH_INFO': _path_encode(self.path),
            'QUERY_STRING': self.query_string,
            'SERVER_NAME': self.server_name,
            'SERVER_PORT': str(self.server_port),
            'HTTP_HOST': self.host,
            'SERVER_PROTOCOL': self.server_protocol,
            'CONTENT_TYPE': content_type or '',
            'CONTENT_LENGTH': str(content_length or '0'),
            'wsgi.version': self.wsgi_version,
            'wsgi.url_scheme': self.url_scheme,
            'wsgi.input': input_stream,
            'wsgi.errors': self.errors_stream,
            'wsgi.multithread': self.multithread,
            'wsgi.multiprocess': self.multiprocess,
            'wsgi.run_once': self.run_once
        })
        for key, value in self.headers.to_list(self.charset):
            result['HTTP_%s' % key.upper().replace('-', '_')] = value
        if self.environ_overrides:
            result.update(self.environ_overrides)
        return result
Example #2
0
    def get_environ(self):
        """Return the built environ."""
        input_stream = self.input_stream
        content_length = self.content_length
        content_type = self.content_type

        if input_stream is not None:
            start_pos = input_stream.tell()
            input_stream.seek(0, 2)
            end_pos = input_stream.tell()
            input_stream.seek(start_pos)
            content_length = end_pos - start_pos
        elif content_type == 'multipart/form-data':
            values = CombinedMultiDict([self.form, self.files])
            input_stream, content_length, boundary = \
                stream_encode_multipart(values, charset=self.charset)
            content_type += '; boundary="%s"' % boundary
        elif content_type == 'application/x-www-form-urlencoded':
            values = url_encode(self.form, charset=self.charset)
            content_length = len(values)
            input_stream = StringIO(values)
        else:
            input_stream = _empty_stream

        result = {}
        if self.environ_base:
            result.update(self.environ_base)

        def _path_encode(x):
            if isinstance(x, unicode):
                x = x.encode(self.charset)
            return _unquote(x)

        result.update({
            'REQUEST_METHOD':       self.method,
            'SCRIPT_NAME':          _path_encode(self.script_root),
            'PATH_INFO':            _path_encode(self.path),
            'QUERY_STRING':         self.query_string,
            'SERVER_NAME':          self.server_name,
            'SERVER_PORT':          str(self.server_port),
            'HTTP_HOST':            self.host,
            'SERVER_PROTOCOL':      self.server_protocol,
            'CONTENT_TYPE':         content_type or '',
            'CONTENT_LENGTH':       str(content_length or '0'),
            'wsgi.version':         self.wsgi_version,
            'wsgi.url_scheme':      self.url_scheme,
            'wsgi.input':           input_stream,
            'wsgi.errors':          self.errors_stream,
            'wsgi.multithread':     self.multithread,
            'wsgi.multiprocess':    self.multiprocess,
            'wsgi.run_once':        self.run_once
        })
        for key, value in self.headers.to_list(self.charset):
            result['HTTP_%s' % key.upper().replace('-', '_')] = value
        if self.environ_overrides:
            result.update(self.environ_overrides)
        return result
Example #3
0
 def _get_query_string(self):
     if self._query_string is None:
         if self._args is not None:
             return url_encode(self._args, charset=self.charset)
         return ''
     return self._query_string
Example #4
0
 def _get_query_string(self):
     if self._query_string is None:
         if self._args is not None:
             return url_encode(self._args, charset=self.charset)
         return ''
     return self._query_string