Issue #29192: Removed deprecated features in the http.cookies module.
This commit is contained in:
parent
009b0a1fac
commit
cc283378d6
|
@ -148,39 +148,31 @@ Morsel Objects
|
||||||
:meth:`~Morsel.__eq__` now takes :attr:`~Morsel.key` and :attr:`~Morsel.value`
|
:meth:`~Morsel.__eq__` now takes :attr:`~Morsel.key` and :attr:`~Morsel.value`
|
||||||
into account.
|
into account.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.7
|
||||||
|
Attributes :attr:`~Morsel.key`, :attr:`~Morsel.value` and
|
||||||
|
:attr:`~Morsel.coded_value` are read-only. Use :meth:`~Morsel.set` for
|
||||||
|
setting them.
|
||||||
|
|
||||||
|
|
||||||
.. attribute:: Morsel.value
|
.. attribute:: Morsel.value
|
||||||
|
|
||||||
The value of the cookie.
|
The value of the cookie.
|
||||||
|
|
||||||
.. deprecated:: 3.5
|
|
||||||
assigning to ``value``; use :meth:`~Morsel.set` instead.
|
|
||||||
|
|
||||||
|
|
||||||
.. attribute:: Morsel.coded_value
|
.. attribute:: Morsel.coded_value
|
||||||
|
|
||||||
The encoded value of the cookie --- this is what should be sent.
|
The encoded value of the cookie --- this is what should be sent.
|
||||||
|
|
||||||
.. deprecated:: 3.5
|
|
||||||
assigning to ``coded_value``; use :meth:`~Morsel.set` instead.
|
|
||||||
|
|
||||||
|
|
||||||
.. attribute:: Morsel.key
|
.. attribute:: Morsel.key
|
||||||
|
|
||||||
The name of the cookie.
|
The name of the cookie.
|
||||||
|
|
||||||
.. deprecated:: 3.5
|
|
||||||
assigning to ``key``; use :meth:`~Morsel.set` instead.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Morsel.set(key, value, coded_value)
|
.. method:: Morsel.set(key, value, coded_value)
|
||||||
|
|
||||||
Set the *key*, *value* and *coded_value* attributes.
|
Set the *key*, *value* and *coded_value* attributes.
|
||||||
|
|
||||||
.. deprecated:: 3.5
|
|
||||||
The undocumented *LegalChars* parameter is ignored and will be removed in
|
|
||||||
a future version.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Morsel.isReservedKey(K)
|
.. method:: Morsel.isReservedKey(K)
|
||||||
|
|
||||||
|
|
|
@ -153,3 +153,10 @@ Changes in the Python API
|
||||||
* A format string argument for :meth:`string.Formatter.format`
|
* A format string argument for :meth:`string.Formatter.format`
|
||||||
is now :ref:`positional-only <positional-only_parameter>`.
|
is now :ref:`positional-only <positional-only_parameter>`.
|
||||||
(Contributed by Serhiy Storchaka in :issue:`29193`.)
|
(Contributed by Serhiy Storchaka in :issue:`29193`.)
|
||||||
|
|
||||||
|
* Attributes :attr:`~http.cookies.Morsel.key`,
|
||||||
|
:attr:`~http.cookies.Morsel.value` and
|
||||||
|
:attr:`~http.cookies.Morsel.coded_value` of class
|
||||||
|
:class:`http.cookies.Morsel` are now read-only.
|
||||||
|
Use the :meth:`~http.cookies.Morsel.set` method for setting them.
|
||||||
|
(Contributed by Serhiy Storchaka in :issue:`29192`.)
|
||||||
|
|
|
@ -138,12 +138,6 @@ _nulljoin = ''.join
|
||||||
_semispacejoin = '; '.join
|
_semispacejoin = '; '.join
|
||||||
_spacejoin = ' '.join
|
_spacejoin = ' '.join
|
||||||
|
|
||||||
def _warn_deprecated_setter(setter):
|
|
||||||
import warnings
|
|
||||||
msg = ('The .%s setter is deprecated. The attribute will be read-only in '
|
|
||||||
'future releases. Please use the set() method instead.' % setter)
|
|
||||||
warnings.warn(msg, DeprecationWarning, stacklevel=3)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Define an exception visible to External modules
|
# Define an exception visible to External modules
|
||||||
#
|
#
|
||||||
|
@ -303,29 +297,14 @@ class Morsel(dict):
|
||||||
def key(self):
|
def key(self):
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
@key.setter
|
|
||||||
def key(self, key):
|
|
||||||
_warn_deprecated_setter('key')
|
|
||||||
self._key = key
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def value(self):
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
@value.setter
|
|
||||||
def value(self, value):
|
|
||||||
_warn_deprecated_setter('value')
|
|
||||||
self._value = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def coded_value(self):
|
def coded_value(self):
|
||||||
return self._coded_value
|
return self._coded_value
|
||||||
|
|
||||||
@coded_value.setter
|
|
||||||
def coded_value(self, coded_value):
|
|
||||||
_warn_deprecated_setter('coded_value')
|
|
||||||
self._coded_value = coded_value
|
|
||||||
|
|
||||||
def __setitem__(self, K, V):
|
def __setitem__(self, K, V):
|
||||||
K = K.lower()
|
K = K.lower()
|
||||||
if not K in self._reserved:
|
if not K in self._reserved:
|
||||||
|
@ -366,14 +345,7 @@ class Morsel(dict):
|
||||||
def isReservedKey(self, K):
|
def isReservedKey(self, K):
|
||||||
return K.lower() in self._reserved
|
return K.lower() in self._reserved
|
||||||
|
|
||||||
def set(self, key, val, coded_val, LegalChars=_LegalChars):
|
def set(self, key, val, coded_val):
|
||||||
if LegalChars != _LegalChars:
|
|
||||||
import warnings
|
|
||||||
warnings.warn(
|
|
||||||
'LegalChars parameter is deprecated, ignored and will '
|
|
||||||
'be removed in future versions.', DeprecationWarning,
|
|
||||||
stacklevel=2)
|
|
||||||
|
|
||||||
if key.lower() in self._reserved:
|
if key.lower() in self._reserved:
|
||||||
raise CookieError('Attempt to set a reserved key %r' % (key,))
|
raise CookieError('Attempt to set a reserved key %r' % (key,))
|
||||||
if not _is_legal_key(key):
|
if not _is_legal_key(key):
|
||||||
|
|
|
@ -9,15 +9,6 @@ import warnings
|
||||||
|
|
||||||
class CookieTests(unittest.TestCase):
|
class CookieTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self._warnings_manager = check_warnings()
|
|
||||||
self._warnings_manager.__enter__()
|
|
||||||
warnings.filterwarnings("ignore", ".* class is insecure.*",
|
|
||||||
DeprecationWarning)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
self._warnings_manager.__exit__(None, None, None)
|
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
cases = [
|
cases = [
|
||||||
{'data': 'chips=ahoy; vienna=finger',
|
{'data': 'chips=ahoy; vienna=finger',
|
||||||
|
@ -256,6 +247,9 @@ class MorselTests(unittest.TestCase):
|
||||||
# Check output and js_output.
|
# Check output and js_output.
|
||||||
M['path'] = '/foo' # Try a reserved key as well
|
M['path'] = '/foo' # Try a reserved key as well
|
||||||
M.set(i, "%s_val" % i, "%s_coded_val" % i)
|
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(
|
self.assertEqual(
|
||||||
M.output(),
|
M.output(),
|
||||||
"Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i))
|
"Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i))
|
||||||
|
@ -272,16 +266,14 @@ class MorselTests(unittest.TestCase):
|
||||||
self.assertRaises(cookies.CookieError,
|
self.assertRaises(cookies.CookieError,
|
||||||
M.set, i, '%s_value' % i, '%s_value' % i)
|
M.set, i, '%s_value' % i, '%s_value' % i)
|
||||||
|
|
||||||
def test_deprecation(self):
|
def test_set_properties(self):
|
||||||
morsel = cookies.Morsel()
|
morsel = cookies.Morsel()
|
||||||
with self.assertWarnsRegex(DeprecationWarning, r'\bkey\b'):
|
with self.assertRaises(AttributeError):
|
||||||
morsel.key = ''
|
morsel.key = ''
|
||||||
with self.assertWarnsRegex(DeprecationWarning, r'\bvalue\b'):
|
with self.assertRaises(AttributeError):
|
||||||
morsel.value = ''
|
morsel.value = ''
|
||||||
with self.assertWarnsRegex(DeprecationWarning, r'\bcoded_value\b'):
|
with self.assertRaises(AttributeError):
|
||||||
morsel.coded_value = ''
|
morsel.coded_value = ''
|
||||||
with self.assertWarnsRegex(DeprecationWarning, r'\bLegalChars\b'):
|
|
||||||
morsel.set('key', 'value', 'coded_value', LegalChars='.*')
|
|
||||||
|
|
||||||
def test_eq(self):
|
def test_eq(self):
|
||||||
base_case = ('key', 'value', '"value"')
|
base_case = ('key', 'value', '"value"')
|
||||||
|
|
|
@ -212,6 +212,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #29192: Removed deprecated features in the http.cookies module.
|
||||||
|
|
||||||
- Issue #29193: A format string argument for string.Formatter.format()
|
- Issue #29193: A format string argument for string.Formatter.format()
|
||||||
is now positional-only.
|
is now positional-only.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue