summaryrefslogtreecommitdiffstats
path: root/Lib/pprint.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-07-08 12:28:06 (GMT)
committerFred Drake <fdrake@acm.org>2002-07-08 12:28:06 (GMT)
commite6691efa0fdd5a0a6d770ff7fc17aa9e6bb0735e (patch)
tree3c045d09b7790bbd3d8cb167d39625434b0c86d5 /Lib/pprint.py
parent1695bcb8488a1da3af0e699b03f59421c271c313 (diff)
downloadcpython-e6691efa0fdd5a0a6d770ff7fc17aa9e6bb0735e.zip
cpython-e6691efa0fdd5a0a6d770ff7fc17aa9e6bb0735e.tar.gz
cpython-e6691efa0fdd5a0a6d770ff7fc17aa9e6bb0735e.tar.bz2
Change the "__ private" names to "_ protected"; this has been a pain for
subclassing so many times it should simply be changed.
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r--Lib/pprint.py62
1 files changed, 31 insertions, 31 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py
index 523572b..d7d0405 100644
--- a/Lib/pprint.py
+++ b/Lib/pprint.py
@@ -98,20 +98,20 @@ class PrettyPrinter:
assert indent >= 0
assert depth is None or depth > 0, "depth must be > 0"
assert width
- self.__depth = depth
- self.__indent_per_level = indent
- self.__width = width
+ self._depth = depth
+ self._indent_per_level = indent
+ self._width = width
if stream is not None:
- self.__stream = stream
+ self._stream = stream
else:
- self.__stream = sys.stdout
+ self._stream = sys.stdout
def pprint(self, object):
- self.__stream.write(self.pformat(object) + "\n")
+ self._stream.write(self.pformat(object) + "\n")
def pformat(self, object):
sio = StringIO()
- self.__format(object, sio, 0, 0, {}, 0)
+ self._format(object, sio, 0, 0, {}, 0)
return sio.getvalue()
def isrecursive(self, object):
@@ -121,43 +121,43 @@ class PrettyPrinter:
s, readable, recursive = self.format(object, {}, 0)
return readable and not recursive
- def __format(self, object, stream, indent, allowance, context, level):
+ def _format(self, object, stream, indent, allowance, context, level):
level = level + 1
objid = _id(object)
if objid in context:
stream.write(_recursion(object))
- self.__recursive = True
- self.__readable = False
+ self._recursive = True
+ self._readable = False
return
- rep = self.__repr(object, context, level - 1)
+ rep = self._repr(object, context, level - 1)
typ = _type(object)
- sepLines = _len(rep) > (self.__width - 1 - indent - allowance)
+ sepLines = _len(rep) > (self._width - 1 - indent - allowance)
write = stream.write
if sepLines:
if typ is DictType:
write('{')
- if self.__indent_per_level > 1:
- write((self.__indent_per_level - 1) * ' ')
+ if self._indent_per_level > 1:
+ write((self._indent_per_level - 1) * ' ')
length = _len(object)
if length:
context[objid] = 1
- indent = indent + self.__indent_per_level
+ indent = indent + self._indent_per_level
items = object.items()
items.sort()
key, ent = items[0]
- rep = self.__repr(key, context, level)
+ rep = self._repr(key, context, level)
write(rep)
write(': ')
- self.__format(ent, stream, indent + _len(rep) + 2,
+ self._format(ent, stream, indent + _len(rep) + 2,
allowance + 1, context, level)
if length > 1:
for key, ent in items[1:]:
- rep = self.__repr(key, context, level)
+ rep = self._repr(key, context, level)
write(',\n%s%s: ' % (' '*indent, rep))
- self.__format(ent, stream, indent + _len(rep) + 2,
+ self._format(ent, stream, indent + _len(rep) + 2,
allowance + 1, context, level)
- indent = indent - self.__indent_per_level
+ indent = indent - self._indent_per_level
del context[objid]
write('}')
return
@@ -169,20 +169,20 @@ class PrettyPrinter:
else:
write('(')
endchar = ')'
- if self.__indent_per_level > 1:
- write((self.__indent_per_level - 1) * ' ')
+ if self._indent_per_level > 1:
+ write((self._indent_per_level - 1) * ' ')
length = _len(object)
if length:
context[objid] = 1
- indent = indent + self.__indent_per_level
- self.__format(object[0], stream, indent, allowance + 1,
- context, level)
+ indent = indent + self._indent_per_level
+ self._format(object[0], stream, indent, allowance + 1,
+ context, level)
if length > 1:
for ent in object[1:]:
write(',\n' + ' '*indent)
- self.__format(ent, stream, indent,
+ self._format(ent, stream, indent,
allowance + 1, context, level)
- indent = indent - self.__indent_per_level
+ indent = indent - self._indent_per_level
del context[objid]
if typ is TupleType and length == 1:
write(',')
@@ -191,13 +191,13 @@ class PrettyPrinter:
write(rep)
- def __repr(self, object, context, level):
+ def _repr(self, object, context, level):
repr, readable, recursive = self.format(object, context.copy(),
- self.__depth, level)
+ self._depth, level)
if not readable:
- self.__readable = False
+ self._readable = False
if recursive:
- self.__recursive = True
+ self._recursive = True
return repr
def format(self, object, context, maxlevels, level):