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


Python SimpleCookie.load方法代码示例

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


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

示例1: Request

# 需要导入模块: from cherrypy._cpcompat import SimpleCookie [as 别名]
# 或者: from cherrypy._cpcompat.SimpleCookie import load [as 别名]

#.........这里部分代码省略.........
            p = httputil.parse_query_string(self.query_string, encoding=self.query_string_encoding)
        except UnicodeDecodeError:
            raise cherrypy.HTTPError(
                404,
                "The given query string could not be processed. Query "
                "strings for this resource must be encoded with %r." % self.query_string_encoding,
            )

        # Python 2 only: keyword arguments must be byte strings (type 'str').
        if not py3k:
            for key, value in p.items():
                if isinstance(key, unicode):
                    del p[key]
                    p[key.encode(self.query_string_encoding)] = value
        self.params.update(p)

    def process_headers(self):
        """Parse HTTP header data into Python structures. (Core)"""
        # Process the headers into self.headers
        headers = self.headers
        for name, value in self.header_list:
            # Call title() now (and use dict.__method__(headers))
            # so title doesn't have to be called twice.
            name = name.title()
            value = value.strip()

            # Warning: if there is more than one header entry for cookies (AFAIK,
            # only Konqueror does that), only the last one will remain in headers
            # (but they will be correctly stored in request.cookie).
            if "=?" in value:
                dict.__setitem__(headers, name, httputil.decode_TEXT(value))
            else:
                dict.__setitem__(headers, name, value)

            # Handle cookies differently because on Konqueror, multiple
            # cookies come on different lines with the same key
            if name == "Cookie":
                try:
                    self.cookie.load(value)
                except CookieError:
                    msg = "Illegal cookie name %s" % value.split("=")[0]
                    raise cherrypy.HTTPError(400, msg)

        if not dict.__contains__(headers, "Host"):
            # All Internet-based HTTP/1.1 servers MUST respond with a 400
            # (Bad Request) status code to any HTTP/1.1 request message
            # which lacks a Host header field.
            if self.protocol >= (1, 1):
                msg = "HTTP/1.1 requires a 'Host' request header."
                raise cherrypy.HTTPError(400, msg)
        host = dict.get(headers, "Host")
        if not host:
            host = self.local.name or self.local.ip
        self.base = "%s://%s" % (self.scheme, host)

    def get_resource(self, path):
        """Call a dispatcher (which sets self.handler and .config). (Core)"""
        # First, see if there is a custom dispatch at this URI. Custom
        # dispatchers can only be specified in app.config, not in _cp_config
        # (since custom dispatchers may not even have an app.root).
        dispatch = self.app.find_config(path, "request.dispatch", self.dispatch)

        # dispatch() should set self.handler and self.config
        dispatch(path)

    def handle_error(self):
        """Handle the last unanticipated exception. (Core)"""
        try:
            self.hooks.run("before_error_response")
            if self.error_response:
                self.error_response()
            self.hooks.run("after_error_response")
            cherrypy.serving.response.finalize()
        except cherrypy.HTTPRedirect:
            inst = sys.exc_info()[1]
            inst.set_response()
            cherrypy.serving.response.finalize()

    # ------------------------- Properties ------------------------- #

    def _get_body_params(self):
        warnings.warn(
            "body_params is deprecated in CherryPy 3.2, will be removed in " "CherryPy 3.3.", DeprecationWarning
        )
        return self.body.params

    body_params = property(
        _get_body_params,
        doc="""
    If the request Content-Type is 'application/x-www-form-urlencoded' or
    multipart, this will be a dict of the params pulled from the entity
    body; that is, it will be the portion of request.params that come
    from the message body (sometimes called "POST params", although they
    can be sent with various HTTP method verbs). This value is set between
    the 'before_request_body' and 'before_handler' hooks (assuming that
    process_request_body is True).

    Deprecated in 3.2, will be removed for 3.3 in favor of
    :attr:`request.body.params<cherrypy._cprequest.RequestBody.params>`.""",
    )
开发者ID:429eagle,项目名称:BitTorrent.bundle,代码行数:104,代码来源:_cprequest.py

示例2: Request

