mfc@sdZddlZddlZyddlmZWn!ek rUddlmZnXdddddd gZd j Z e Z e ZeZdd d dd Zd d ddZdZdZdZdZd ddYZdZdZddZedkrendS(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. iN(tStringIOtpprinttpformatt isreadablet isrecursivetsafereprt PrettyPrinters, iiPc Cs2td|d|d|d|}|j|dS(sAPretty-print a Python object to a stream [default is sys.stdout].tstreamtindenttwidthtdepthN(RR(tobjectRRR R tprinter((s/usr/lib64/python2.7/pprint.pyR7scCs"td|d|d|j|S(s<Format a Python object into a pretty-printed representation.RR R (RR(R RR R ((s/usr/lib64/python2.7/pprint.pyR=scCst|idddS(s=Version of repr() which can handle recursive data structures.iN(t _safe_reprtNone(R ((s/usr/lib64/python2.7/pprint.pyRAscCst|idddS(s4Determine if saferepr(object) is readable by eval().iiN(R R(R ((s/usr/lib64/python2.7/pprint.pyREscCst|idddS(s8Determine if object requires a recursive representation.iiN(R R(R ((s/usr/lib64/python2.7/pprint.pyRIscCs@tj.tjr,tjddtnt|SWdQXdS(Ntignores%comparing unequal types not supported(twarningstcatch_warningst_syst py3kwarningtfilterwarningstDeprecationWarningtsorted(titerable((s/usr/lib64/python2.7/pprint.pyt_sortedMs     cBs\eZddd d dZdZdZdZdZdZdZ d Z RS( iiPcCs[t|}t|}||_||_||_|dk rK||_n tj|_dS(sHandle 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. N(tintt_deptht_indent_per_levelt_widthRt_streamRtstdout(tselfRR R R((s/usr/lib64/python2.7/pprint.pyt__init__Us       cCs3|j||jddid|jjddS(Nis (t_formatRtwrite(RR ((s/usr/lib64/python2.7/pprint.pyRtscCs/t}|j||ddid|jS(Ni(t _StringIOR!tgetvalue(RR tsio((s/usr/lib64/python2.7/pprint.pyRxs cCs|j|idddS(Nii(tformat(RR ((s/usr/lib64/python2.7/pprint.pyR}scCs,|j|idd\}}}|o+| S(Ni(R&(RR tstreadablet recursive((s/usr/lib64/python2.7/pprint.pyRs!cCs|d}t|}||krK|jt|t|_t|_dS|j|||d}t|} t ||j d||k} |j} |j r||j kr| |dSt | dd} t| tr| tjkr| d|jdkr!| |jddnt |} | rvd||<||j}t|j}|d\}}|j|||}| || d|j|||t |d|d||| dkr_x|dD]~\}}|j|||}| r| dd||fn| d ||j|||t |d|d||qWn||j}||=n| d dSt| tr| tjkst| tr| tjkst| tr| tjkst| tr| tjkrt |} t| tr*| d d }nt| trv| sM| d dS| dd}t|}|d7}n\t| tr| s| ddS| dd}t|}|d7}n| dd}|jdkr| r| |jddn| rd||<||j}|j|d|||d||| dkrxZ|dD]K}| rx| dd|n | d|j||||d||qWWn||j}||=nt| tr| dkr| dn| |dS| |dS(Nit__repr__t{t is: is, %s%s: s, %s: t}t[t]sset()sset([s])is frozenset()s frozenset([i t(t)s, s, t,(t_idR"t _recursiontTruet _recursivetFalset _readablet_reprt_typet_lenRRtgetattrRt issubclasstdictR*RRtitemsR!tlistttupletsett frozenset(RR RRt allowancetcontexttleveltobjidtrepttyptsepLinesR"trtlengthR?tkeytenttendchar((s/usr/lib64/python2.7/pprint.pyR!s      !                                 cCsR|j||j|j|\}}}|s<t|_n|rNt|_n|S(N(R&tcopyRR7R8R5R6(RR RERFtreprR(R)((s/usr/lib64/python2.7/pprint.pyR9s  cCst||||S(sFormat 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 (RR REt maxlevelsRF((s/usr/lib64/python2.7/pprint.pyR&sN( t__name__t __module__RR RRRRR!R9R&(((s/usr/lib64/python2.7/pprint.pyRTs     c c Cs<t|}|tkrdtjkr:t|ttfSd|krhd|krhd}idd6}nd}idd6}|j}t}|j } xG|D]?} | j r| | q| || t| dd!qWd||j |fttfSt |d d} t|tr| tjkr|sCd ttfSt|} |rt||krtd t| |kfS| |krt|ttfSd|| R*R3R4tappendR RR?t _commajoinR@RAR;t startswith( R RERRRFRItclosuretquotestqgetR%R"tcharRKRGR(R)t componentsR]Rtktvtkreprt kreadabletkrecurtvreprt vreadabletvrecurR&totoreprt oreadabletorecurRH((s/usr/lib64/python2.7/pprint.pyR s         $                       cCsdt|jt|fS(Ns(R:RSR3(R ((s/usr/lib64/python2.7/pprint.pyR4NscCsddl}|dkrHddddgidd6d d 6fgd }nt}|j}t|idd |j}|j||j}d G||GHdG||GHdS(Nitstringiiiiiiiiiis _safe_repr:spformat:(ii(ttimeRRR R(R Rrtptt1tt2tt3((s/usr/lib64/python2.7/pprint.pyt _perfcheckSs  0      t__main__((t__doc__tsysRRt cStringIORR#t ImportErrort__all__tjoinR^tidR3tlenR;ttypeR:RRRRRRRRR R4RwRS(((s/usr/lib64/python2.7/pprint.pyt#s0          T