当前位置: 首页>>代码示例>>Python>>正文


Python BaseRequest.environ方法代码示例

本文整理汇总了Python中werkzeug.wrappers.BaseRequest.environ方法的典型用法代码示例。如果您正苦于以下问题:Python BaseRequest.environ方法的具体用法?Python BaseRequest.environ怎么用?Python BaseRequest.environ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.wrappers.BaseRequest的用法示例。


在下文中一共展示了BaseRequest.environ方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_app_iter

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def get_app_iter(self, environ):
        """Returns the application iterator for the given environ.  Depending
        on the request method and the current status code the return value
        might be an empty response rather than the one from the response.

        If the request method is `HEAD` or the status code is in a range
        where the HTTP specification requires an empty response, an empty
        iterable is returned.

        .. versionadded:: 0.6

        :param environ: the WSGI environment of the request.
        :return: a response iterable.
        """
        status = self.status_code
        if environ['REQUEST_METHOD'] == 'HEAD' or \
           100 <= status < 200 or status in (204, 304):
            iterable = ()
        elif self.direct_passthrough:
            if __debug__:
                _warn_if_string(self.response)
            return self.response
        else:
            iterable = self.iter_encoded()
        return ClosingIterator(iterable, self.close) 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:wrappers.py

示例2: get_wsgi_response

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def get_wsgi_response(self, environ):
        """Returns the final WSGI response as tuple.  The first item in
        the tuple is the application iterator, the second the status and
        the third the list of headers.  The response returned is created
        specially for the given environment.  For example if the request
        method in the WSGI environment is ``'HEAD'`` the response will
        be empty and only the headers and status code will be present.

        .. versionadded:: 0.6

        :param environ: the WSGI environment of the request.
        :return: an ``(app_iter, status, headers)`` tuple.
        """
        headers = self.get_wsgi_headers(environ)
        app_iter = self.get_app_iter(environ)
        return app_iter, self.status, headers.to_wsgi_list() 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:wrappers.py

示例3: is_xhr

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def is_xhr(self):
        """True if the request was triggered via a JavaScript XMLHttpRequest.
        This only works with libraries that support the ``X-Requested-With``
        header and set it to "XMLHttpRequest".  Libraries that do that are
        prototype, jQuery and Mochikit and probably some more.

        .. deprecated:: 0.13
            ``X-Requested-With`` is not standard and is unreliable.
        """
        warn(DeprecationWarning(
            'Request.is_xhr is deprecated. Given that the X-Requested-With '
            'header is not a part of any spec, it is not reliable'
        ), stacklevel=2)
        return self.environ.get(
            'HTTP_X_REQUESTED_WITH', ''
        ).lower() == 'xmlhttprequest' 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:wrappers.py

示例4: get_app_iter

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def get_app_iter(self, environ):
        """Returns the application iterator for the given environ.  Depending
        on the request method and the current status code the return value
        might be an empty response rather than the one from the response.

        If the request method is `HEAD` or the status code is in a range
        where the HTTP specification requires an empty response, an empty
        iterable is returned.

        .. versionadded:: 0.6

        :param environ: the WSGI environment of the request.
        :return: a response iterable.
        """
        status = self.status_code
        if environ['REQUEST_METHOD'] == 'HEAD' or \
           100 <= status < 200 or status in (204, 304, 412):
            iterable = ()
        elif self.direct_passthrough:
            if __debug__:
                _warn_if_string(self.response)
            return self.response
        else:
            iterable = self.iter_encoded()
        return ClosingIterator(iterable, self.close) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:wrappers.py

示例5: __init__

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def __init__(self, environ, populate_request=True, shallow=False):
        self.environ = environ
        if populate_request and not shallow:
            self.environ['werkzeug.request'] = self
        self.shallow = shallow 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:wrappers.py

示例6: __repr__

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def __repr__(self):
        # make sure the __repr__ even works if the request was created
        # from an invalid WSGI environment.  If we display the request
        # in a debug session we don't want the repr to blow up.
        args = []
        try:
            args.append("'%s'" % to_native(self.url, self.url_charset))
            args.append('[%s]' % self.method)
        except Exception:
            args.append('(invalid WSGI environ)')

        return '<%s %s>' % (
            self.__class__.__name__,
            ' '.join(args)
        ) 
开发者ID:jpush,项目名称:jbox,代码行数:17,代码来源:wrappers.py

