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|ƒ}||_||_||_|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. N( tintRRR tselft_deptht_indent_per_levelt_widthRRt_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 RRR ((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 RRR8R-R*RERR,RBRAR6R?R>R;R9R4((R Rxs†      !               @             cCsV|i||iƒ|i|ƒ\}}}|p t |_ n|o t |_ n|S(N(RRR R-tcopyRR*treprRR R1R2R/R0(RR R-R*R RRG((R R3À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-RHR*((R RÉs( t__name__t __module__RRRRRRRR3R(((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||(R5R RIR+(R ((R R.'scCs¶dk}|djo5ddddghdd<dd