ó
è¾bc           @   s  d  Z  d d l Z d d l Z y d d l m Z Wn! e k
 rU d d l m Z n Xd d d d d d	 g Z d
 j	 Z
 e Z e Z e Z d d d d d „ Z d d d d „ Z d „  Z d „  Z d „  Z d „  Z d	 d d „  ƒ  YZ d „  Z d „  Z d d „ Z e d k re ƒ  n  d S(   s/  Support to pretty-print lists, tuples, & dictionaries recursively.

Very simple, but useful, especially in debugging data structures.

Classes
-------

PrettyPrinter()
    Handle pretty-printing operations onto a stream using a configured
    set of formatting parameters.

Functions
---------

pformat()
    Format a Python object into a pretty-printed representation.

pprint()
    Pretty-print a Python object to a stream [default is sys.stdout].

saferepr()
    Generate a 'standard' repr()-like value, but protect against recursive
    data structures.

iÿÿÿÿN(   t   StringIOt   pprintt   pformatt
   isreadablet   isrecursivet   safereprt   PrettyPrinters   , i   iP   c      	   C   s2   t  d | d | d | d | ƒ } | j |  ƒ d S(   sA   Pretty-print a Python object to a stream [default is sys.stdout].t   streamt   indentt   widtht   depthN(   R   R   (   t   objectR   R   R	   R
   t   printer(    (    s   /usr/lib/python2.7/pprint.pyR   7   s    c         C   s"   t  d | d | d | ƒ j |  ƒ S(   s<   Format a Python object into a pretty-printed representation.R   R	   R
   (   R   R   (   R   R   R	   R
   (    (    s   /usr/lib/python2.7/pprint.pyR   =   s    c         C   s   t  |  i  d d ƒ d S(   s=   Version of repr() which can handle recursive data structures.i    N(   t
   _safe_reprt   None(   R   (    (    s   /usr/lib/python2.7/pprint.pyR   A   s    c         C   s   t  |  i  d d ƒ d S(   s4   Determine if saferepr(object) is readable by eval().i    i   N(   R   R   (   R   (    (    s   /usr/lib/python2.7/pprint.pyR   E   s    c         C   s   t  |  i  d d ƒ d S(   s8   Determine if object requires a recursive representation.i    i   N(   R   R   (   R   (    (    s   /usr/lib/python2.7/pprint.pyR   I   s    c         C   s@   t  j ƒ  . t j r, t  j d d t ƒ n  t |  ƒ SWd  QXd  S(   Nt   ignores%   comparing unequal types not supported(   t   warningst   catch_warningst   _syst   py3kwarningt   filterwarningst   DeprecationWarningt   sorted(   t   iterable(    (    s   /usr/lib/python2.7/pprint.pyt   _sortedM   s
    	
c           B   s\   e  Z d  d d
 d
 d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 RS(   i   iP   c         C   s©   t  | ƒ } t  | ƒ } | d k s0 t d ƒ ‚ | d k sT | d k sT t d ƒ ‚ | sf t d ƒ ‚ | |  _ | |  _ | |  _ | d k	 r™ | |  _ n t j |  _ d S(   sò  Handle pretty printing operations onto a stream using a set of
        configured parameters.

        indent
            Number of spaces to indent for each level of nesting.

        width
            Attempted maximum number of columns in the output.

        depth
            The maximum depth to print out nested structures.

        stream
            The desired output stream.  If omitted (or false), the standard
            output stream available at construction will be used.

        i    s   indent must be >= 0s   depth must be > 0s   width must be != 0N(	   t   intt   AssertionErrorR   t   _deptht   _indent_per_levelt   _widtht   _streamR   t   stdout(   t   selfR   R	   R
   R   (    (    s   /usr/lib/python2.7/pprint.pyt   __init__U   s    $			c         C   s3   |  j  | |  j d d i  d ƒ |  j j d ƒ d  S(   Ni    s   
(   t   _formatR   t   write(   R    R   (    (    s   /usr/lib/python2.7/pprint.pyR   t   s    c         C   s/   t  ƒ  } |  j | | d d i  d ƒ | j ƒ  S(   Ni    (   t	   _StringIOR"   t   getvalue(   R    R   t   sio(    (    s   /usr/lib/python2.7/pprint.pyR   x   s    	c         C   s   |  j  | i  d d ƒ d S(   Ni    i   (   t   format(   R    R   (    (    s   /usr/lib/python2.7/pprint.pyR   }   s    c         C   s,   |  j  | i  d d ƒ \ } } } | o+ | S(   Ni    (   R'   (   R    R   t   st   readablet	   recursive(    (    s   /usr/lib/python2.7/pprint.pyR   €   s    !c         C   sÒ  | d } t  | ƒ } | | k rK | j t | ƒ ƒ t |  _ t |  _ d  S|  j | | | d ƒ } t | ƒ }	 t	 | ƒ |  j
 d | | k }
 | j } |  j rÀ | |  j k rÀ | | ƒ d  St |	 d d  ƒ } t |	 t ƒ r„| t j k r„| d ƒ |  j d k r!| |  j d d ƒ n  t	 | ƒ } | rvd | | <| |  j } t | j ƒ  ƒ } | d \ } } |  j | | | ƒ } | | ƒ | d ƒ |  j | | | t	 | ƒ d | d | | ƒ | d k r_x | d D]~ \ } } |  j | | | ƒ } |
 r| d d | | f ƒ n | d	 | ƒ |  j | | | t	 | ƒ d | d | | ƒ qÚWn  | |  j } | | =n  | d
 ƒ d  St |	 t ƒ r¢| t j k süt |	 t ƒ rÀ| t j k süt |	 t ƒ rÞ| t j k süt |	 t ƒ rÄ| t j k rÄt	 | ƒ } t |	 t ƒ r*| d ƒ d } nv t |	 t ƒ rL| d ƒ d } nT | s`| | ƒ d  S| |	 j ƒ | d ƒ d } | t |	 j ƒ d 7} t | ƒ } |  j d k rÍ|
 rÍ| |  j d d ƒ n  | rŽd | | <| |  j } |  j | d | | | d | | ƒ | d k rwxZ | d D]K } |
 rF| d d | ƒ n
 | d ƒ |  j | | | | d | | ƒ q%Wn  | |  j } | | =n  t |	 t ƒ r¶| d k r¶| d ƒ n  | | ƒ d  S| | ƒ d  S(   Ni   t   __repr__t   {t    i    s   : i   s   ,
%s%s: s   , %s: t   }t   [t   ]t   (t   )s   ([s   ])s   ,
s   , t   ,(   t   _idR#   t
   _recursiont   Truet
   _recursivet   Falset	   _readablet   _reprt   _typet   _lenR   R   t   getattrR   t
   issubclasst   dictR+   R   R   t   itemsR"   t   listt   tuplet   sett	   frozensett   __name__t   len(   R    R   R   R   t	   allowancet   contextt   levelt   objidt   rept   typt   sepLinesR#   t   rt   lengthR@   t   keyt   entt   endchar(    (    s   /usr/lib/python2.7/pprint.pyR"   „   s¤    
		!	







	
	






c         C   sR   |  j  | | j ƒ  |  j | ƒ \ } } } | s< t |  _ n  | rN t |  _ n  | S(   N(   R'   t   copyR   R8   R9   R6   R7   (   R    R   RH   RI   t   reprR)   R*   (    (    s   /usr/lib/python2.7/pprint.pyR:   à   s    c         C   s   t  | | | | ƒ S(   sÈ   Format object for a specific context, returning a string
        and flags indicating whether the representation is 'readable'
        and whether the object represents a recursive construct.
        (   R   (   R    R   RH   t	   maxlevelsRI   (    (    s   /usr/lib/python2.7/pprint.pyR'   é   s    N(   RE   t
   __module__R   R!   R   R   R   R   R"   R:   R'   (    (    (    s   /usr/lib/python2.7/pprint.pyR   T   s   					\		c          C   s<  t  |  ƒ } | t k r d t j k r: t |  ƒ t t f Sd |  k rh d |  k rh d } i d d 6} n d } i d d 6} | j } t ƒ  } | j	 }	 xG |  D]? }
 |
 j
 ƒ  r¼ |	 |
 ƒ q |	 | |
 t |
 ƒ d d !ƒ ƒ q Wd | | j ƒ  | f t t f St | d	 d  ƒ } t | t ƒ r€| t j k r€|  sCd
 t t f St |  ƒ } | rt| | k rtd t | | k f S| | k r“t |  ƒ t t f Sd | | <t } t } g  } | j } | d 7} t } x— t |  j ƒ  ƒ D]ƒ \ } } | | | | | ƒ \ } } } | | | | | ƒ \ } } } | d | | f ƒ | oF| oF| } | sU| rÛt } qÛqÛW| | =d t | ƒ | | f St | t ƒ rž| t j k s¼t | t ƒ r| t j k rt | t ƒ rç|  sÞd t t f Sd } n4 t |  ƒ d k rd } n |  sd t t f Sd } t |  ƒ } | rP| | k rP| d t | | k f S| | k rot |  ƒ t t f Sd | | <t } t } g  } | j } | d 7} xT |  D]L } t | | | | ƒ \ } } } | | ƒ | sât } n  | r¥t } q¥q¥W| | =| t | ƒ | | f St |  ƒ } | | o5| j d ƒ t f S(   Nt   localet   't   "s   \"s   \'i   iÿÿÿÿs   %s%s%sR+   s   {}s   {...}s   %s: %ss   {%s}s   []s   [%s]s   (%s,)s   ()s   (%s)s   ...t   <(   R;   t   strR   t   modulesRT   R6   R8   t   getR$   R#   t   isalphaR%   R=   R   R>   R?   R+   R4   R5   t   appendR   R   R@   t
   _commajoinRA   RB   R<   t
   startswith(    R   RH   RU   RI   RL   t   closuret   quotest   qgetR&   R#   t   charRN   RJ   R)   R*   t
   componentsR_   R   t   kt   vt   kreprt	   kreadablet   krecurt   vreprt	   vreadablet   vrecurR'   t   ot   oreprt	   oreadablet   orecurRK   (    (    s   /usr/lib/python2.7/pprint.pyR   ó   s–    			$ 
	
		
	

	c         C   s   d t  |  ƒ j t |  ƒ f S(   Ns   <Recursion on %s with id=%s>(   R;   RE   R4   (   R   (    (    s   /usr/lib/python2.7/pprint.pyR5   G  s    c         C   s³   d d  l  } |  d  k rH d d d d g i d d 6d	 d
 6f g d }  n  t ƒ  } | j  ƒ  } t |  i  d  d ƒ | j  ƒ  } | j |  ƒ | j  ƒ  } d G| | GHd G| | GHd  S(   Niÿÿÿÿt   stringi   i   i   i   i   i   i   i   i † i    s   _safe_repr:s   pformat:(   i   i   (   t   timeR   R   R   R   (   R   Rt   t   pt   t1t   t2t   t3(    (    s   /usr/lib/python2.7/pprint.pyt
   _perfcheckL  s    0	t   __main__(    (   t   __doc__t   sysR   R   t	   cStringIOR    R$   t   ImportErrort   __all__t   joinR`   t   idR4   RF   R<   t   typeR;   R   R   R   R   R   R   R   R   R   R5   Ry   RE   (    (    (    s   /usr/lib/python2.7/pprint.pyt   <module>#   s0   						Ÿ	T	