示例7: from_values

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def from_values(cls, *args, **kwargs):
        """Create a new request object based on the values provided.  If
        environ is given missing values are filled from there.  This method is
        useful for small scripts when you need to simulate a request from an URL.
        Do not use this method for unittesting, there is a full featured client
        object (:class:`Client`) that allows to create multipart requests,
        support for cookies etc.

        This accepts the same options as the
        :class:`~werkzeug.test.EnvironBuilder`.

        .. versionchanged:: 0.5
           This method now accepts the same arguments as
           :class:`~werkzeug.test.EnvironBuilder`.  Because of this the
           `environ` parameter is now called `environ_overrides`.

        :return: request object
        """
        from werkzeug.test import EnvironBuilder
        charset = kwargs.pop('charset', cls.charset)
        kwargs['charset'] = charset
        builder = EnvironBuilder(*args, **kwargs)
        try:
            return builder.get_request(cls)
        finally:
            builder.close() 
开发者ID:jpush,项目名称:jbox,代码行数:28,代码来源:wrappers.py

示例8: want_form_data_parsed

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def want_form_data_parsed(self):
        """Returns True if the request method carries content.  As of
        Werkzeug 0.9 this will be the case if a content type is transmitted.

        .. versionadded:: 0.8
        """
        return bool(self.environ.get('CONTENT_TYPE')) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:wrappers.py

示例9: _load_form_data

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def _load_form_data(self):
        """Method used internally to retrieve submitted data.  After calling
        this sets `form` and `files` on the request object to multi dicts
        filled with the incoming form data.  As a matter of fact the input
        stream will be empty afterwards.  You can also call this method to
        force the parsing of the form data.

        .. versionadded:: 0.8
        """
        # abort early if we have already consumed the stream
        if 'form' in self.__dict__:
            return

        _assert_not_shallow(self)

        if self.want_form_data_parsed:
            content_type = self.environ.get('CONTENT_TYPE', '')
            content_length = get_content_length(self.environ)
            mimetype, options = parse_options_header(content_type)
            parser = self.make_form_data_parser()
            data = parser.parse(self._get_stream_for_parsing(),
                                mimetype, content_length, options)
        else:
            data = (self.stream, self.parameter_storage_class(),
                    self.parameter_storage_class())

        # inject the values into the instance dict so that we bypass
        # our cached_property non-data descriptor.
        d = self.__dict__
        d['stream'], d['form'], d['files'] = data 
开发者ID:jpush,项目名称:jbox,代码行数:32,代码来源:wrappers.py

示例10: args

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def args(self):
        """The parsed URL parameters.  By default an
        :class:`~werkzeug.datastructures.ImmutableMultiDict`
        is returned from this function.  This can be changed by setting
        :attr:`parameter_storage_class` to a different type.  This might
        be necessary if the order of the form data is important.
        """
        return url_decode(wsgi_get_bytes(self.environ.get('QUERY_STRING', '')),
                          self.url_charset, errors=self.encoding_errors,
                          cls=self.parameter_storage_class) 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:wrappers.py

示例11: cookies

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def cookies(self):
        """Read only access to the retrieved cookie values as dictionary."""
        return parse_cookie(self.environ, self.charset,
                            self.encoding_errors,
                            cls=self.dict_storage_class) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:wrappers.py

示例12: headers

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def headers(self):
        """The headers from the WSGI environ as immutable
        :class:`~werkzeug.datastructures.EnvironHeaders`.
        """
        return EnvironHeaders(self.environ) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:wrappers.py

示例13: path

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def path(self):
        """Requested path as unicode.  This works a bit like the regular path
        info in the WSGI environment but will always include a leading slash,
        even if the URL root is accessed.
        """
        raw_path = wsgi_decoding_dance(self.environ.get('PATH_INFO') or '',
                                       self.charset, self.encoding_errors)
        return '/' + raw_path.lstrip('/') 
开发者ID:jpush,项目名称:jbox,代码行数:10,代码来源:wrappers.py

示例14: script_root

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def script_root(self):
        """The root path of the script without the trailing slash."""
        raw_path = wsgi_decoding_dance(self.environ.get('SCRIPT_NAME') or '',
                                       self.charset, self.encoding_errors)
        return raw_path.rstrip('/') 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:wrappers.py

示例15: base_url

# 需要导入模块: from werkzeug.wrappers import BaseRequest [as 别名]
# 或者: from werkzeug.wrappers.BaseRequest import environ [as 别名]
def base_url(self):
        """Like :attr:`url` but without the querystring
        See also: :attr:`trusted_hosts`.
        """
        return get_current_url(self.environ, strip_querystring=True,
                               trusted_hosts=self.trusted_hosts) 
开发者ID:jpush,项目名称:jbox,代码行数:8,代码来源:wrappers.py


注:本文中的werkzeug.wrappers.BaseRequest.environ方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。