ó DÑÕfc@sdZddlZddlZyddlmZWn!ek rUddlmZnXdddddd gZd j Z e Z e ZeZdd d dd „Zd d dd„Zd„Zd„Zd„Zd„Zd dd„ƒYZd„Zd„Zdd„ZedkreƒndS(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(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|iddƒdS(s=Version of repr() which can handle recursive data structures.iN(t _safe_reprtNone(R ((s/usr/lib64/python2.7/pprint.pyRAscCst|iddƒdS(s4Determine if saferepr(object) is readable by eval().iiN(R R(R ((s/usr/lib64/python2.7/pprint.pyREscCst|iddƒdS(s8Determine if object requires a recursive representation.iiN(R R(R ((s/usr/lib64/python2.7/pprint.pyRIscCs@tjƒ.tjr,tjddtƒnt|ƒSWdQXdS(Ntignores%comparing unequal types not supported(twarningstcatch_warningst_syst py3kwarningtfilterwarningstDeprecationWarningtsorted(titerable((s/usr/lib64/python2.7/pprint.pyt_sortedMs     cBs\eZddd d d„Zd„Zd„Zd„Zd„Zd„Zd„Z d „Z RS( iiPcCs[t|ƒ}t|ƒ}||_||_||_|dk rK||_n tj|_dS(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. N(tintt_deptht_indent_per_levelt_widthRt_streamRtstdout(tselfRR R R((s/usr/lib64/python2.7/pprint.pyt__init__Us       cCs3|j||jddidƒ|jjdƒdS(Nis (t_formatRtwrite(RR ((s/usr/lib64/python2.7/pprint.pyRtscCs/tƒ}|j||ddidƒ|jƒS(Ni(t _StringIOR!tgetvalue(RR tsio((s/usr/lib64/python2.7/pprint.pyRxs cCs|j|iddƒdS(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.pyR€s!cCs|d}t|ƒ}||krK|jt|ƒƒt|_t|_dS|j|||dƒ}t|ƒ} t |ƒ|j d||k} |j} |j rÀ||j krÀ| |ƒdSt | ddƒ} t| tƒr„| tjkr„| dƒ|jdkr!| |jddƒnt |ƒ} | rvd||<||j}t|jƒƒ}|d\}}|j|||ƒ}| |ƒ| dƒ|j|||t |ƒd|d||ƒ| dkr_x|dD]~\}}|j|||ƒ}| r| dd||fƒn| d |ƒ|j|||t |ƒd|d||ƒqÚWn||j}||=n| d ƒdSt| tƒr¢| tjksüt| tƒrÀ| tjksüt| tƒrÞ| tjksüt| tƒrö| tjkröt |ƒ} t| tƒr*| d ƒd }n¨t| tƒrv| sM| d ƒdS| dƒd}t|ƒ}|d7}n\t| tƒrÂ| s™| dƒdS| dƒd}t|ƒ}|d7}n| dƒd}|jdkrÿ| rÿ| |jddƒn| rÀd||<||j}|j|d|||d||ƒ| dkr©xZ|dD]K}| rx| dd|ƒn | dƒ|j||||d||ƒqWWn||j}||=nt| tƒrè| dkrè| dƒn| |ƒ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.pyR9çs  cCst||||ƒ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 (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|tƒr€| tjkr€|sCd ttfSt|ƒ} |rt||krtd t| |kfS| |kr“t|ƒ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.pyR4NscCs³ddl}|dkrHddddgidd6d d 6fgd }ntƒ}|jƒ}t|idd ƒ|jƒ}|j|ƒ|jƒ}d G||GHdG||GHdS(Niÿÿÿÿtstringiiiiiiiii †is _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