Simplify various spots where: str() is called on something

that already is a string or the existence of the str class
is checked or a check is done for str twice. These all stem
from the initial unicode->str replacement.
This commit is contained in:
Walter Dörwald 2007-06-11 21:38:39 +00:00
parent 80bfb725af
commit 5de48bdd19
9 changed files with 48 additions and 89 deletions

View file

@ -104,33 +104,28 @@ for ch in "\"'\\\n#":
_tran = ''.join(_tran)
del ch
try:
UnicodeType = type(str(""))
except NameError:
UnicodeType = None
class Parser:
def __init__(self, indentwidth, tabwidth):
self.indentwidth = indentwidth
self.tabwidth = tabwidth
def set_str(self, str):
assert len(str) == 0 or str[-1] == '\n'
if type(str) is UnicodeType:
def set_str(self, s):
assert len(s) == 0 or s[-1] == '\n'
if isinstance(s, str):
# The parse functions have no idea what to do with Unicode, so
# replace all Unicode characters with "x". This is "safe"
# so long as the only characters germane to parsing the structure
# of Python are 7-bit ASCII. It's *necessary* because Unicode
# strings don't have a .translate() method that supports
# deletechars.
uniphooey = str
uniphooey = s
str = []
push = str.append
push = s.append
for raw in map(ord, uniphooey):
push(raw < 127 and chr(raw) or "x")
str = "".join(str)
self.str = str
s = "".join(s)
self.str = s
self.study_level = 0
# Return index of a good place to begin parsing, as close to the