Skip to content

Commit e10df7d

Browse files
committed
chore: PEP8-ization
The only change in the code is using `K not in` instead of `not K in` on the line 310.
1 parent 67ddba9 commit e10df7d

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

Lib/http/cookies.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
_semispacejoin = '; '.join
140140
_spacejoin = ' '.join
141141

142+
142143
#
143144
# Define an exception visible to External modules
144145
#
@@ -195,12 +196,14 @@ def _quote(str):
195196

196197
_unquote_sub = re.compile(r'\\(?:([0-3][0-7][0-7])|(.))').sub
197198

199+
198200
def _unquote_replace(m):
199201
if m[1]:
200202
return chr(int(m[1], 8))
201203
else:
202204
return m[2]
203205

206+
204207
def _unquote(str):
205208
# If there aren't any doublequotes,
206209
# then there can't be any special characters. See RFC 2109.
@@ -221,19 +224,22 @@ def _unquote(str):
221224
#
222225
return _unquote_sub(_unquote_replace, str)
223226

224-
# The _getdate() routine is used to set the expiration time in the cookie's HTTP
225-
# header. By default, _getdate() returns the current time in the appropriate
226-
# "expires" format for a Set-Cookie header. The one optional argument is an
227-
# offset from now, in seconds. For example, an offset of -3600 means "one hour
228-
# ago". The offset may be a floating-point number.
227+
# The _getdate() routine is used to set the expiration time in the
228+
# cookie's HTTP header. By default, _getdate() returns the current time
229+
# in the appropriate "expires" format for a Set-Cookie header. The one
230+
# optional argument is an offset from now, in seconds. For example, an
231+
# offset of -3600 means "one hour ago". The offset may be
232+
# a floating-point number.
229233
#
230234

235+
231236
_weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
232237

233238
_monthname = [None,
234239
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
235240
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
236241

242+
237243
def _getdate(future=0, weekdayname=_weekdayname, monthname=_monthname):
238244
from time import gmtime, time
239245
now = time()
@@ -301,18 +307,20 @@ def coded_value(self):
301307

302308
def __setitem__(self, K, V):
303309
K = K.lower()
304-
if not K in self._reserved:
310+
if K not in self._reserved:
305311
raise CookieError("Invalid attribute %r" % (K,))
306312
if _has_control_character(K, V):
307-
raise CookieError(f"Control characters are not allowed in cookies {K!r} {V!r}")
313+
raise CookieError("Control characters are not allowed in " +
314+
f"cookies {K!r} {V!r}")
308315
dict.__setitem__(self, K, V)
309316

310317
def setdefault(self, key, val=None):
311318
key = key.lower()
312319
if key not in self._reserved:
313320
raise CookieError("Invalid attribute %r" % (key,))
314321
if _has_control_character(key, val):
315-
raise CookieError("Control characters are not allowed in cookies %r %r" % (key, val,))
322+
raise CookieError("Control characters are not allowed in " +
323+
f"cookies {key!r} {val!r}")
316324
return dict.setdefault(self, key, val)
317325

318326
def __eq__(self, morsel):
@@ -350,7 +358,8 @@ def set(self, key, val, coded_val):
350358
raise CookieError('Illegal key %r' % (key,))
351359
if _has_control_character(key, val, coded_val):
352360
raise CookieError(
353-
"Control characters are not allowed in cookies %r %r %r" % (key, val, coded_val,))
361+
"Control characters are not allowed in cookies " +
362+
f"{key!r} {val!r} {coded_val!r}")
354363

355364
# It's a good key, so save it.
356365
self._key = key
@@ -432,7 +441,7 @@ def OutputString(self, attrs=None):
432441
# result, the parsing rules here are less strict.
433442
#
434443

435-
_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
444+
_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
436445
_LegalValueChars = _LegalKeyChars + r'\[\]'
437446
_CookiePattern = re.compile(r"""
438447
\s* # Optional whitespace at start of cookie
@@ -506,18 +515,19 @@ def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
506515
for key, value in items:
507516
value_output = value.output(attrs, header)
508517
if _has_control_character(value_output):
509-
raise CookieError("Control characters are not allowed in cookies")
518+
raise CookieError("Control characters are not allowed " +
519+
"in cookies")
510520
result.append(value_output)
511521
return sep.join(result)
512522

513523
__str__ = output
514524

515525
def __repr__(self):
516-
l = []
526+
t_l = []
517527
items = sorted(self.items())
518528
for key, value in items:
519-
l.append('%s=%s' % (key, repr(value.value)))
520-
return '<%s: %s>' % (self.__class__.__name__, _spacejoin(l))
529+
t_l.append('%s=%s' % (key, repr(value.value)))
530+
return '<%s: %s>' % (self.__class__.__name__, _spacejoin(t_l))
521531

522532
def js_output(self, attrs=None):
523533
"""Return a string suitable for JavaScript."""
@@ -583,7 +593,8 @@ def __parse_string(self, str, patt=_CookiePattern):
583593
else:
584594
parsed_items.append((TYPE_ATTRIBUTE, key, _unquote(value)))
585595
elif value is not None:
586-
parsed_items.append((TYPE_KEYVALUE, key, self.value_decode(value)))
596+
parsed_items.append((TYPE_KEYVALUE, key,
597+
self.value_decode(value)))
587598
morsel_seen = True
588599
else:
589600
# Invalid cookie string
@@ -609,6 +620,7 @@ class SimpleCookie(BaseCookie):
609620
calls the builtin str() to convert the value to a string. Values
610621
received from HTTP are kept as strings.
611622
"""
623+
612624
def value_decode(self, val):
613625
return _unquote(val), val
614626

0 commit comments

Comments
 (0)