Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
reprlib.Repr Class Reference
Inheritance diagram for reprlib.Repr:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def repr
def repr1
def repr_tuple
def repr_list
def repr_array
def repr_set
def repr_frozenset
def repr_deque
def repr_dict
def repr_str
def repr_int
def repr_instance

Public Attributes

 maxlevel
 maxtuple
 maxlist
 maxarray
 maxdict
 maxset
 maxfrozenset
 maxdeque
 maxstring
 maxlong
 maxother

Private Member Functions

def _repr_iterable

Detailed Description

Definition at line 38 of file reprlib.py.


Constructor & Destructor Documentation

def reprlib.Repr.__init__ (   self)

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 40 of file reprlib.py.

00040 
00041     def __init__(self):
00042         self.maxlevel = 6
00043         self.maxtuple = 6
00044         self.maxlist = 6
00045         self.maxarray = 5
00046         self.maxdict = 4
00047         self.maxset = 6
00048         self.maxfrozenset = 6
00049         self.maxdeque = 6
00050         self.maxstring = 30
00051         self.maxlong = 40
00052         self.maxother = 30

Here is the caller graph for this function:


Member Function Documentation

def reprlib.Repr._repr_iterable (   self,
  x,
  level,
  left,
  right,
  maxiter,
  trail = '' 
) [private]

Definition at line 66 of file reprlib.py.

00066 
00067     def _repr_iterable(self, x, level, left, right, maxiter, trail=''):
00068         n = len(x)
00069         if level <= 0 and n:
00070             s = '...'
00071         else:
00072             newlevel = level - 1
00073             repr1 = self.repr1
00074             pieces = [repr1(elem, newlevel) for elem in islice(x, maxiter)]
00075             if n > maxiter:  pieces.append('...')
00076             s = ', '.join(pieces)
00077             if n == 1 and trail:  right = trail + right
00078         return '%s%s%s' % (left, s, right)

Here is the call graph for this function:

Here is the caller graph for this function:

def reprlib.Repr.repr (   self,
  x 
)

Reimplemented in pydoc.HTMLRepr.

Definition at line 53 of file reprlib.py.

00053 
00054     def repr(self, x):
00055         return self.repr1(x, self.maxlevel)

Here is the call graph for this function:

Here is the caller graph for this function:

def reprlib.Repr.repr1 (   self,
  x,
  level 
)

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 56 of file reprlib.py.

00056 
00057     def repr1(self, x, level):
00058         typename = type(x).__name__
00059         if ' ' in typename:
00060             parts = typename.split()
00061             typename = '_'.join(parts)
00062         if hasattr(self, 'repr_' + typename):
00063             return getattr(self, 'repr_' + typename)(x, level)
00064         else:
00065             return self.repr_instance(x, level)

Here is the call graph for this function:

Here is the caller graph for this function:

def reprlib.Repr.repr_array (   self,
  x,
  level 
)

Definition at line 85 of file reprlib.py.

00085 
00086     def repr_array(self, x, level):
00087         header = "array('%s', [" % x.typecode
00088         return self._repr_iterable(x, level, header, '])', self.maxarray)

Here is the call graph for this function:

def reprlib.Repr.repr_deque (   self,
  x,
  level 
)

Definition at line 98 of file reprlib.py.

00098 
00099     def repr_deque(self, x, level):
00100         return self._repr_iterable(x, level, 'deque([', '])', self.maxdeque)

Here is the call graph for this function:

def reprlib.Repr.repr_dict (   self,
  x,
  level 
)

Definition at line 101 of file reprlib.py.

00101 
00102     def repr_dict(self, x, level):
00103         n = len(x)
00104         if n == 0: return '{}'
00105         if level <= 0: return '{...}'
00106         newlevel = level - 1
00107         repr1 = self.repr1
00108         pieces = []
00109         for key in islice(_possibly_sorted(x), self.maxdict):
00110             keyrepr = repr1(key, newlevel)
00111             valrepr = repr1(x[key], newlevel)
00112             pieces.append('%s: %s' % (keyrepr, valrepr))
00113         if n > self.maxdict: pieces.append('...')
00114         s = ', '.join(pieces)
00115         return '{%s}' % (s,)

