Commit 70ba6050 authored by Georg Brandl's avatar Georg Brandl

string.maketrans() now produces translation tables for bytes.translate() -- wrong module?

Fix all remaining instances that did bad things with the new str.translate().
parent b7375849
...@@ -348,11 +348,10 @@ class install (Command): ...@@ -348,11 +348,10 @@ class install (Command):
if opt_name[-1] == "=": if opt_name[-1] == "=":
opt_name = opt_name[0:-1] opt_name = opt_name[0:-1]
if self.negative_opt.has_key(opt_name): if self.negative_opt.has_key(opt_name):
opt_name = self.negative_opt[opt_name].translate( opt_name = longopt_xlate(self.negative_opt[opt_name])
longopt_xlate)
val = not getattr(self, opt_name) val = not getattr(self, opt_name)
else: else:
opt_name = opt_name.translate(longopt_xlate) opt_name = longopt_xlate(opt_name)
val = getattr(self, opt_name) val = getattr(self, opt_name)
print(" %s: %s" % (opt_name, val)) print(" %s: %s" % (opt_name, val))
......
...@@ -26,7 +26,7 @@ neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat)) ...@@ -26,7 +26,7 @@ neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
# This is used to translate long options to legitimate Python identifiers # This is used to translate long options to legitimate Python identifiers
# (for use as attributes of some object). # (for use as attributes of some object).
longopt_xlate = string.maketrans('-', '_') longopt_xlate = lambda s: s.replace('-', '_')
class FancyGetopt: class FancyGetopt:
"""Wrapper around the standard 'getopt()' module that provides some """Wrapper around the standard 'getopt()' module that provides some
...@@ -107,7 +107,7 @@ class FancyGetopt: ...@@ -107,7 +107,7 @@ class FancyGetopt:
"""Translate long option name 'long_option' to the form it """Translate long option name 'long_option' to the form it
has as an attribute of some object: ie., translate hyphens has as an attribute of some object: ie., translate hyphens
to underscores.""" to underscores."""
return long_option.translate(longopt_xlate) return longopt_xlate(long_option)
def _check_alias_dict(self, aliases, what): def _check_alias_dict(self, aliases, what):
assert isinstance(aliases, dict) assert isinstance(aliases, dict)
...@@ -372,7 +372,7 @@ def fancy_getopt(options, negative_opt, object, args): ...@@ -372,7 +372,7 @@ def fancy_getopt(options, negative_opt, object, args):
return parser.getopt(args, object) return parser.getopt(args, object)
WS_TRANS = string.maketrans(string.whitespace, ' ' * len(string.whitespace)) WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}
def wrap_text(text, width): def wrap_text(text, width):
"""wrap_text(text : string, width : int) -> [string] """wrap_text(text : string, width : int) -> [string]
...@@ -432,7 +432,7 @@ def translate_longopt(opt): ...@@ -432,7 +432,7 @@ def translate_longopt(opt):
"""Convert a long option name to a valid Python identifier by """Convert a long option name to a valid Python identifier by
changing "-" to "_". changing "-" to "_".
""" """
return opt.translate(longopt_xlate) return longopt_xlate(opt)
class OptionDummy: class OptionDummy:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment