231231__all__ = ["CookieError" ,"BaseCookie" ,"SimpleCookie" ,"SerialCookie" ,
232232 "SmartCookie" ,"Cookie" ]
233233
234+ _nulljoin = '' .join
235+ _spacejoin = ' ' .join
236+
234237#
235238# Define an exception visible to External modules
236239#
@@ -311,7 +314,7 @@ class CookieError(Exception):
311314 }
312315
313316def _quote (str , LegalChars = _LegalChars ,
314- join = string . join , idmap = string ._idmap , translate = string .translate ):
317+ idmap = string ._idmap , translate = string .translate ):
315318 #
316319 # If the string does not need to be double-quoted,
317320 # then just return the string. Otherwise, surround
@@ -321,14 +324,14 @@ def _quote(str, LegalChars=_LegalChars,
321324 if "" == translate (str , idmap , LegalChars ):
322325 return str
323326 else :
324- return '"' + join ( map (_Translator .get , str , str ), "" ) + '"'
327+ return '"' + _nulljoin ( map (_Translator .get , str , str ) ) + '"'
325328# end _quote
326329
327330
328331_OctalPatt = re .compile (r"\\[0-3][0-7][0-7]" )
329332_QuotePatt = re .compile (r"[\\]." )
330333
331- def _unquote (str , join = string . join , atoi = string . atoi ):
334+ def _unquote (str ):
332335 # If there aren't any doublequotes,
333336 # then there can't be any special characters. See RFC 2109.
334337 if len (str ) < 2 :
@@ -365,9 +368,9 @@ def _unquote(str, join=string.join, atoi=string.atoi):
365368 i = k + 2
366369 else : # OctalPatt matched
367370 res .append (str [i :j ])
368- res .append ( chr ( atoi (str [j + 1 :j + 4 ], 8 ) ) )
371+ res .append ( chr ( int (str [j + 1 :j + 4 ], 8 ) ) )
369372 i = j + 4
370- return join (res , "" )
373+ return _nulljoin (res )
371374# end _unquote
372375
373376# The _getdate() routine is used to set the expiration time in
@@ -435,22 +438,22 @@ def __init__(self):
435438 # end __init__
436439
437440 def __setitem__ (self , K , V ):
438- K = string .lower (K )
441+ K = K .lower ()
439442 if not K in self ._reserved_keys :
440443 raise CookieError ("Invalid Attribute %s" % K )
441444 UserDict .__setitem__ (self , K , V )
442445 # end __setitem__
443446
444447 def isReservedKey (self , K ):
445- return string .lower (K ) in self ._reserved_keys
448+ return K .lower () in self ._reserved_keys
446449 # end isReservedKey
447450
448451 def set (self , key , val , coded_val ,
449452 LegalChars = _LegalChars ,
450453 idmap = string ._idmap , translate = string .translate ):
451454 # First we verify that the key isn't a reserved word
452455 # Second we make sure it only contains legal characters
453- if string .lower (key ) in self ._reserved_keys :
456+ if key .lower () in self ._reserved_keys :
454457 raise CookieError ("Attempt to set a reserved key: %s" % key )
455458 if "" != translate (key , idmap , LegalChars ):
456459 raise CookieError ("Illegal key value: %s" % key )
@@ -508,7 +511,7 @@ def OutputString(self, attrs=None):
508511 RA ("%s=%s;" % (self ._reserved [K ], V ))
509512
510513 # Return the result
511- return string . join (result , " " )
514+ return _spacejoin (result )
512515 # end OutputString
513516# end Morsel class
514517
@@ -592,7 +595,7 @@ def output(self, attrs=None, header="Set-Cookie:", sep="\n"):
592595 items .sort ()
593596 for K ,V in items :
594597 result .append ( V .output (attrs , header ) )
595- return string .join (result , sep )
598+ return sep .join (result )
596599 # end output
597600
598601 __str__ = output
@@ -603,7 +606,7 @@ def __repr__(self):
603606 items .sort ()
604607 for K ,V in items :
605608 L .append ( '%s=%s' % (K ,repr (V .value ) ) )
606- return '<%s: %s>' % (self .__class__ .__name__ , string . join (L ))
609+ return '<%s: %s>' % (self .__class__ .__name__ , _spacejoin (L ))
607610
608611 def js_output (self , attrs = None ):
609612 """Return a string suitable for JavaScript."""
@@ -612,7 +615,7 @@ def js_output(self, attrs=None):
612615 items .sort ()
613616 for K ,V in items :
614617 result .append ( V .js_output (attrs ) )
615- return string . join (result , "" )
618+ return _nulljoin (result )
616619 # end js_output
617620
618621 def load (self , rawdata ):
@@ -648,7 +651,7 @@ def __ParseString(self, str, patt=_CookiePattern):
648651 # (Does anyone care?)
649652 if M :
650653 M [ K [1 :] ] = V
651- elif string .lower (K ) in Morsel ._reserved_keys :
654+ elif K .lower () in Morsel ._reserved_keys :
652655 if M :
653656 M [ K ] = _unquote (V )
654657 else :
0 commit comments