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


Python SimpleCookie.items方法代码示例

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


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

示例1: is_present

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
        def is_present(mpkt):
            hdrs = mpkt.cfields.get('dissector.http.headers', None)

            if not hdrs:
                return False

            if 'cookie' in hdrs:
                for cstr in hdrs['cookie']:
                    cookie = SimpleCookie()
                    cookie.load(cstr)

                    for k, mar in cookie.items():
                        cookies[k].append(mar.value)

                return True

            elif 'set-cookie' in hdrs:
                for cstr in hdrs['set-cookie']:
                    cookie = SimpleCookie()
                    cookie.load(cstr)

                    for k, mar in cookie.items():
                        cookies[k].append(mar.value)

                return True

            return False
开发者ID:Paulxia,项目名称:PacketManipulator,代码行数:29,代码来源:main.py

示例2: cookies

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
    def cookies(self, rawdata):
        """Set Response Cookies.

        :param rawdata: (str or dict). List of `cookielib.Cookie`.
        """
        sc = SimpleCookie()
        sc.load(rawdata)
        self._cookies = sc.items()
开发者ID:importcjj,项目名称:myweb.py,代码行数:10,代码来源:http.py

示例3: get_cookies

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
def get_cookies(str):
    cookie = SimpleCookie()
    cookie.load(str)
 
    cookies = {}
    for key, morsel in cookie.items():
        cookies[key] = morsel.value
    return cookies
开发者ID:PhyzXeno,项目名称:pythonScripts,代码行数:10,代码来源:getCookie.py

示例4: middleware

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
def middleware(environ, start_response):
    request = Request(environ).copy()

    response = request.get_response(django)

    if response.status_int != 305:
        return response(environ, start_response)
    data = json.loads(response.body)

    proxy = RemoteProxy([data['base_url']], rewrite_links=True)

    request.environ.pop("HTTP_ACCEPT_ENCODING", None)

    request.environ['SCRIPT_NAME'] = str(data['script_name']).rstrip("/")
    request.environ['PATH_INFO'] = "/" + str(data['path_info'].lstrip("/") )

    from Cookie import SimpleCookie as Cookie
    orig_cookie = cookie = request.environ.get('HTTP_COOKIE')
    if cookie:
        cookie = Cookie(cookie)
        for key in data['cookie_blacklist']:
            cookie.pop(key, None)
        cookiestr = []
        for key, value in cookie.items():
            cookiestr.append(value.OutputString())
        cookiestr = "; ".join(cookiestr)
        request.environ['HTTP_COOKIE'] = cookiestr

    request.environ['HTTP_X_THING_THEME'] = data['theme']

    filter = deliverance(proxy)

    def per_project_theme(environ):
        return "%(wsgi.url_scheme)s://%(HTTP_HOST)s%(HTTP_X_THING_THEME)s" % environ
    filter.default_theme = per_project_theme
    filter.rule_getter = TemplateRuleGetter(data['deliverance_rules'])
    filter.use_internal_subrequest = lambda *args, **kw: False

    base_subrequest = filter.build_external_subrequest
    def build_external_subrequest(url, orig_req, log):
        subreq = base_subrequest(url, orig_req, log)
        if url.endswith("/theme/") and orig_cookie:
            subreq.environ['HTTP_COOKIE'] = orig_cookie
        return subreq
    filter.build_external_subrequest = build_external_subrequest

    resp = request.get_response(filter)

    return resp(request.environ, start_response)
开发者ID:ejucovy,项目名称:thing,代码行数:51,代码来源:wsgi.py

示例5: decompose_incoming_envelope

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
    def decompose_incoming_envelope(self, ctx, message):
        assert message == FlatDictDocument.REQUEST

        ctx.transport.itself.decompose_incoming_envelope(self, ctx, message)

        if self.parse_cookie:
            cookies = ctx.in_header_doc.get('cookie', [])
            for cookie_string in cookies:
                cookie = SimpleCookie()
                cookie.load(cookie_string)
                for k,v in cookie.items():
                    l = ctx.in_header_doc.get(k, [])
                    l.append(v.coded_value)
                    ctx.in_header_doc[k] = l

        logger.debug('\theader : %r' % (ctx.in_header_doc))
        logger.debug('\tbody   : %r' % (ctx.in_body_doc))
开发者ID:amgibson,项目名称:spyne,代码行数:19,代码来源:http.py

示例6: probe_securecookie

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
 def probe_securecookie(self):
     """Something that looks like a securecookie was detected"""
     rv = self.make_request(self.config.url)
     setcookie = rv.headers.get('set-cookie')
     if setcookie is None:
         return False
     if not '; Path=' in setcookie:
         return False
     cookie = SimpleCookie(setcookie)
     for key, morsel in cookie.items():
         if not '?' in morsel.value:
             continue
         try:
             morsel.value.split('?')[0].decode('base64')
             return True
         except Exception:
             return False
     return False
开发者ID:mitsuhiko,项目名称:probe,代码行数:20,代码来源:libprobe.py

示例7: build

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
        def build(resp):

            response = Response()

            # Pass settings over.
            response.config = self.config

            if resp:

                # Fallback to None if there's no staus_code, for whatever reason.
                response.status_code = getattr(resp, 'status', None)

                # Make headers case-insensitive.
                response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))

                # Start off with our local cookies.
                cookies = self.cookies or dict()

                # Add new cookies from the server.
                if 'set-cookie' in response.headers:
                    cookie_header = response.headers['set-cookie']

                    c = SimpleCookie()
                    c.load(cookie_header)

                    for k,v in c.items():
                        cookies.update({k: v.value})

                # Save cookies in Response.
                response.cookies = cookies

            # Save original resopnse for later.
            response.raw = resp

            if is_error:
                response.error = resp

            response.url = self.full_url

            return response