Here is the call graph for this function:

def reprlib.Repr.repr_frozenset (   self,
  x,
  level 
)

Definition at line 93 of file reprlib.py.

00093 
00094     def repr_frozenset(self, x, level):
00095         x = _possibly_sorted(x)
00096         return self._repr_iterable(x, level, 'frozenset([', '])',
00097                                    self.maxfrozenset)

Here is the call graph for this function:

def reprlib.Repr.repr_instance (   self,
  x,
  level 
)

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 133 of file reprlib.py.

00133 
00134     def repr_instance(self, x, level):
00135         try:
00136             s = builtins.repr(x)
00137             # Bugs in x.__repr__() can cause arbitrary
00138             # exceptions -- then make up something
00139         except Exception:
00140             return '<%s instance at %x>' % (x.__class__.__name__, id(x))
00141         if len(s) > self.maxother:
00142             i = max(0, (self.maxother-3)//2)
00143             j = max(0, self.maxother-3-i)
00144             s = s[:i] + '...' + s[len(s)-j:]
00145         return s
00146 

Here is the caller graph for this function:

def reprlib.Repr.repr_int (   self,
  x,
  level 
)

Definition at line 125 of file reprlib.py.

00125 
00126     def repr_int(self, x, level):
00127         s = builtins.repr(x) # XXX Hope this isn't too slow...
00128         if len(s) > self.maxlong:
00129             i = max(0, (self.maxlong-3)//2)
00130             j = max(0, self.maxlong-3-i)
00131             s = s[:i] + '...' + s[len(s)-j:]
00132         return s

def reprlib.Repr.repr_list (   self,
  x,
  level 
)

Definition at line 82 of file reprlib.py.

00082 
00083     def repr_list(self, x, level):
00084         return self._repr_iterable(x, level, '[', ']', self.maxlist)

Here is the call graph for this function:

def reprlib.Repr.repr_set (   self,
  x,
  level 
)

Definition at line 89 of file reprlib.py.

00089 
00090     def repr_set(self, x, level):
00091         x = _possibly_sorted(x)
00092         return self._repr_iterable(x, level, 'set([', '])', self.maxset)

Here is the call graph for this function:

def reprlib.Repr.repr_str (   self,
  x,
  level 
)

Definition at line 116 of file reprlib.py.

00116 
00117     def repr_str(self, x, level):
00118         s = builtins.repr(x[:self.maxstring])
00119         if len(s) > self.maxstring:
00120             i = max(0, (self.maxstring-3)//2)
00121             j = max(0, self.maxstring-3-i)
00122             s = builtins.repr(x[:i] + x[len(x)-j:])
00123             s = s[:i] + '...' + s[len(s)-j:]
00124         return s

def reprlib.Repr.repr_tuple (   self,
  x,
  level 
)

Definition at line 79 of file reprlib.py.

00079 
00080     def repr_tuple(self, x, level):
00081         return self._repr_iterable(x, level, '(', ')', self.maxtuple, ',')

Here is the call graph for this function:


Member Data Documentation

Definition at line 44 of file reprlib.py.

Definition at line 48 of file reprlib.py.

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 45 of file reprlib.py.

Definition at line 47 of file reprlib.py.

Definition at line 41 of file reprlib.py.

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 43 of file reprlib.py.

Definition at line 50 of file reprlib.py.

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 51 of file reprlib.py.

Definition at line 46 of file reprlib.py.

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 49 of file reprlib.py.

Reimplemented in pydoc.TextRepr, and pydoc.HTMLRepr.

Definition at line 42 of file reprlib.py.


The documentation for this class was generated from the following file: