summaryrefslogtreecommitdiffstats
path: root/Lib/formatter.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-06-03 15:58:32 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-06-03 15:58:32 (GMT)
commit65230a2de758fbde57b3893c402436ae0202ada3 (patch)
tree4b0b8431990125dd567b23c4ad3325959dc91a2e /Lib/formatter.py
parenta401ae4010eeb385a0775c505637bbc332bc184c (diff)
downloadcpython-65230a2de758fbde57b3893c402436ae0202ada3.zip
cpython-65230a2de758fbde57b3893c402436ae0202ada3.tar.gz
cpython-65230a2de758fbde57b3893c402436ae0202ada3.tar.bz2
Remove uses of the string and types modules:
x in string.whitespace => x.isspace() type(x) in types.StringTypes => isinstance(x, basestring) isinstance(x, types.StringTypes) => isinstance(x, basestring) type(x) is types.StringType => isinstance(x, str) type(x) == types.StringType => isinstance(x, str) string.split(x, ...) => x.split(...) string.join(x, y) => y.join(x) string.zfill(x, ...) => x.zfill(...) string.count(x, ...) => x.count(...) hasattr(types, "UnicodeType") => try: unicode except NameError: type(x) != types.TupleTuple => not isinstance(x, tuple) isinstance(x, types.TupleType) => isinstance(x, tuple) type(x) is types.IntType => isinstance(x, int) Do not mention the string module in the rlcompleter docstring. This partially applies SF patch http://www.python.org/sf/562373 (with basestring instead of string). (It excludes the changes to unittest.py and does not change the os.stat stuff.)
Diffstat (limited to 'Lib/formatter.py')
-rw-r--r--Lib/formatter.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/Lib/formatter.py b/Lib/formatter.py
index ccbbdf1..6ea5d9e 100644
--- a/Lib/formatter.py
+++ b/Lib/formatter.py
@@ -18,9 +18,7 @@ available mechanisms for setting the properties which formatter objects
manage and inserting data into the output.
"""
-import string
import sys
-from types import StringType
AS_IS = None
@@ -119,7 +117,7 @@ class AbstractFormatter:
self.writer.send_line_break()
if not self.para_end:
self.writer.send_paragraph((blankline and 1) or 0)
- if type(format) is StringType:
+ if isinstance(format, str):
self.writer.send_label_data(self.format_counter(format, counter))
else:
self.writer.send_label_data(format)
@@ -176,16 +174,13 @@ class AbstractFormatter:
return label.upper()
return label
- def add_flowing_data(self, data,
- # These are only here to load them into locals:
- whitespace = string.whitespace,
- join = string.join, split = string.split):
+ def add_flowing_data(self, data):
if not data: return
# The following looks a bit convoluted but is a great improvement over
# data = regsub.gsub('[' + string.whitespace + ']+', ' ', data)
- prespace = data[:1] in whitespace
- postspace = data[-1:] in whitespace
- data = join(split(data))
+ prespace = data[:1].isspace()
+ postspace = data[-1:].isspace()
+ data = " ".join(data.split())
if self.nospace and not data:
return
elif prespace or self.softspace:
@@ -411,7 +406,7 @@ class DumbWriter(NullWriter):
def send_flowing_data(self, data):
if not data: return
- atbreak = self.atbreak or data[0] in string.whitespace
+ atbreak = self.atbreak or data[0].isspace()
col = self.col
maxcol = self.maxcol
write = self.file.write
@@ -427,7 +422,7 @@ class DumbWriter(NullWriter):
col = col + len(word)
atbreak = 1
self.col = col
- self.atbreak = data[-1] in string.whitespace
+ self.atbreak = data[-1].isspace()
def test(file = None):