mò %U²Ic@sÞdZdkZdklZddddddgZd iZe Z e Z e Zdd d dd „Zd d dd „Zd„Zd„Zd„Zdfd„ƒYZd„Zd„Zdd„Zedjo eƒ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. N(sStringIOtpprinttpformatt isreadablet isrecursivetsafereprt PrettyPrinters, iiPc Cs2td|d|d|d|ƒ}|i|ƒdS(sAPretty-print a Python object to a stream [default is sys.stdout].tstreamtindenttwidthtdepthN(RRRRR tprinterRtobject(R RRRR R ((t#/data/zmath/lib/python2.4/pprint.pyR3s!cCs"td|d|d|ƒi|ƒS(s<Format a Python object into a pretty-printed representation.RRR N(RRRR RR (R RRR ((R R9scCst|hddƒdS(s=Version of repr() which can handle recursive data structures.iN(t _safe_reprR tNone(R ((R R=scCst|hddƒdS(s4Determine if saferepr(object) is readable by eval().iiN(R R R(R ((R RAscCst|hddƒdS(s8Determine if object requires a recursive representation.iiN(R R R(R ((R REscBs\tZddddd„Zd„Zd„Zd„Zd„Zd„Zd „Z d „Z RS( NiiPcCs©t|ƒ}t|ƒ}|djp td‚|djp|djp td‚|p td‚||_||_||_ |dj o ||_ n t i |_ 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. isindent must be >= 0sdepth must be > 0swidth must be != 0N(tintRRtAssertionErrorR Rtselft_deptht_indent_per_levelt_widthRt_streamt_syststdout(RRRR R((R t__init__Js  $     cCs!|ii|i|ƒdƒdS(Ns (RRtwriteRR (RR ((R RiscCs/tƒ}|i||ddhdƒ|iƒS(Ni(t _StringIOtsioRt_formatR tgetvalue(RR R((R Rls cCs|i|hddƒdS(Nii(RtformatR (RR ((R RqscCs-|i|hddƒ\}}}|o| S(Ni(RRR tstreadablet recursive(RR R RR!((R Rts!cCs |d}t|ƒ} | |jo-|it|ƒƒt|_ t |_ dSn|i |||dƒ}t|ƒ} t|ƒ|id||j}|i}|oYt| ddƒ}t| tƒo›|tijo‹|dƒ|idjo||iddƒnt|ƒ}|o3d|| <||i}|iƒ} | iƒ| d\} } |i | ||ƒ}||ƒ|dƒ|i"| ||t|ƒd|d||ƒ|djozxw| dD]g\} } |i | ||ƒ}|dd||fƒ|i"| ||t|ƒd|d||ƒqÊWn||i}|| =n|d ƒdSnt| t#ƒo|t#ijp t| t$ƒoh|t$ijoXt| t#ƒo|d ƒd }n|d ƒd }|idjo||iddƒnt|ƒ}|o«d|| <||i}|i"|d|||d||ƒ|djoKxH|dD]8} |dd|ƒ|i"| |||d||ƒqfWn||i}|| =nt| t$ƒo|djo|dƒn||ƒdSqÿn||ƒdS(Nit__repr__t{t is: is, %s%s: t}t[t]t(t)s, t,(&tlevelt_idR tobjidtcontextRRt _recursiontTrueRt _recursivetFalset _readablet_reprtrept_typettypt_lenRRt allowancetsepLinestgetattrRtrt issubclasstdictR"RtlengthtitemstsorttkeytentRtlistttupletendchar(RR RRR9R.R+RFRR-RCRBR7R@R?R<R:R5((R Rxs†      !               @             cCsV|i||iƒ|i|ƒ\}}}|p t |_ n|o t |_ n|S(N(RRR R.tcopyRR+treprR R!R2R3R0R1(RR R.R+R!R RH((R R4À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. N(R R R.t maxlevelsR+(RR R.RIR+((R RÉs( t__name__t __module__RRRRRRRR4R(((R RIs     H c CsŠt|ƒ}|tjoúdtijot|ƒttfSnd|jo&d|jod}hdd<}nd}hdd<}|i } t ƒ}|i}xI|D]A}|iƒo||ƒqª|| |t|ƒdd!ƒƒqªWd||iƒ|fttfSnt|d dƒ}t|tƒos|tijoc|pd ttfSnt|ƒ}|o$||jod t||jfSn||jot|ƒttfSnd||R"R,R-RIR+R.R/R R!t componentstappendR Rt iteritemstktvtkreprt kreadabletkrecurtvreprt vreadabletvrecurt _commajoinRDRERR8totoreprt oreadabletorecurR5t startswith( R R.RIR+R^RVRSRdRbRURYReR_R!RgR5RR RRaR-RXR`R7RRR]RfRR[RR<R\((R R Ósš      $$       @          cCsdt|ƒit|ƒfS(Ns(R6R RJR,(R ((R R/'scCs¶dk}|djo5ddddghdd<dd