Clean up uses of some deprecated features.

Reported by Neal Norwitz on python-dev.
This commit is contained in:
Fred Drake 2002-04-26 02:29:55 +00:00
parent 89e3ee0ccf
commit d451ec1cdb
3 changed files with 20 additions and 17 deletions

View file

@ -301,10 +301,10 @@ class ConfigParser:
return conv(self.get(section, option)) return conv(self.get(section, option))
def getint(self, section, option): def getint(self, section, option):
return self.__get(section, string.atoi, option) return self.__get(section, int, option)
def getfloat(self, section, option): def getfloat(self, section, option):
return self.__get(section, string.atof, option) return self.__get(section, float, option)
def getboolean(self, section, option): def getboolean(self, section, option):
states = {'1': 1, 'yes': 1, 'true': 1, 'on': 1, states = {'1': 1, 'yes': 1, 'true': 1, 'on': 1,

View file

@ -231,6 +231,9 @@ except ImportError:
__all__ = ["CookieError","BaseCookie","SimpleCookie","SerialCookie", __all__ = ["CookieError","BaseCookie","SimpleCookie","SerialCookie",
"SmartCookie","Cookie"] "SmartCookie","Cookie"]
_nulljoin = ''.join
_spacejoin = ' '.join
# #
# Define an exception visible to External modules # Define an exception visible to External modules
# #
@ -311,7 +314,7 @@ _Translator = {
} }
def _quote(str, LegalChars=_LegalChars, def _quote(str, LegalChars=_LegalChars,
join=string.join, idmap=string._idmap, translate=string.translate): idmap=string._idmap, translate=string.translate):
# #
# If the string does not need to be double-quoted, # If the string does not need to be double-quoted,
# then just return the string. Otherwise, surround # then just return the string. Otherwise, surround
@ -321,14 +324,14 @@ def _quote(str, LegalChars=_LegalChars,
if "" == translate(str, idmap, LegalChars): if "" == translate(str, idmap, LegalChars):
return str return str
else: else:
return '"' + join( map(_Translator.get, str, str), "" ) + '"' return '"' + _nulljoin( map(_Translator.get, str, str) ) + '"'
# end _quote # end _quote
_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]") _OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
_QuotePatt = re.compile(r"[\\].") _QuotePatt = re.compile(r"[\\].")
def _unquote(str, join=string.join, atoi=string.atoi): def _unquote(str):
# If there aren't any doublequotes, # If there aren't any doublequotes,
# then there can't be any special characters. See RFC 2109. # then there can't be any special characters. See RFC 2109.
if len(str) < 2: if len(str) < 2:
@ -365,9 +368,9 @@ def _unquote(str, join=string.join, atoi=string.atoi):
i = k+2 i = k+2
else: # OctalPatt matched else: # OctalPatt matched
res.append(str[i:j]) res.append(str[i:j])
res.append( chr( atoi(str[j+1:j+4], 8) ) ) res.append( chr( int(str[j+1:j+4], 8) ) )
i = j+4 i = j+4
return join(res, "") return _nulljoin(res)
# end _unquote # end _unquote
# The _getdate() routine is used to set the expiration time in # The _getdate() routine is used to set the expiration time in
@ -435,14 +438,14 @@ class Morsel(UserDict):
# end __init__ # end __init__
def __setitem__(self, K, V): def __setitem__(self, K, V):
K = string.lower(K) K = K.lower()
if not K in self._reserved_keys: if not K in self._reserved_keys:
raise CookieError("Invalid Attribute %s" % K) raise CookieError("Invalid Attribute %s" % K)
UserDict.__setitem__(self, K, V) UserDict.__setitem__(self, K, V)
# end __setitem__ # end __setitem__
def isReservedKey(self, K): def isReservedKey(self, K):
return string.lower(K) in self._reserved_keys return K.lower() in self._reserved_keys
# end isReservedKey # end isReservedKey
def set(self, key, val, coded_val, def set(self, key, val, coded_val,
@ -450,7 +453,7 @@ class Morsel(UserDict):
idmap=string._idmap, translate=string.translate ): idmap=string._idmap, translate=string.translate ):
# First we verify that the key isn't a reserved word # First we verify that the key isn't a reserved word
# Second we make sure it only contains legal characters # Second we make sure it only contains legal characters
if string.lower(key) in self._reserved_keys: if key.lower() in self._reserved_keys:
raise CookieError("Attempt to set a reserved key: %s" % key) raise CookieError("Attempt to set a reserved key: %s" % key)
if "" != translate(key, idmap, LegalChars): if "" != translate(key, idmap, LegalChars):
raise CookieError("Illegal key value: %s" % key) raise CookieError("Illegal key value: %s" % key)
@ -508,7 +511,7 @@ class Morsel(UserDict):
RA("%s=%s;" % (self._reserved[K], V)) RA("%s=%s;" % (self._reserved[K], V))
# Return the result # Return the result
return string.join(result, " ") return _spacejoin(result)
# end OutputString # end OutputString
# end Morsel class # end Morsel class
@ -592,7 +595,7 @@ class BaseCookie(UserDict):
items.sort() items.sort()
for K,V in items: for K,V in items:
result.append( V.output(attrs, header) ) result.append( V.output(attrs, header) )
return string.join(result, sep) return sep.join(result)
# end output # end output
__str__ = output __str__ = output
@ -603,7 +606,7 @@ class BaseCookie(UserDict):
items.sort() items.sort()
for K,V in items: for K,V in items:
L.append( '%s=%s' % (K,repr(V.value) ) ) L.append( '%s=%s' % (K,repr(V.value) ) )
return '<%s: %s>' % (self.__class__.__name__, string.join(L)) return '<%s: %s>' % (self.__class__.__name__, _spacejoin(L))
def js_output(self, attrs=None): def js_output(self, attrs=None):
"""Return a string suitable for JavaScript.""" """Return a string suitable for JavaScript."""
@ -612,7 +615,7 @@ class BaseCookie(UserDict):
items.sort() items.sort()
for K,V in items: for K,V in items:
result.append( V.js_output(attrs) ) result.append( V.js_output(attrs) )
return string.join(result, "") return _nulljoin(result)
# end js_output # end js_output
def load(self, rawdata): def load(self, rawdata):
@ -648,7 +651,7 @@ class BaseCookie(UserDict):
# (Does anyone care?) # (Does anyone care?)
if M: if M:
M[ K[1:] ] = V M[ K[1:] ] = V
elif string.lower(K) in Morsel._reserved_keys: elif K.lower() in Morsel._reserved_keys:
if M: if M:
M[ K ] = _unquote(V) M[ K ] = _unquote(V)
else: else:

View file

@ -769,7 +769,7 @@ def currentframe():
try: try:
1/0 1/0
except ZeroDivisionError: except ZeroDivisionError:
return sys.exc_traceback.tb_frame.f_back return sys.exc_info()[2].tb_frame.f_back
if hasattr(sys, '_getframe'): currentframe = sys._getframe if hasattr(sys, '_getframe'): currentframe = sys._getframe
@ -779,4 +779,4 @@ def stack(context=1):
def trace(context=1): def trace(context=1):
"""Return a list of records for the stack below the current exception.""" """Return a list of records for the stack below the current exception."""
return getinnerframes(sys.exc_traceback, context) return getinnerframes(sys.exc_info()[2], context)