示例#1
0
    def on_change(self):
        def e(t):
            return t.encode("utf8")

        data = [(e(k), e(v)) for k, v in self.items()]
        qs = url_encode(data)
        self.env["QUERY_STRING"] = qs
        self.env["webob._parsed_query_vars"] = (self, qs)
示例#2
0
文件: multidict.py 项目: Pylons/webob
    def on_change(self):
        def e(t):
            return t.encode("utf8")

        data = [(e(k), e(v)) for k, v in self.items()]
        qs = url_encode(data)
        self.env["QUERY_STRING"] = qs
        self.env["webob._parsed_query_vars"] = (self, qs)
示例#3
0
文件: http.py 项目: ral99/weppy
    def put(cls, http_version='HTTP/1.1', server_name='localhost', server_port=8000,
            script_name='', path_info='', query_string='', params=None, url_scheme='http',
            headers=None, multithread=True, multiprocess=False, run_once=True):
        """
        Return a PUT HTTPRequest.

        http_version -- str that specifies the server protocol. 'HTTP/1.1' by default.
        server_name -- str that specifies the server name. 'localhost' by default.
        server_port -- int that specifies the server port. 8000 by default.
        script_name -- str that specifies the script name. Empty str by default.
        path_info -- str that specifies the path info. Empty str by default.
        query_string -- str that specifies the query string. Empty str by default.
        params -- dict that associates names and values. Files are specified by a tuple
                  (filename, content). None by default.
        url_scheme -- str that specifies the scheme portion of the URL. 'http' by default.
        headers -- dict of HTTP headers. None by default.
        multithread -- bool that specifies wheter the request may be simultaneously invoked by
                       another thread in the same process. True by default.
        multiprocess -- bool that specifies wheter the request may be simultaneously invoked by
                        another process. False by default.
        run_once -- bool that specifies wheter the server expects (but does not guarantee) that
                    the application will only be invoked one time during the life of its
                    containing process. Normally, this will only be true for a gateway based on
                    CGI. True by default.
        """
        params = params or {}
        for k, v in params.items():
            if isinstance(v, tuple):
                content_type, data = _encode_multipart(params, 'multipart/form-data')
                break
        else:
            content_type = 'application/x-www-form-urlencoded'
            data = url_encode(params).encode('utf-8')
        environ = {
            'REQUEST_METHOD': 'PUT',
            'SERVER_PROTOCOL': http_version,
            'SERVER_NAME': server_name,
            'SERVER_PORT': str(server_port),
            'SCRIPT_NAME': script_name,
            'PATH_INFO': path_info,
            'QUERY_STRING': query_string,
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': str(len(data)),
            'wsgi.version': (1, 0),
            'wsgi.url_scheme': url_scheme,
            'wsgi.input': io.BytesIO(data),
            'wsgi.errors': sys.stderr,
            'wsgi.multithread': multithread,
            'wsgi.multiprocess': multiprocess,
            'wsgi.run_once': run_once,
        }
        environ.update(headers or {})
        return cls(environ)
示例#4
0
 def on_change(self):
     e = lambda t: t.encode('utf8')
     data = [(e(k), e(v)) for k, v in self.items()]
     qs = url_encode(data)
     self.env['QUERY_STRING'] = qs
     self.env['webob._parsed_query_vars'] = (self, qs)
示例#5
0
 def on_change(self):
     e = lambda t: t.encode('utf8')
     data = [(e(k), e(v)) for k,v in self.items()]
     qs = url_encode(data)
     self.env['QUERY_STRING'] = qs
     self.env['webob._parsed_query_vars'] = (self, qs)
示例#6
0
    def put(cls,
            http_version='HTTP/1.1',
            server_name='localhost',
            server_port=8000,
            script_name='',
            path_info='',
            query_string='',
            params=None,
            url_scheme='http',
            headers=None,
            multithread=True,
            multiprocess=False,
            run_once=True):
        """
        Return a PUT HTTPRequest.

        http_version -- str that specifies the server protocol. 'HTTP/1.1' by default.
        server_name -- str that specifies the server name. 'localhost' by default.
        server_port -- int that specifies the server port. 8000 by default.
        script_name -- str that specifies the script name. Empty str by default.
        path_info -- str that specifies the path info. Empty str by default.
        query_string -- str that specifies the query string. Empty str by default.
        params -- dict that associates names and values. Files are specified by a tuple
                  (filename, content). None by default.
        url_scheme -- str that specifies the scheme portion of the URL. 'http' by default.
        headers -- dict of HTTP headers. None by default.
        multithread -- bool that specifies wheter the request may be simultaneously invoked by
                       another thread in the same process. True by default.
        multiprocess -- bool that specifies wheter the request may be simultaneously invoked by
                        another process. False by default.
        run_once -- bool that specifies wheter the server expects (but does not guarantee) that
                    the application will only be invoked one time during the life of its
                    containing process. Normally, this will only be true for a gateway based on
                    CGI. True by default.
        """
        params = params or {}
        for k, v in params.items():
            if isinstance(v, tuple):
                content_type, data = _encode_multipart(params,
                                                       'multipart/form-data')
                break
        else:
            content_type = 'application/x-www-form-urlencoded'
            data = url_encode(params).encode('utf-8')
        environ = {
            'REQUEST_METHOD': 'PUT',
            'SERVER_PROTOCOL': http_version,
            'SERVER_NAME': server_name,
            'SERVER_PORT': str(server_port),
            'SCRIPT_NAME': script_name,
            'PATH_INFO': path_info,
            'QUERY_STRING': query_string,
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': str(len(data)),
            'wsgi.version': (1, 0),
            'wsgi.url_scheme': url_scheme,
            'wsgi.input': io.BytesIO(data),
            'wsgi.errors': sys.stderr,
            'wsgi.multithread': multithread,
            'wsgi.multiprocess': multiprocess,
            'wsgi.run_once': run_once,
        }
        environ.update(headers or {})
        return cls(environ)