관리-도구
편집 파일: pprint.cpython-34.pyo
� e fG: � @ s& d Z d d l Z d d l Z d d l m Z d d l m Z d d d d d d g Z d d d d d d d d �Z d d d d d d d �Z d d � Z d d � Z d d � Z Gd d � d � Z d d � Z Gd d � d � Z d d � Z d d � Z d d d � Z e d k r"e � n d S) a/ 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. � N)�OrderedDict)�StringIO�pprint�pformat� isreadable�isrecursive�saferepr� PrettyPrinter� �P �compactFc C s8 t d | d | d | d | d | � } | j | � d S)zAPretty-print a Python object to a stream [default is sys.stdout].�stream�indent�width�depthr N)r r )�objectr r r r r Zprinter� r �+/opt/alt/python34/lib64/python3.4/pprint.pyr . s c C s( t d | d | d | d | � j | � S)z<Format a Python object into a pretty-printed representation.r r r r )r r )r r r r r r r r r 6 s c C s t | i d d � d S)z=Version of repr() which can handle recursive data structures.Nr )� _safe_repr)r r r r r ; s c C s t | i d d � d S)z4Determine if saferepr(object) is readable by eval().Nr r )r )r r r r r ? s c C s t | i d d � d S)z8Determine if object requires a recursive representation.Nr � )r )r r r r r C s c @ s7 e Z d Z d Z d g Z d d � Z d d � Z d S)� _safe_keyaV Helper function for key functions when sorting unorderable objects. The wrapped-object will fallback to an Py2.x style comparison for unorderable types (sorting first comparing the type name and then by the obj ids). Does not work recursively, so dict.items() must have _safe_key applied to both the key and the value. �objc C s | | _ d S)N)r )�selfr r r r �__init__S s z_safe_key.__init__c C s� y | j j | j � } Wn t k r3 t } Yn X| t k r� t t | j � � t | j � f t t | j � � t | j � f k } n | S)N)r �__lt__� TypeError�NotImplemented�str�type�id)r �other�rvr r r r V s !*z_safe_key.__lt__N)�__name__� __module__�__qualname__�__doc__� __slots__r r r r r r r G s r c C s t | d � t | d � f S)z&Helper function for comparing 2-tuplesr r )r )�tr r r �_safe_tuplea s r( c @ s� e Z d Z d d d d d d d d �Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d d � Z d S)r r r Nr Fc C sj t | � } t | � } | | _ | | _ | | _ | d k rK | | _ n t j | _ t | � | _ d S)aD 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. compact If true, several items will be combined in one line. N) �int�_depth�_indent_per_level�_width�_stream�_sys�stdout�bool�_compact)r r r r r r r r r r f s zPrettyPrinter.__init__c C s3 | j | | j d d i d � | j j d � d S)Nr � )�_formatr- �write)r r r r r r � s zPrettyPrinter.pprintc C s/ t � } | j | | d d i d � | j � S)Nr )� _StringIOr3 �getvalue)r r �sior r r r � s zPrettyPrinter.pformatc C s | j | i d d � d S)Nr r )�format)r r r r r r � s zPrettyPrinter.isrecursivec C s, | j | i d d � \ } } } | o+ | S)Nr )r8 )r r �s�readable� recursiver r r r � s !zPrettyPrinter.isreadablec C sv | d } t | � } | | k rK | j t | � � d | _ d | _ d S| j | | | d � } t | � } | j d | | } t | � | k } | j } | rht | d d � } t | t � rt| d � | j d k r� | | j d d � n t | � } | rfd | | <| | j } t | t � rEt | j � � } n t | j � d t �} | d \ } } | j | | | � } | | � | d � | j | | | t | � d | d | | � | d k rOx| | d d � D]g \ } } | j | | | � } | d d | | f � | 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 � rS| t j k rSt | � } t | t � r| d � d } n� t | t � r<| d � d } ny | sP| | � d S| t k ro| d � d } n4 | | j � | d � d } | t | j � d 7} t | d t �} | j d k r�| | j d d � n | rd | | <| j | | | | j | d | | � | | =n t | t � rE| d k rE| d � n | | � d St | t � rht | � d k rh| t j k rhg } | j d � } | d k r�| d 7} | d 8} n x t | � D]� \ } } t | � } t | � | k r| j | � q�t j d | � d g } d } x� t! d t | � d � D]i } | | | | d } | | } t t | � � | k r�| r�| j t | � � n | } q:| } q:W| r�| j t | � � q�q�Wt | � d k r�| | � d S| d k r | d � n xE t | � D]7 \ } } | d k r:| d d | � n | | � q W| d k ra| d � n d Sn | | � d S)Nr TF�__repr__�{� �keyr z: r z, %s%s: �}�[�]�(�)z({z})�,z(\s+)� r2 )"r r4 � _recursion� _recursive� _readable�_reprr r, �len�getattr� issubclass�dictr+ �_OrderedDict�list�items�sortedr( r3 r<