# 需要导入模块: from cherrypy._cpcompat import SimpleCookie [as 别名]
# 或者: from cherrypy._cpcompat.SimpleCookie import load [as 别名]

#.........这里部分代码省略.........
                self.toolmaps = {}
                self.stage = 'get_resource'
                self.get_resource(path_info)
                self.body = _cpreqbody.RequestBody(self.rfile, self.headers, request_params=self.params)
                self.namespaces(self.config)
                self.stage = 'on_start_resource'
                self.hooks.run('on_start_resource')
                self.stage = 'process_query_string'
                self.process_query_string()
                if self.process_request_body:
                    if self.method not in self.methods_with_bodies:
                        self.process_request_body = False
                self.stage = 'before_request_body'
                self.hooks.run('before_request_body')
                if self.process_request_body:
                    self.body.process()
                self.stage = 'before_handler'
                self.hooks.run('before_handler')
                if self.handler:
                    self.stage = 'handler'
                    response.body = self.handler()
                self.stage = 'before_finalize'
                self.hooks.run('before_finalize')
                response.finalize()
            except (cherrypy.HTTPRedirect, cherrypy.HTTPError):
                inst = sys.exc_info()[1]
                inst.set_response()
                self.stage = 'before_finalize (HTTPError)'
                self.hooks.run('before_finalize')
                response.finalize()
            finally:
                self.stage = 'on_end_resource'
                self.hooks.run('on_end_resource')

        except self.throws:
            raise
        except:
            if self.throw_errors:
                raise
            self.handle_error()

    def process_query_string(self):
        try:
            p = httputil.parse_query_string(self.query_string, encoding=self.query_string_encoding)
        except UnicodeDecodeError:
            raise cherrypy.HTTPError(404, 'The given query string could not be processed. Query strings for this resource must be encoded with %r.' % self.query_string_encoding)

        for key, value in p.items():
            if isinstance(key, unicode):
                del p[key]
                p[key.encode(self.query_string_encoding)] = value

        self.params.update(p)

    def process_headers(self):
        headers = self.headers
        for name, value in self.header_list:
            name = name.title()
            value = value.strip()
            if '=?' in value:
                dict.__setitem__(headers, name, httputil.decode_TEXT(value))
            else:
                dict.__setitem__(headers, name, value)
            if name == 'Cookie':
                try:
                    self.cookie.load(value)
                except CookieError:
                    msg = 'Illegal cookie name %s' % value.split('=')[0]
                    raise cherrypy.HTTPError(400, msg)

        if not dict.__contains__(headers, 'Host'):
            if self.protocol >= (1, 1):
                msg = "HTTP/1.1 requires a 'Host' request header."
                raise cherrypy.HTTPError(400, msg)
        host = dict.get(headers, 'Host')
        if not host:
            host = self.local.name or self.local.ip
        self.base = '%s://%s' % (self.scheme, host)

    def get_resource(self, path):
        dispatch = self.app.find_config(path, 'request.dispatch', self.dispatch)
        dispatch(path)

    def handle_error(self):
        try:
            self.hooks.run('before_error_response')
            if self.error_response:
                self.error_response()
            self.hooks.run('after_error_response')
            cherrypy.serving.response.finalize()
        except cherrypy.HTTPRedirect:
            inst = sys.exc_info()[1]
            inst.set_response()
            cherrypy.serving.response.finalize()

    def _get_body_params(self):
        warnings.warn('body_params is deprecated in CherryPy 3.2, will be removed in CherryPy 3.3.', DeprecationWarning)
        return self.body.params

    body_params = property(_get_body_params, doc='\n    If the request Content-Type is \'application/x-www-form-urlencoded\' or\n    multipart, this will be a dict of the params pulled from the entity\n    body; that is, it will be the portion of request.params that come\n    from the message body (sometimes called "POST params", although they\n    can be sent with various HTTP method verbs). This value is set between\n    the \'before_request_body\' and \'before_handler\' hooks (assuming that\n    process_request_body is True).\n    \n    Deprecated in 3.2, will be removed for 3.3 in favor of\n    :attr:`request.body.params<cherrypy._cprequest.RequestBody.params>`.')
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:104,代码来源:_cprequest.py


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