Python http.cookies.CookieError() Examples
The following are 22
code examples of http.cookies.CookieError().
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
http.cookies
, or try the search function
.
Example #1
Source File: test_http_cookies.py From android_universal with MIT License | 6 votes |
def test_setdefault(self): morsel = cookies.Morsel() morsel.update({ 'domain': 'example.com', 'version': 2, }) # this shouldn't override the default value self.assertEqual(morsel.setdefault('expires', 'value'), '') self.assertEqual(morsel['expires'], '') self.assertEqual(morsel.setdefault('Version', 1), 2) self.assertEqual(morsel['version'], 2) self.assertEqual(morsel.setdefault('DOMAIN', 'value'), 'example.com') self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel.setdefault('invalid', 'value') self.assertNotIn('invalid', morsel)
Example #2
Source File: test_http_cookies.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_setdefault(self): morsel = cookies.Morsel() morsel.update({ 'domain': 'example.com', 'version': 2, }) # this shouldn't override the default value self.assertEqual(morsel.setdefault('expires', 'value'), '') self.assertEqual(morsel['expires'], '') self.assertEqual(morsel.setdefault('Version', 1), 2) self.assertEqual(morsel['version'], 2) self.assertEqual(morsel.setdefault('DOMAIN', 'value'), 'example.com') self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel.setdefault('invalid', 'value') self.assertNotIn('invalid', morsel)
Example #3
Source File: test_http_cookies.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_setdefault(self): morsel = cookies.Morsel() morsel.update({ 'domain': 'example.com', 'version': 2, }) # this shouldn't override the default value self.assertEqual(morsel.setdefault('expires', 'value'), '') self.assertEqual(morsel['expires'], '') self.assertEqual(morsel.setdefault('Version', 1), 2) self.assertEqual(morsel['version'], 2) self.assertEqual(morsel.setdefault('DOMAIN', 'value'), 'example.com') self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel.setdefault('invalid', 'value') self.assertNotIn('invalid', morsel)
Example #4
Source File: test_http_cookies.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_setter(self): M = cookies.Morsel() # tests the .set method to set keys and their values for i in M._reserved: # Makes sure that all reserved keys can't be set this way self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i) for i in "thou cast _the- !holy! ^hand| +*grenade~".split(): # Try typical use case. Setting decent values. # Check output and js_output. M['path'] = '/foo' # Try a reserved key as well M.set(i, "%s_val" % i, "%s_coded_val" % i) self.assertEqual( M.output(), "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) expected_js_output = """ <script type="text/javascript"> <!-- begin hiding document.cookie = "%s=%s; Path=/foo"; // end hiding --> </script> """ % (i, "%s_coded_val" % i) self.assertEqual(M.js_output(), expected_js_output) for i in ["foo bar", "foo@bar"]: # Try some illegal characters self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i)
Example #5
Source File: test_http_cookies.py From android_universal with MIT License | 5 votes |
def test_setitem(self): morsel = cookies.Morsel() morsel['expires'] = 0 self.assertEqual(morsel['expires'], 0) morsel['Version'] = 2 self.assertEqual(morsel['version'], 2) morsel['DOMAIN'] = 'example.com' self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel['invalid'] = 'value' self.assertNotIn('invalid', morsel)
Example #6
Source File: test_http_cookies.py From android_universal with MIT License | 5 votes |
def test_setter(self): M = cookies.Morsel() # tests the .set method to set keys and their values for i in M._reserved: # Makes sure that all reserved keys can't be set this way self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i) for i in "thou cast _the- !holy! ^hand| +*grenade~".split(): # Try typical use case. Setting decent values. # Check output and js_output. M['path'] = '/foo' # Try a reserved key as well M.set(i, "%s_val" % i, "%s_coded_val" % i) self.assertEqual(M.key, i) self.assertEqual(M.value, "%s_val" % i) self.assertEqual(M.coded_value, "%s_coded_val" % i) self.assertEqual( M.output(), "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) expected_js_output = """ <script type="text/javascript"> <!-- begin hiding document.cookie = "%s=%s; Path=/foo"; // end hiding --> </script> """ % (i, "%s_coded_val" % i) self.assertEqual(M.js_output(), expected_js_output) for i in ["foo bar", "foo@bar"]: # Try some illegal characters self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i)
Example #7
Source File: test_http_cookies.py From android_universal with MIT License | 5 votes |
def test_reserved_keys(self): M = cookies.Morsel() # tests valid and invalid reserved keys for Morsels for i in M._reserved: # Test that all valid keys are reported as reserved and set them self.assertTrue(M.isReservedKey(i)) M[i] = '%s_value' % i for i in M._reserved: # Test that valid key values come out fine self.assertEqual(M[i], '%s_value' % i) for i in "the holy hand grenade".split(): # Test that invalid keys raise CookieError self.assertRaises(cookies.CookieError, M.__setitem__, i, '%s_value' % i)
Example #8
Source File: test_http_cookies.py From android_universal with MIT License | 5 votes |
def test_illegal_chars(self): rawdata = "a=b; c,d=e" C = cookies.SimpleCookie() with self.assertRaises(cookies.CookieError): C.load(rawdata)
Example #9
Source File: http.py From JWTConnect-Python-OidcRP with Apache License 2.0 | 5 votes |
def set_cookie(self, response): try: _cookie = response.headers["set-cookie"] logger.debug("RECEIVED COOKIE") try: # add received cookies to the cookie jar set_cookie(self.cookiejar, SimpleCookie(_cookie)) except CookieError as err: logger.error(err) raise NonFatalException(response, "{}".format(err)) except (AttributeError, KeyError) as err: pass
Example #10
Source File: test_http_cookies.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_setitem(self): morsel = cookies.Morsel() morsel['expires'] = 0 self.assertEqual(morsel['expires'], 0) morsel['Version'] = 2 self.assertEqual(morsel['version'], 2) morsel['DOMAIN'] = 'example.com' self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel['invalid'] = 'value' self.assertNotIn('invalid', morsel)
Example #11
Source File: _cprequest.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
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() headers[name] = httputil.decode_TEXT_maybe(value) # Some clients, notably Konquoror, supply multiple # cookies on different lines with the same key. To # handle this case, store all cookies in self.cookie. if name == 'Cookie': try: self.cookie.load(value) except CookieError as exc: raise cherrypy.HTTPError(400, str(exc)) 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)
Example #12
Source File: test_http_cookies.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_reserved_keys(self): M = cookies.Morsel() # tests valid and invalid reserved keys for Morsels for i in M._reserved: # Test that all valid keys are reported as reserved and set them self.assertTrue(M.isReservedKey(i)) M[i] = '%s_value' % i for i in M._reserved: # Test that valid key values come out fine self.assertEqual(M[i], '%s_value' % i) for i in "the holy hand grenade".split(): # Test that invalid keys raise CookieError self.assertRaises(cookies.CookieError, M.__setitem__, i, '%s_value' % i)
Example #13
Source File: test_http_cookies.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_illegal_chars(self): rawdata = "a=b; c,d=e" C = cookies.SimpleCookie() with self.assertRaises(cookies.CookieError): C.load(rawdata)
Example #14
Source File: test_http_cookies.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_setter(self): M = cookies.Morsel() # tests the .set method to set keys and their values for i in M._reserved: # Makes sure that all reserved keys can't be set this way self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i) for i in "thou cast _the- !holy! ^hand| +*grenade~".split(): # Try typical use case. Setting decent values. # Check output and js_output. M['path'] = '/foo' # Try a reserved key as well M.set(i, "%s_val" % i, "%s_coded_val" % i) self.assertEqual( M.output(), "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) expected_js_output = """ <script type="text/javascript"> <!-- begin hiding document.cookie = "%s=%s; Path=/foo"; // end hiding --> </script> """ % (i, "%s_coded_val" % i) self.assertEqual(M.js_output(), expected_js_output) for i in ["foo bar", "foo@bar"]: # Try some illegal characters self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i)
Example #15
Source File: test_http_cookies.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_reserved_keys(self): M = cookies.Morsel() # tests valid and invalid reserved keys for Morsels for i in M._reserved: # Test that all valid keys are reported as reserved and set them self.assertTrue(M.isReservedKey(i)) M[i] = '%s_value' % i for i in M._reserved: # Test that valid key values come out fine self.assertEqual(M[i], '%s_value' % i) for i in "the holy hand grenade".split(): # Test that invalid keys raise CookieError self.assertRaises(cookies.CookieError, M.__setitem__, i, '%s_value' % i)
Example #16
Source File: test_http_cookies.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_update(self): attribs = {'expires': 1, 'Version': 2, 'DOMAIN': 'example.com'} # test dict update morsel = cookies.Morsel() morsel.update(attribs) self.assertEqual(morsel['expires'], 1) self.assertEqual(morsel['version'], 2) self.assertEqual(morsel['domain'], 'example.com') # test iterable update morsel = cookies.Morsel() morsel.update(list(attribs.items())) self.assertEqual(morsel['expires'], 1) self.assertEqual(morsel['version'], 2) self.assertEqual(morsel['domain'], 'example.com') # test iterator update morsel = cookies.Morsel() morsel.update((k, v) for k, v in attribs.items()) self.assertEqual(morsel['expires'], 1) self.assertEqual(morsel['version'], 2) self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel.update({'invalid': 'value'}) self.assertNotIn('invalid', morsel) self.assertRaises(TypeError, morsel.update) self.assertRaises(TypeError, morsel.update, 0)
Example #17
Source File: test_http_cookies.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_setitem(self): morsel = cookies.Morsel() morsel['expires'] = 0 self.assertEqual(morsel['expires'], 0) morsel['Version'] = 2 self.assertEqual(morsel['version'], 2) morsel['DOMAIN'] = 'example.com' self.assertEqual(morsel['domain'], 'example.com') with self.assertRaises(cookies.CookieError): morsel['invalid'] = 'value' self.assertNotIn('invalid', morsel)
Example #18
Source File: test_http_cookies.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_setter(self): M = cookies.Morsel() # tests the .set method to set keys and their values for i in M._reserved: # Makes sure that all reserved keys can't be set this way self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i) for i in "thou cast _the- !holy! ^hand| +*grenade~".split(): # Try typical use case. Setting decent values. # Check output and js_output. M['path'] = '/foo' # Try a reserved key as well M.set(i, "%s_val" % i, "%s_coded_val" % i) self.assertEqual( M.output(), "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i)) expected_js_output = """ <script type="text/javascript"> <!-- begin hiding document.cookie = "%s=%s; Path=/foo"; // end hiding --> </script> """ % (i, "%s_coded_val" % i) self.assertEqual(M.js_output(), expected_js_output) for i in ["foo bar", "foo@bar"]: # Try some illegal characters self.assertRaises(cookies.CookieError, M.set, i, '%s_value' % i, '%s_value' % i)
Example #19
Source File: test_http_cookies.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_reserved_keys(self): M = cookies.Morsel() # tests valid and invalid reserved keys for Morsels for i in M._reserved: # Test that all valid keys are reported as reserved and set them self.assertTrue(M.isReservedKey(i)) M[i] = '%s_value' % i for i in M._reserved: # Test that valid key values come out fine self.assertEqual(M[i], '%s_value' % i) for i in "the holy hand grenade".split(): # Test that invalid keys raise CookieError self.assertRaises(cookies.CookieError, M.__setitem__, i, '%s_value' % i)
Example #20
Source File: client_reqrep.py From Galaxy_Plugin_Bethesda with MIT License | 4 votes |
def start(self, connection: 'Connection') -> 'ClientResponse': """Start response processing.""" self._closed = False self._protocol = connection.protocol self._connection = connection with self._timer: while True: # read response try: message, payload = await self._protocol.read() # type: ignore # noqa except http.HttpProcessingError as exc: raise ClientResponseError( self.request_info, self.history, status=exc.code, message=exc.message, headers=exc.headers) from exc if (message.code < 100 or message.code > 199 or message.code == 101): break if self._continue is not None: set_result(self._continue, True) self._continue = None # payload eof handler payload.on_eof(self._response_eof) # response status self.version = message.version self.status = message.code self.reason = message.reason # headers self._headers = message.headers # type is CIMultiDictProxy self._raw_headers = message.raw_headers # type is Tuple[bytes, bytes] # payload self.content = payload # cookies for hdr in self.headers.getall(hdrs.SET_COOKIE, ()): try: self.cookies.load(hdr) except CookieError as exc: client_logger.warning( 'Can not load response cookies: %s', exc) return self
Example #21
Source File: client_reqrep.py From lambda-text-extractor with Apache License 2.0 | 4 votes |
def start(self, connection, read_until_eof=False): """Start response processing.""" self._closed = False self._protocol = connection.protocol self._connection = connection connection.protocol.set_response_params( timer=self._timer, skip_payload=self.method.lower() == 'head', skip_status_codes=(204, 304), read_until_eof=read_until_eof) with self._timer: while True: # read response try: (message, payload) = yield from self._protocol.read() except http.HttpProcessingError as exc: raise ClientResponseError( self.request_info, self.history, code=exc.code, message=exc.message, headers=exc.headers) from exc if (message.code < 100 or message.code > 199 or message.code == 101): break if self._continue is not None and not self._continue.done(): self._continue.set_result(True) self._continue = None # payload eof handler payload.on_eof(self._response_eof) # response status self.version = message.version self.status = message.code self.reason = message.reason # headers self.headers = CIMultiDictProxy(message.headers) self.raw_headers = tuple(message.raw_headers) # payload self.content = payload # cookies for hdr in self.headers.getall(hdrs.SET_COOKIE, ()): try: self.cookies.load(hdr) except CookieError as exc: client_logger.warning( 'Can not load response cookies: %s', exc) return self
Example #22
Source File: client_reqrep.py From lambda-text-extractor with Apache License 2.0 | 4 votes |
def start(self, connection, read_until_eof=False): """Start response processing.""" self._closed = False self._protocol = connection.protocol self._connection = connection connection.protocol.set_response_params( timer=self._timer, skip_payload=self.method.lower() == 'head', skip_status_codes=(204, 304), read_until_eof=read_until_eof) with self._timer: while True: # read response try: (message, payload) = yield from self._protocol.read() except http.HttpProcessingError as exc: raise ClientResponseError( self.request_info, self.history, code=exc.code, message=exc.message, headers=exc.headers) from exc if (message.code < 100 or message.code > 199 or message.code == 101): break if self._continue is not None and not self._continue.done(): self._continue.set_result(True) self._continue = None # payload eof handler payload.on_eof(self._response_eof) # response status self.version = message.version self.status = message.code self.reason = message.reason # headers self.headers = CIMultiDictProxy(message.headers) self.raw_headers = tuple(message.raw_headers) # payload self.content = payload # cookies for hdr in self.headers.getall(hdrs.SET_COOKIE, ()): try: self.cookies.load(hdr) except CookieError as exc: client_logger.warning( 'Can not load response cookies: %s', exc) return self