Package SimPy :: Module Lister |
[hide private]
[frames] | no frames]

# Source Code for Module SimPy.Lister

     1  #!/usr / bin / env python
     2  # coding=utf-8
     3  # $Revision: 503 $ $Date: 2010-05-11 08:27:54 +0200 (Tue, 11 May 2010) $ kgm
     4  """Lister 2.1
     5  Pretty-printer for SimPy class objects
     6  """
     7  __version__ = '2.1.0 $Revision: 503 $ $Date: 2010-05-11 08:27:54 +0200 (Tue, 11 May 2010) $'
     8
     9 -class Lister(object):
    10
    11     indent = 0
    12
    13 -   def __str__(self):
    14         Lister.indent += 1
    15         if Lister.indent > 3:
    16             # In case of recursion, avoid infinite loop
    17             result = ' ... '
    18         else:
    19             result = '< Instance of %s, id %s:\n%s%s>' % (
    20                 self.__class__.__name__,
    21                 id(self),
    22                 self.attrnames(),
    23                 '\t' * (Lister.indent - 1),
    24             )
    25         Lister.indent -= 1
    26         return result
    27
    28 -   def attrnames(self):
    29         result = ''
    30         for attr in self.__dict__.keys():
    31             # Ignore built-in and private attributes
    32             if not (attr[:2] == '__' or attr[0] == '_'):
    33                 result += '\t' * Lister.indent + '.%s=%s\n' % (attr,
    34                         self.__dict__[attr])
    35         return result
    36
    37 -   def __repr__(self):
    38         return self.__str__()
    39