ž §ÿfœ1c@s)dZddlZddlmZddlmZddddd d gZ d j Z e Z eZeZdd d ddd„Zd d ddd„Zdd „Zdd„Zdd„ZGdd„dƒZdd„ZGdd „d ƒZdd„Zdd„Zddd„Zedkr%eƒndS(u/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(u OrderedDict(uStringIOupprintupformatu isreadableu isrecursiveusaferepru PrettyPrinteru, iiPc Cs2td|d|d|d|ƒ}|j|ƒdS(uAPretty-print a Python object to a stream [default is sys.stdout].ustreamuindentuwidthudepthN(u PrettyPrinterupprint(uobjectustreamuindentuwidthudepthuprinter((u+/opt/alt/python33/lib64/python3.3/pprint.pyupprint3scCs"td|d|d|ƒj|ƒS(u<Format a Python object into a pretty-printed representation.uindentuwidthudepth(u PrettyPrinterupformat(uobjectuindentuwidthudepth((u+/opt/alt/python33/lib64/python3.3/pprint.pyupformat9scCst|iddƒdS(u=Version of repr() which can handle recursive data structures.iN(u _safe_repruNone(uobject((u+/opt/alt/python33/lib64/python3.3/pprint.pyusaferepr=scCst|iddƒdS(u4Determine if saferepr(object) is readable by eval().iiN(u _safe_repruNone(uobject((u+/opt/alt/python33/lib64/python3.3/pprint.pyu isreadableAscCst|iddƒdS(u8Determine if object requires a recursive representation.iiN(u _safe_repruNone(uobject((u+/opt/alt/python33/lib64/python3.3/pprint.pyu isrecursiveEscBs;|EeZdZdZdgZdd„Zdd„ZdS(u _safe_keyuVHelper 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. uobjcCs ||_dS(N(uobj(uselfuobj((u+/opt/alt/python33/lib64/python3.3/pprint.pyu__init__Usu_safe_key.__init__c Csy|jj|jƒ}Wntk r3t}YnX|tkr‹tt|jƒƒt|jƒftt|jƒƒt|jƒfk}n|S(N(uobju__lt__u TypeErroruNotImplementedustrutypeuid(uselfuotherurv((u+/opt/alt/python33/lib64/python3.3/pprint.pyu__lt__Xs   !*u_safe_key.__lt__N(u__name__u __module__u __qualname__u__doc__u __slots__u__init__u__lt__(u __locals__((u+/opt/alt/python33/lib64/python3.3/pprint.pyu _safe_keyIs  u _safe_keycCst|dƒt|dƒfS(u&Helper function for comparing 2-tuplesii(u _safe_key(ut((u+/opt/alt/python33/lib64/python3.3/pprint.pyu _safe_tuplecsu _safe_tuplecBs€|EeZdZdddddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS(u PrettyPrinteriiPcCs©t|ƒ}t|ƒ}|dks0tdƒ‚|dksT|dksTtdƒ‚|sftdƒ‚||_||_||_|dk r™||_n tj|_dS(uò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. iuindent must be >= 0udepth must be > 0uwidth must be != 0N( uintuAssertionErroruNoneu_depthu_indent_per_levelu_widthu_streamu_sysustdout(uselfuindentuwidthudepthustream((u+/opt/alt/python33/lib64/python3.3/pprint.pyu__init__hs  $     uPrettyPrinter.__init__cCs3|j||jddidƒ|jjdƒdS(Niu (u_formatu_streamuwrite(uselfuobject((u+/opt/alt/python33/lib64/python3.3/pprint.pyupprint‡suPrettyPrinter.pprintcCs/tƒ}|j||ddidƒ|jƒS(Ni(u _StringIOu_formatugetvalue(uselfuobjectusio((u+/opt/alt/python33/lib64/python3.3/pprint.pyupformat‹s uPrettyPrinter.pformatcCs|j|iddƒdS(Nii(uformat(uselfuobject((u+/opt/alt/python33/lib64/python3.3/pprint.pyu isrecursivesuPrettyPrinter.isrecursivecCs,|j|iddƒ\}}}|o+| S(Ni(uformat(uselfuobjectusureadableu recursive((u+/opt/alt/python33/lib64/python3.3/pprint.pyu isreadable“s!uPrettyPrinter.isreadablecCs÷|d}t|ƒ}||krK|jt|ƒƒd|_d|_dS|j|||dƒ}t|ƒ} t |ƒ|j d||k} |j} |j rÀ||j krÀ| |ƒdS| rét | ddƒ} t| tƒr”| dƒ|jdkr| |jddƒnt |ƒ} | r†d||<||j}t| tƒret|jƒƒ}nt|jƒdtƒ}|d\}}|j|||ƒ}| |ƒ| dƒ|j|||t |ƒd|d||ƒ| dkrox||dd…D]g\}}|j|||ƒ}| d d||fƒ|j|||t |ƒd|d||ƒqWn||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ƒr\| d ƒd}ny| sp| |ƒdS| tkr| dƒd }n4| | jƒ| dƒd}|t| jƒd7}t|dtƒ}|jdkrü| |jddƒn| r°d||<||j}|j|d|||d||ƒ| dkr™xM|dd…D]8}| dd|ƒ|j||||d||ƒqZWn||j}||=nt| tƒrØ| dkrØ| dƒn| |ƒdSn| |ƒdS(Niu__repr__u{u ukeyiu: iu, %s%s: u}u[u]u(u)u({u})u, u,TF(u_iduwriteu _recursionuTrueu _recursiveuFalseu _readableu_repru_typeu_lenu_widthu_depthugetattruNoneu issubclassudictu_indent_per_levelu _OrderedDictulistuitemsusortedu _safe_tupleu_formatu__repr__utupleusetu frozensetu__name__ulenu _safe_key(uselfuobjectustreamuindentu allowanceucontextuleveluobjidureputypusepLinesuwriteurulengthuitemsukeyuentuendchar((u+/opt/alt/python33/lib64/python3.3/pprint.pyu_format—s¨      !                               uPrettyPrinter._formatcCsR|j||jƒ|j|ƒ\}}}|s<d|_n|rNd|_n|S(NFT(uformatucopyu_depthuFalseu _readableuTrueu _recursive(uselfuobjectucontextulevelureprureadableu recursive((u+/opt/alt/python33/lib64/python3.3/pprint.pyu_reprõs  uPrettyPrinter._reprcCst||||ƒS(uÈ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. (u _safe_repr(uselfuobjectucontextu maxlevelsulevel((u+/opt/alt/python33/lib64/python3.3/pprint.pyuformatþsuPrettyPrinter.formatN( u__name__u __module__u __qualname__uNoneu__init__upprintupformatu isrecursiveu isreadableu_formatu_repruformat(u __locals__((u+/opt/alt/python33/lib64/python3.3/pprint.pyu PrettyPrintergs     ^ c! Cs0t|ƒ}|tkrdtjkr:t|ƒddfSd|krhd|krhd}idd6}nd}idd6}|j}tƒ}|j } xJ|D]B} | j ƒr¼| | ƒq| || t| ƒdd…ƒƒqWd||j ƒ|fddfSt |ddƒ} t|tƒr†| tjkr†|s=dSt|ƒ} |rn||krnd d| |kfS| |krt|ƒddfSd|| (u_typeu__name__u_id(uobject((u+/opt/alt/python33/lib64/python3.3/pprint.pyu _recursion]su _recursioncCs»ddl}|dkrHddddgidd6d d 6fgd }ntƒ}|jƒ}t|iddƒ|jƒ}|j|ƒ|jƒ}td ||ƒtd ||ƒdS(Niustringiiiiiiiii †u _safe_repr:upformat:(ii(utimeuNoneu PrettyPrinteru _safe_reprupformatuprint(uobjectutimeuput1ut2ut3((u+/opt/alt/python33/lib64/python3.3/pprint.pyu _perfcheckbs  0     u _perfchecku__main__(u__doc__usysu_sysu collectionsu OrderedDictu _OrderedDictuiouStringIOu _StringIOu__all__ujoinu _commajoinuidu_idulenu_lenutypeu_typeuNoneupprintupformatusaferepru isreadableu isrecursiveu _safe_keyu _safe_tupleu PrettyPrinteru _safe_repru _recursionu _perfchecku__name__(((u+/opt/alt/python33/lib64/python3.3/pprint.pyu#s,       ¡ U