コード例 #1
0
	def _update_cookies(self, response):
		cookies = Cookie()
		
		# Load any generated cookies.
		for cookie in response.headers.getall('Set-Cookie'):
			cookies.load(cookie)
		
		self.cookies.update({i.name.decode('ascii'): i.value.decode('ascii') for i in cookies.values()})
コード例 #2
0
ファイル: conftest.py プロジェクト: QPanWeb/FM_PY-pyramid
 def get_cookie(self, name, default=None):
     # webtest currently doesn't expose the unescaped cookie values
     # so we're using webob to parse them for us
     # see https://github.com/Pylons/webtest/issues/171
     cookie = Cookie(' '.join('%s=%s' % (c.name, c.value)
                              for c in self.cookiejar if c.name == name))
     return next(
         (m.value.decode('latin-1') for m in cookie.values()),
         default,
     )
コード例 #3
0
ファイル: common.py プロジェクト: Hazer/WebCore
    def _handle_cookies(self, resp):
        existing = resp.headers.getall("Set-Cookie")
        if not existing:
            return dict()

        cookies = Cookie()
        for header in existing:
            cookies.load(header)

        for key in cookies:
            self._cookies[key] = cookies[key].value
コード例 #4
0
ファイル: cookies.py プロジェクト: oscarchan/oc.python
def get_cookie(response, key):
    existing = response.headers.getall("Set-Cookie")
    if not existing:
        return False

    cookies = Cookie()
    for header in existing:
        cookies.load(header)

    if isinstance(key, text_type):
        key = key.encode("utf8")

    if key in cookies:
        return cookies[key]

    return None
コード例 #5
0
def parse_response_cookies(request_or_response) -> Cookie:
    try:
        response = make_response(request_or_response)
    except AttributeError:
        response = request_or_response

    headers = response.headers.getall('Set-Cookie')
    return Cookie('\r\n'.join(headers))
コード例 #6
0
ファイル: response.py プロジェクト: startup-one/cogofly
 def unset_cookie(self, key, strict=True):
     """
     Unset a cookie with the given name (remove it from the
     response).
     """
     existing = self.headers.getall('Set-Cookie')
     if not existing and not strict:
         return
     cookies = Cookie()
     for header in existing:
         cookies.load(header)
     if key in cookies:
         del cookies[key]
         del self.headers['Set-Cookie']
         for m in list(cookies.values()):
             self.headerlist.append(('Set-Cookie', str(m)))
     elif strict:
         raise KeyError("No cookie has been set with the name %r" % key)
コード例 #7
0
ファイル: response.py プロジェクト: 404minds/quiz-forest
 def unset_cookie(self, key, strict=True):
     """
     Unset a cookie with the given name (remove it from the
     response).
     """
     existing = self.headers.getall('Set-Cookie')
     if not existing and not strict:
         return
     cookies = Cookie()
     for header in existing:
         cookies.load(header)
     if key in cookies:
         del cookies[key]
         del self.headers['Set-Cookie']
         for m in cookies.values():
             self.headerlist.append(('Set-Cookie', str(m)))
     elif strict:
         raise KeyError("No cookie has been set with the name %r" % key)
コード例 #8
0
ファイル: response.py プロジェクト: rylz/webob
 def unset_cookie(self, name, strict=True):
     """
     Unset a cookie with the given name (remove it from the
     response).
     """
     existing = self.headers.getall('Set-Cookie')
     if not existing and not strict:
         return
     cookies = Cookie()
     for header in existing:
         cookies.load(header)
     if isinstance(name, text_type):
         name = name.encode('utf8')
     if name in cookies:
         del cookies[name]
         del self.headers['Set-Cookie']
         for m in cookies.values():
             self.headerlist.append(('Set-Cookie', m.serialize()))
     elif strict:
         raise KeyError("No cookie has been set with the name %r" % name)