开发者ID:BGEray,项目名称:pyTOP,代码行数:42,代码来源:models.py

示例8: call_wsgi_app

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
def call_wsgi_app(wsgi_app, request, path_info):
    """
    Call the ``wsgi_app`` with ``request`` and return its response.
    
    :param wsgi_app: The WSGI application to be run.
    :type wsgi_app: callable
    :param request: The Django request.
    :type request: :class:`twod.wsgi.handler.TwodWSGIRequest`
    :param path_info: The ``PATH_INFO`` to be used by the WSGI application.
    :type path: :class:`basestring`
    :raises twod.wsgi.exc.ApplicationCallError: If ``path_info`` is not the
        last portion of the ``PATH_INFO`` in ``request``.
    :return: The response from the WSGI application, turned into a Django
        response.
    :rtype: :class:`twod.wsgi.TwodResponse`
    
    """
    new_request = request.copy()
    
    # Moving the portion of the path consumed by the current view, from the
    # PATH_INTO to the SCRIPT_NAME:
    if not request.path_info.endswith(path_info):
        raise ApplicationCallError("Path %s is not the last portion of the "
                                   "PATH_INFO in the original request (%s)"
                                   % (path_info, request.path_info))
    consumed_path = request.path_info[:-len(path_info)]
    new_request.path_info = path_info
    new_request.script_name = request.script_name + consumed_path
    
    # If the user has been authenticated in Django, log him in the WSGI app:
    if request.user.is_authenticated():
        new_request.remote_user = request.user.username
    
    # Cleaning the routing_args, if any. The application should have its own
    # arguments, without relying on any arguments from a parent application:
    if "wsgiorg.routing_args" in request.environ:
        del new_request.environ['wsgiorg.routing_args']
    # And the same for the WebOb ad-hoc attributes:
    if "webob.adhoc_attrs" in request.environ:
        del new_request.environ['webob.adhoc_attrs']
    
    # Calling the WSGI application and getting its response:
    (status, headers, body) = new_request.call_application(wsgi_app)
    
    # Turning its response into a Django response:
    cookies = SimpleCookie()
    django_response = TwodResponse(body, status=status)
    for (header, value) in headers:
        if header.upper() == "SET-COOKIE":
            if isinstance(value, unicode):
                # It can't be Unicode:
                value = value.encode("us-ascii")
            cookies.load(value)
        else:
            django_response[header] = value
    
    # Setting the cookies from Django:
    for (cookie_name, cookie) in cookies.items():
        cookie_attributes = {
            'key': cookie_name,
            'value': cookie.value,
            'max_age': cookie.get("max-age"),
            'expires': cookie.get("expires"),
            'path': cookie.get("path", "/"),
            'domain': cookie.get("domain"),
            }
        django_response.set_cookie(**cookie_attributes)
    return django_response
开发者ID:hekevintran,项目名称:twod.wsgi,代码行数:70,代码来源:embedded_wsgi.py

示例9: do_request

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import items [as 别名]
    def do_request(self, req, status, expect_errors):
        """
        Executes the given request (``req``), with the expected
        ``status``.  Generally ``.get()`` and ``.post()`` are used
        instead.

        To use this::

            resp = app.do_request(webtest.TestRequest.blank(
                'url', ...args...))

        Note you can pass any keyword arguments to
        ``TestRequest.blank()``, which will be set on the request.
        These can be arguments like ``content_type``, ``accept``, etc.
        """
        __tracebackhide__ = True
        errors = StringIO()
        req.environ['wsgi.errors'] = errors
        if self.cookies:
            cookie_header = ''.join([
                '%s=%s; ' % (name, cookie_quote(value))
                for name, value in self.cookies.items()])
            req.environ['HTTP_COOKIE'] = cookie_header
        req.environ['paste.testing'] = True
        req.environ['paste.testing_variables'] = {}
        app = lint.middleware(self.app)
        old_stdout = sys.stdout
        out = CaptureStdout(old_stdout)
        try:
            sys.stdout = out
            start_time = time.time()
            ## FIXME: should it be an option to not catch exc_info?
            res = req.get_response(app, catch_exc_info=True)
            end_time = time.time()
        finally:
            sys.stdout = old_stdout
        res.app = app
        res.test_app = self
        # We do this to make sure the app_iter is exausted:
        res.body
        res.errors = errors.getvalue()
        total_time = end_time - start_time
        for name, value in req.environ['paste.testing_variables'].items():
            if hasattr(res, name):
                raise ValueError(
                    "paste.testing_variables contains the variable %r, but "
                    "the response object already has an attribute by that "
                    "name" % name)
            setattr(res, name, value)
        if not expect_errors:
            self._check_status(status, res)
            self._check_errors(res)
        res.cookies_set = {}
        for header in res.headers.getall('set-cookie'):
            try:
                c = SimpleCookie(header)
            except CookieError, e:
                raise CookieError(
                    "Could not parse cookie header %r: %s" % (header, e))
            for key, morsel in c.items():
                self.cookies[key] = morsel.value
                res.cookies_set[key] = morsel.value
开发者ID:Anuja-D,项目名称:gae-sessions,代码行数:64,代码来源:__init__.py


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