[Python-checkins] python/dist/src/Lib pprint.py,1.22,1.23

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Mon, 08 Jul 2002 05:28:08 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv843/Lib

Modified Files:
	pprint.py 
Log Message:
Change the "__ private" names to "_ protected"; this has been a pain for
subclassing so many times it should simply be changed.


Index: pprint.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pprint.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** pprint.py	1 Jun 2002 16:07:16 -0000	1.22
--- pprint.py	8 Jul 2002 12:28:06 -0000	1.23
***************
*** 99,116 ****
          assert depth is None or depth > 0, "depth must be > 0"
          assert width
!         self.__depth = depth
!         self.__indent_per_level = indent
!         self.__width = width
          if stream is not None:
!             self.__stream = stream
          else:
!             self.__stream = sys.stdout
  
      def pprint(self, object):
!         self.__stream.write(self.pformat(object) + "\n")
  
      def pformat(self, object):
          sio = StringIO()
!         self.__format(object, sio, 0, 0, {}, 0)
          return sio.getvalue()
  
--- 99,116 ----
          assert depth is None or depth > 0, "depth must be > 0"
          assert width
!         self._depth = depth
!         self._indent_per_level = indent
!         self._width = width
          if stream is not None:
!             self._stream = stream
          else:
!             self._stream = sys.stdout
  
      def pprint(self, object):
!         self._stream.write(self.pformat(object) + "\n")
  
      def pformat(self, object):
          sio = StringIO()
!         self._format(object, sio, 0, 0, {}, 0)
          return sio.getvalue()
  
***************
*** 122,136 ****
          return readable and not recursive
  
!     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
              return
!         rep = self.__repr(object, context, level - 1)
          typ = _type(object)
!         sepLines = _len(rep) > (self.__width - 1 - indent - allowance)
          write = stream.write
  
--- 122,136 ----
          return readable and not recursive
  
!     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
              return
!         rep = self._repr(object, context, level - 1)
          typ = _type(object)
!         sepLines = _len(rep) > (self._width - 1 - indent - allowance)
          write = stream.write
  
***************
*** 138,162 ****
              if typ is DictType:
                  write('{')
!                 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
                      items  = object.items()
                      items.sort()
                      key, ent = items[0]
!                     rep = self.__repr(key, context, level)
                      write(rep)
                      write(': ')
!                     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)
                              write(',\n%s%s: ' % (' '*indent, rep))
!                             self.__format(ent, stream, indent + _len(rep) + 2,
                                            allowance + 1, context, level)
!                     indent = indent - self.__indent_per_level
                      del context[objid]
                  write('}')
--- 138,162 ----
              if typ is DictType:
                  write('{')
!                 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
                      items  = object.items()
                      items.sort()
                      key, ent = items[0]
!                     rep = self._repr(key, context, level)
                      write(rep)
                      write(': ')
!                     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)
                              write(',\n%s%s: ' % (' '*indent, rep))
!                             self._format(ent, stream, indent + _len(rep) + 2,
                                            allowance + 1, context, level)
!                     indent = indent - self._indent_per_level
                      del context[objid]
                  write('}')
***************
*** 170,187 ****
                      write('(')
                      endchar = ')'
!                 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)
                      if length > 1:
                          for ent in object[1:]:
                              write(',\n' + ' '*indent)
!                             self.__format(ent, stream, indent,
                                            allowance + 1, context, level)
!                     indent = indent - self.__indent_per_level
                      del context[objid]
                  if typ is TupleType and length == 1:
--- 170,187 ----
                      write('(')
                      endchar = ')'
!                 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)
                      if length > 1:
                          for ent in object[1:]:
                              write(',\n' + ' '*indent)
!                             self._format(ent, stream, indent,
                                            allowance + 1, context, level)
!                     indent = indent - self._indent_per_level
                      del context[objid]
                  if typ is TupleType and length == 1:
***************
*** 192,202 ****
          write(rep)
  
!     def __repr(self, object, context, level):
          repr, readable, recursive = self.format(object, context.copy(),
!                                                 self.__depth, level)
          if not readable:
!             self.__readable = False
          if recursive:
!             self.__recursive = True
          return repr
  
--- 192,202 ----
          write(rep)
  
!     def _repr(self, object, context, level):
          repr, readable, recursive = self.format(object, context.copy(),
!                                                 self._depth, level)
          if not readable:
!             self._readable = False
          if recursive:
!             self._recursive = True
          return repr