コード例 #9
0
 def unset_cookie(self, name, strict=True):
     """
     Unset a cookie with the given name (remove it from the
     response).
     """
     existing = self.headers.getall('Set-Cookie')
     if not existing and not strict:
         return
     cookies = Cookie()
     for header in existing:
         cookies.load(header)
     if isinstance(name, text_type):
         name = name.encode('utf8')
     if name in cookies:
         del cookies[name]
         del self.headers['Set-Cookie']
         for m in cookies.values():
             self.headerlist.append(('Set-Cookie', m.serialize()))
     elif strict:
         raise KeyError("No cookie has been set with the name %r" % name)
コード例 #10
0
ファイル: renderers.py プロジェクト: kidaa/encoded
    def normalize_cookie_tween(request):
        if request.path in ignore or request.path.startswith("/static/"):
            return handler(request)

        session = request.session
        if session or session._cookie_name not in request.cookies:
            return handler(request)

        response = handler(request)
        existing = response.headers.getall("Set-Cookie")
        if existing:
            cookies = Cookie()
            for header in existing:
                cookies.load(header)
            if session._cookie_name in cookies:
                return response

        response.delete_cookie(session._cookie_name, path=session._cookie_path, domain=session._cookie_domain)

        return response
コード例 #11
0
ファイル: response.py プロジェクト: mvidner/webob
 def unset_cookie(self, key, strict=True):
     """
     Unset a cookie with the given name (remove it from the
     response).
     """
     existing = self.headers.getall("Set-Cookie")
     if not existing and not strict:
         return
     cookies = Cookie()
     for header in existing:
         cookies.load(header)
     if isinstance(key, text_type):
         key = key.encode("utf8")
     if key in cookies:
         del cookies[key]
         del self.headers["Set-Cookie"]
         for m in cookies.values():
             self.headerlist.append(("Set-Cookie", m.serialize()))
     elif strict:
         raise KeyError("No cookie has been set with the name %r" % key)
コード例 #12
0
ファイル: request.py プロジェクト: dargonar/DirectoDueno
 def _str_cookies(self):
     env = self.environ
     source = env.get('HTTP_COOKIE', '')
     if 'webob._parsed_cookies' in env:
         vars, var_source = env['webob._parsed_cookies']
         if var_source == source:
             return vars
     vars = {}
     if source:
         cookies = Cookie(source)
         for name in cookies:
             vars[name] = cookies[name].value
     env['webob._parsed_cookies'] = (vars, source)
     return vars
コード例 #13
0
ファイル: renderers.py プロジェクト: T2DREAM/t2dream-portal
    def normalize_cookie_tween(request):
        if request.path in ignore or request.path.startswith('/static/'):
            return handler(request)

        session = request.session
        if session or session._cookie_name not in request.cookies:
            return handler(request)

        response = handler(request)
        existing = response.headers.getall('Set-Cookie')
        if existing:
            cookies = Cookie()
            for header in existing:
                cookies.load(header)
            if session._cookie_name in cookies:
                return response

        response.delete_cookie(
            session._cookie_name,
            path=session._cookie_path,
            domain=session._cookie_domain,
        )

        return response
コード例 #14
0
ファイル: request.py プロジェクト: dholth/webob
 def str_cookies(self):
     """
     Return a *plain* dictionary of cookies as found in the request.
     """
     env = self.environ
     source = env.get('HTTP_COOKIE', '')
     if 'webob._parsed_cookies' in env:
         vars, var_source = env['webob._parsed_cookies']
         if var_source == source:
             return vars
     vars = {}
     if source:
         cookies = Cookie(source)
         for name in cookies:
             vars[name] = cookies[name].value
     env['webob._parsed_cookies'] = (vars, source)
     return vars
コード例 #15
0
 def cookies(self):
     """
     A dictionary of cookies as found in the request.
     """
     env = self.environ
     source = env.get('HTTP_COOKIE', '')
     if 'webob._parsed_cookies' in env:
         vars, var_source = env['webob._parsed_cookies']
         if var_source == source:
             return vars
     vars = {}
     if source:
         cookies = Cookie(source)
         for name in cookies:
             vars[name] = cookies[name].value
     #@@ decode directly
     vars = UnicodeMultiDict(vars,
                             encoding=self.charset,
                             errors=self.unicode_errors)
     env['webob._parsed_cookies'] = (vars, source)
     return vars