Python Cookie.BaseCookie() Examples
The following are 12
code examples of Cookie.BaseCookie().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Cookie
, or try the search function
.
Example #1
Source File: web.py From honeything with GNU General Public License v3.0 | 5 votes |
def cookies(self): """A dictionary of Cookie.Morsel objects.""" if not hasattr(self, "_cookies"): self._cookies = Cookie.BaseCookie() if "Cookie" in self.request.headers: try: self._cookies.load(self.request.headers["Cookie"]) except: self.clear_all_cookies() return self._cookies
Example #2
Source File: web.py From honeything with GNU General Public License v3.0 | 5 votes |
def set_cookie(self, name, value, domain=None, expires=None, path="/", expires_days=None, **kwargs): """Sets the given cookie name/value with the given options. Additional keyword arguments are set on the Cookie.Morsel directly. See http://docs.python.org/library/cookie.html#morsel-objects for available attributes. """ name = _utf8(name) value = _utf8(value) if re.search(r"[\x00-\x20]", name + value): # Don't let us accidentally inject bad stuff raise ValueError("Invalid cookie %r: %r" % (name, value)) if not hasattr(self, "_new_cookies"): self._new_cookies = [] new_cookie = Cookie.BaseCookie() self._new_cookies.append(new_cookie) new_cookie[name] = value if domain: new_cookie[name]["domain"] = domain if expires_days is not None and not expires: expires = datetime.datetime.utcnow() + datetime.timedelta( days=expires_days) if expires: timestamp = calendar.timegm(expires.utctimetuple()) new_cookie[name]["expires"] = email.utils.formatdate( timestamp, localtime=False, usegmt=True) if path: new_cookie[name]["path"] = path for k, v in kwargs.iteritems(): new_cookie[name][k] = v
Example #3
Source File: session.py From malwareHunter with GNU General Public License v2.0 | 5 votes |
def __init__(self, secret, input=None): self.secret = secret.encode('UTF-8') Cookie.BaseCookie.__init__(self, input)
Example #4
Source File: session.py From malwareHunter with GNU General Public License v2.0 | 5 votes |
def __init__(self, secret, input=None): self.secret = secret.encode('UTF-8') Cookie.BaseCookie.__init__(self, input)
Example #5
Source File: repeater.py From pappy-proxy with MIT License | 5 votes |
def cookies(self): try: cookie = hcookies.BaseCookie() cookie.load(self.headers.get("cookie")) return cookie except Exception as e: return hcookies.BaseCookie()
Example #6
Source File: repeater.py From pappy-proxy with MIT License | 5 votes |
def set_cookies(self, c): cookie_pairs = [] if isinstance(c, hcookies.BaseCookie()): # it's a basecookie for k in c: cookie_pairs.append('{}={}'.format(k, c[k].value)) else: # it's a dictionary for k, v in c.items(): cookie_pairs.append('{}={}'.format(k, v)) header_str = '; '.join(cookie_pairs) self.headers.set("Cookie", header_str)
Example #7
Source File: repeater.py From pappy-proxy with MIT License | 5 votes |
def cookies(self): try: cookie = hcookies.BaseCookie() for _, v in self.headers.pairs('set-cookie'): cookie.load(v) return cookie except Exception as e: return hcookies.BaseCookie()
Example #8
Source File: repeater.py From pappy-proxy with MIT License | 5 votes |
def set_cookies(self, c): self.headers.delete("set-cookie") if isinstance(c, hcookies.BaseCookie): cookies = c else: cookies = hcookies.BaseCookie() for k, v in c.items(): cookies[k] = v for _, m in c.items(): self.headers.add("Set-Cookie", m.OutputString())
Example #9
Source File: bulkload_deprecated.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def InfoPage(self, uri): """ Renders an information page with the POST endpoint and cookie flag. Args: uri: a string containing the request URI Returns: A string with the contents of the info page to be displayed """ page = """ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head> <title>Bulk Loader</title> </head><body>""" page += ('The bulk load endpoint is: <a href="%s">%s</a><br />\n' % (uri, uri)) cookies = os.environ.get('HTTP_COOKIE', None) if cookies: cookie = Cookie.BaseCookie(cookies) for param in ['ACSID', 'dev_appserver_login']: value = cookie.get(param) if value: page += ("Pass this flag to the client: --cookie='%s=%s'\n" % (param, value.value)) break else: page += 'No cookie found!\n' page += '</body></html>' return page
Example #10
Source File: base.py From mltshp with Mozilla Public License 2.0 | 5 votes |
def get_sid(self, response): cookie = Cookie.BaseCookie(response.headers['Set-Cookie']) return cookie['sid'].value
Example #11
Source File: nginx-ldap-auth-daemon.py From docker-ldap-auth with GNU General Public License v3.0 | 5 votes |
def get_cookie(self, name): cookies = self.headers.get('Cookie') if cookies: authcookie = BaseCookie(cookies).get(name) if authcookie: return authcookie.value else: return None else: return None # Log the error and complete the request with appropriate status
Example #12
Source File: fixture.py From mishkal with GNU General Public License v3.0 | 4 votes |
def do_request(self, req, status): """ Executes the given request (``req``), with the expected ``status``. Generally ``.get()`` and ``.post()`` are used instead. """ if self.pre_request_hook: self.pre_request_hook(self) __tracebackhide__ = True if self.cookies: c = BaseCookie() for name, value in self.cookies.items(): c[name] = value hc = '; '.join(['='.join([m.key, m.value]) for m in c.values()]) req.environ['HTTP_COOKIE'] = hc 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() raise_on_wsgi_error = not req.expect_errors raw_res = wsgilib.raw_interactive( app, req.url, raise_on_wsgi_error=raise_on_wsgi_error, **req.environ) end_time = time.time() finally: sys.stdout = old_stdout sys.stderr.write(out.getvalue()) res = self._make_response(raw_res, end_time - start_time) res.request = req 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 self.namespace is not None: self.namespace['res'] = res if not req.expect_errors: self._check_status(status, res) self._check_errors(res) res.cookies_set = {} for header in res.all_headers('set-cookie'): c = BaseCookie(header) for key, morsel in c.items(): self.cookies[key] = morsel.value res.cookies_set[key] = morsel.value if self.post_request_hook: self.post_request_hook(self) if self.namespace is None: # It's annoying to return the response in doctests, as it'll # be printed, so we only return it is we couldn't assign # it anywhere return res