}BFjx UdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZejd krdd lmZdd lmZee ejZ gdZdZeejdZ d\dZ!dZ"dddefdZ#dddefdZ$GddZ%Gdde%Z&dZ'Gdde&Z(Gd d!Z)Gd"d#e)Z*Gd$d%e)Z+Gd&d'e)Z,Gd(d)Z-Gd*d+Z.Gd,d-Z/Gd.d/Z0d0Z1d1Z2d2Z3d3Z4d4Z5Gd5d6Z6d7Z7d8Z8d9Z9d:Z:d;Z;d<ZZ?n #e@$reAZ?YnwxYwieBe:eCe:eDe:eEe2d>d?eFe2d@dAeGe4dBdCeHe3dBdCeIe3dDdEeJe5e e7ee9ejKe;ejLe;ejMe:ejNe8eje:ejOe:e?er?opencloses r groupz_PrettyPrinterBase.groups` &&& * EEE NN65 ) ) ) ) )DNN65 ) ) ) )s 6AN)rrr)__name__ __module__ __qualname__rr?rEr5r r;r;sM''^'***^***r5r;c\eZdZdZddefdZdZdZdZdd Z d Z dd Z dZ ddZ dZdS)ra Baseclass for the `RepresentationPrinter` prettyprinter that is used to generate pretty reprs of objects. Contrary to the `RepresentationPrinter` this printer knows nothing about the default pprinters or the `_repr_pretty_` callback method. r)r*c||_||_||_||_d|_d|_t |_td}|g|_ t||_ d|_ dSNr) outputr1r2r- output_width buffer_widthrbufferGroup group_stack GroupQueue group_queuer=)r>rMr1r2r- root_groups r __init__zPrettyPrinter.__init__sm " ,gg 1XX &<%j11r5c|jrZ|j}||j|j|_|xj|jzc_|jZ|jrt|jdtr|j}||j|j|_|xj|jzc_|jr$t|jdtzdSdSdSdSrL) breakablesrPpopleftrMrNrOwidth isinstanceText)r>rExs r _break_one_groupzPrettyPrinter._break_one_groups ) ##%%A !d6G H HD     (   )k )jQ>> ) ##%%A !d6G H HD     (  k )jQ>> ) ) ) ) ) ) ) ) )r5c|j|j|jzkrL|j}|sdS|||j|j|jzkJdSdSN)r1rNrOrTdeqr^r>rEs r _break_outer_groupsz!PrettyPrinter._break_outer_groupssunt043DDDD$((**E   ! !% ( ( ( nt043DDDDDDDDr5ct|}|jr|jd}t|ts(t}|j|||||xj|z c_|dS|j ||xj |z c_ dS)zAdd literal text to the output.N) lenrPr[r\appendaddrOrcrMr9rN)r>rrZtexts r rizPrettyPrinter.textsC ; ';r?DdD)) )vv ""4((( HHS%    &    $ $ & & & & & K  c " " "    &    r5 ct|}|jd}|jrj||j|j|jd|jz|j|_d|_ dS|j t||||xj |z c_ | dS)z Add a breakable separator to the output. This does not mean that it will automatically break here. If no breaking on this position takes place the `sep` is inserted which default to one space. rerjrN)rfrR want_breakr.rMr9r2r=rNrOrPrg Breakablerc)r>seprZrEs r breakablezPrettyPrinter.breakables C $   ' JJLLL K  dl + + + K  cD$44 5 5 5 $ 0D  !D    K  yeT:: ; ; ;    &    $ $ & & & & &r5c6|j}|r||||j|j|jd|jz|j|_d|_ dS)z_ Explicitly insert a newline into the output, maintaining correct indentation. rjrN) rTrar^r.rMr9r2r=rNrOrbs r break_zPrettyPrinter.break_ s $$&&  )  ! !% ( ( (  $,''' # 00111 ,r5rrc|r||t|jdjdz}|j||j||xj|z c_dS)z Begin a group. The first parameter specifies the indentation for the next line (usually the width of the opening text), the second the opening text. All parameters are optional. reN)rirQrRdepthrgrTenqr=)r>r?rCrEs r rAzPrettyPrinter.begin_groups   IIdOOOd&r*01455 &&& U### F"r5c#Kt|D]^\}}|jrL||jkrA|d||ddS||fV_dS)z>like enumerate, but with an upper limit on the number of items,...N) enumerater-riro)r>seqidxr]s r _enumeratezPrettyPrinter._enumerate(snn  FC" sd.A'A'A #    %   q&LLLL   r5c|xj|zc_|j}|js|j||r||dSdS)z0End a group. See `begin_group` for more details.N)r=rRpoprXrTremoveri)r>dedentrDrEs r rBzPrettyPrinter.end_group2sv F" $$&& +   # #E * * *   IIe       r5c|jD]0}|xj||j|jz c_1|jd|_dS)z&Flush data that is left in the buffer.rN)rPrNrMclearrO)r>datas r r.zPrettyPrinter.flush;saK M MD   T[$:K!L!L L    r5N)rj)rr)rFrGrH__doc__MAX_SEQ_LENGTHrVr^rcrirorqrAr|rBr.rIr5r rrs*,T.    )))))) ' ' '''''&    # # # #r5rct|dsA t|j|tfi}|jdd}n#t $r|g}Yn wxYw|j}|S)z| Get a reasonable method resolution order of a class and its superclasses for both old-style and new-style classes. __mro__rsre)hasattrtyperFobjectr TypeError) obj_classmros r _get_mrorCs 9i ( (   *Y/)V1DbIII #AbD)CC    +CCC  Js? AAc4eZdZdZddddddefdZdZdZdS) ra Special pretty printer that has a `pretty` method that calls the pretty printer for a python object. This class stores processing data on `self` so you must *never* use this class in a threaded environment. Always lock it or reinstanciate it. Instances also have a verbose flag callbacks can access to control their output. For example the default instance repr prints all attributes and methods that are not prefixed by an underscore if the printer is in verbose mode. Fr)r*Nc ,t|||||||_g|_|t}||_|t}||_|t}||_ dS)Nr,) rrVr0stack_singleton_pprinterscopysingleton_pprinters_type_pprinterstype_pprinters_deferred_type_pprintersdeferred_pprinters) r>rMr0r1r2rrrr-s r rVzRepresentationPrinter.__init__es tVYP^___   &"6";";"="= #6  !,1133N,  %!9!>!>!@!@ "4r5crt|}||jv}|j|| t |ddpt |} |j|}||||||jS#ttf$rYnwxYwt|D]q}||j vrG|j ||||c||jS| |}|<||||c||jSd|jvrR|j}t!|r<||||c||jS|t"urgd|jvr^t!t |ddr@t%|||c||jSst'|||||jS#||jwxYw)zPretty print the given object. __class__N _repr_pretty___repr__)idrrgrAr!rrrBr~rKeyErrorrr_in_deferred_types__dict__rcallabler _repr_pprint_default_pprint)r>robj_idcyclerr4clsmeths r rzRepresentationPrinter.prettyvsC$*$ &!!! - %c;==JcI 126:wsD%00H NN    JNN    Qx(     ** B B$---34.s3CuEEEE: NN    JNN    7#55c::G*&wsD%88880 NN    JNN    '+cl::#D'~~>'+tCu'='= = = NN    JNN     v-- *cl : : !)sJ)M)M N N !;$0T5#A#AAA NN    JNN    #3e44 NN    JNN     NN    JNN    sI J) B06 J0CJC7J)%J<-JAJJ/J6ct|dd}t|dd}||f}d}||jvr$|j|}||j|<|S)a Check if the given class is specified in the deferred type registry. Returns the printer from the registry if it exists, and None if the class is not in the registry. Successful matches will be moved to the regular type registry for future use. rGNrF)r!rr~r)r>rmodnamer#r4s r rz(RepresentationPrinter._in_deferred_typessjCt44S*d33Dk $) ) )-11#66G'.D  $r5)rFrGrHrrrVrrrIr5r rrVsd  (-D $%5555"333jr5rceZdZdZdS) Printablec|Sr`rIr>r3rNs r rMzPrintable.outputsr5N)rFrGrHrMrIr5r rrs#r5rc eZdZdZdZdZdS)r\c"g|_d|_dSrL)objsrZr>s r rVz Text.__init__s  r5cT|jD]}||||jzSr`)rr9rZ)r>r3rNrs r rMz Text.outputs59  C LL    dj((r5cZ|j||xj|z c_dSr`)rrgrZ)r>rrZs r rhzText.adds,  e r5N)rFrGrHrVrMrhrIr5r r\r\sA))) r5r\ceZdZdZdZdS)rmc||_||_||_|j|_|jd|_|jj|dS)Nre)rrZrr=rRrErXrg)r>rzrZrs r rVzBreakable.__init__sP  !-'+  $$T*****r5c|jj|jjrC||jj|d|jz|jS|jjs$|jj |j||j ||j zS)Nrj) rErXrYrlr9rr2r=rTrrrZrs r rMzBreakable.outputs %%''' :  $ LL, - - - LLt// 0 0 0# #z$ 7 K # * *4: 6 6 6 TXdj((r5N)rFrGrHrVrMrIr5r rmrms2+++ ) ) ) ) )r5rmceZdZdZdS)rQcH||_t|_d|_dS)NF)rtrrXrl)r>rts r rVzGroup.__init__s ''r5N)rFrGrHrVrIr5r rQrQs#     r5rQc&eZdZdZdZdZdZdS)rScHg|_|D]}||dSr`)queueru)r>groupsrEs r rVzGroupQueue.__init__s3   E HHUOOOO  r5c|j}|t|jdz kr5|jg|t|jdz k5|j||dS)Nrs)rtrfrrg)r>rErts r ruzGroupQueue.enqsr c$*oo))) J  b ! ! !c$*oo))) 5  '''''r5c|jD]L}tt|D]\}}|jr||=d|_|ccS|D] }d|_ |dd=MdS)NT)rryreversedrXrl)r>rr{rEs r razGroupQueue.deqsZ  E'88 ! ! U#!c '+E$ LLLLL! ( (#'  aaa  r5ct |j|j|dS#t$rYdSwxYwr`)rrtr ValueErrorrbs r rzGroupQueue.remove sL  Ju{ # * *5 1 1 1 1 1    DD s %) 77N)rFrGrHrVrurarrIr5r rSrSsP (((   r5rSceZdZdZdZdZdS)rz Object such that ``p.pretty(RawText(value))`` is the same as ``p.text(value)``. An example usage of this would be to show a list as binary numbers, using ``p.pretty([RawText(bin(i)) for i in integers])``. c||_dSr`valuer>rs r rVzRawText.__init__  r5c:||jdSr`)rir)r>prs r rzRawText._repr_pretty_s tzr5NrFrGrHrrVrrIr5r rrs< r5rc4eZdZdZdZedZdZdS)rzY Object which emits a line-wrapped call expression in the form `__name(*args, **kwargs)` c4|}||_||_||_dSr`)rargskwargs)_CallExpression__self_CallExpression__namerrr>s r rVzCallExpression.__init__ s"   r5cfd}|S)Ncg|Ri|Sr`rI)rrrrs r innerz%CallExpression.factory..inner*s#3t-d---f-- -r5rI)rrrs`` r factoryzCallExpression.factory(s' . . . . . . r5cdfd}|jdz}t||d5|jD]!}||"|jD]d\}}||dz}t||5|dddn #1swxYwYe ddddS#1swxYwYdS)NFcbr)dddS)NrwT)riro)rstartedsr new_itemz.CallExpression._repr_pretty_..new_item3s0 s  GGGr5()=)rrErfrrrr') r>rrrprefixargarg_name arg_prefixrs ` @r rzCallExpression._repr_pretty_.s      S WWS[[&# . . " "y    !%!2!2!4!4 " " # %^ WWS__j99""HHSMMM""""""""""""""" "  " " " " " " " " " " " " " " " " " "s6A:C/3C C/C C/C C//C36C3N)rFrGrHrrV classmethodrrrIr5r rrsScc[ """""r5rceZdZdZdZdZdS)rz/ Wrapper that shows a string with a `r` prefix c||_dSr`rrs r rVzRawStringLiteral.__init__Hrr5ct|j}|dddvr |dd}d}nd}||ddz}||dS)NrsuUurrz\\\)reprrreplaceri)r>rr base_reprrs r rzRawStringLiteral._repr_pretty_Kso$$ RaR=D !!"" IFFFY..vt<<<  yr5NrrIr5r rrFs899r5rct|ddpt|}t|ddtjurt |||dS|dd|||dt|z|r|dn |j rd}t|D]}| d s t||}n#t$rY5wxYwt|tjrT|s|d ||||d t%|dz}|xj|z c_|||xj|zc_d }|dd dS)zw The default print function. Used if an object does not provide one and it's none of the builtin objects. rNrrs)r!rrrrrArrirr0dir startswithrAttributeErrorr[types MethodTyperorfr=rB)rrrklassfirstr#rsteps r rrVs #{D 1 1 >T#YYEUJ--V_DDS!U###MM!SHHUOOOFF:3      v s88  C>>#&& #C--EE%HeU%566 FF3KKK s s 3xx!| %  % KK3s+C<< D D cfd}|S)z| Factory that returns a pprint function useful for sequences. Used by the default pprint for tuples and lists. c|r|dzzSt}||||D]E\}}|r)|d|||Ft|dkr*t |tr|d||dS)Nrxrwrs) rirfrAr|rorr[tuplerB)rrrrr{r]endstarts r rz$_seq_pprinter_factory..inners  /66%%-#-.. .5zz dE"""ll3''  FC s  HHQKKKK s88q==ZU33= FF3KKK D#r5rIrrrs`` r _seq_pprinter_factoryr|)       Lr5cfd}|S)zP Factory that returns a pprint function useful for sets and frozensets. cN|r|dzzSt|dkr,|t|jdzdSt}|||jrt||jkst |}n|}||D]E\}}|r)|d|| |F| |dS)Nrxrz()rw) rirfrrFrAr-r(r|rorrB) rrrrr'r{r]rrs r rz$_set_pprinter_factory..inners  /66%%-#-.. . s88q== FF499%, - - - - -u::D MM$ & & &$ SQ5E)E)E*3//,,u--  Q"FF3KKKKKMMM KKc " " " " "r5rIrs`` r _set_pprinter_factoryrs)######( Lr5cfd}|S)zj Factory that returns a pprint function used by the default pprint of dicts and dict proxies. c|r|dSt}|||}||D]u\}}|r)|d||||d|||v||dS)Nz{...}rwz: )rirfrAkeysr|rorrB) rrrrrr{r#rrs r rz%_dict_pprinter_factory..inners  #66'?? "5zz dE"""xxzz T**  HC s  HHSMMM FF4LLL HHSX     D#r5rIrs`` r _dict_pprinter_factoryrrr5cv|dd||j|d|t r(|jj}|||urdn|n||j|dddS)zThe pprint for the super type.zrrdone_oneflags r rz_ReFlags._repr_pretty_sp DzGB---  FF3KKKut|$$$ r5N)rFrGrHrVrrIr5r rrs2     r5rc2td}|jrE||t |jt |jdS||t |jdS)z4The pprint function for regular expression patterns.z re.compileN)rrflagsrrpatternr)rrr re_compiles r _re_pattern_pprintr s'' 55J y< ,S[998CI;N;NOOPPPPP ,S[99::;;;;;r5ctd}|r-||tddS||di|jdS)z.The pprint function for types.SimpleNamespace. namespacerxNrI)rrrrr)rrrr"s r _types_simplenamespace_pprintr#so&&{33I , 75>>**+++++ **S\**+++++r5cdtt|Dddtgkrt|||dSt|dd} |j}t |t stdn.#t$r!|j}t |t sd}YnwxYw|dvr| |dS| |dz|zdS) z!The pprint for classes and types.c4g|]}dt|v|S)r)vars).0ms r z _type_pprint..s(@@@a*Q*?*?*?*?*?r5NrsrGz Try __name__z)N __builtin__builtins exceptions.) rrrr!rHr[r&rrFri)rrrrrs r _type_pprintr.sA@8DII&&@@@!DNNS!U### \4 0 0C $$$$ ,N++ + , $$$|$$$ $#D$  === t  sSy4     s+B (B54B5c(t|}|}|5t|D]0\}}|r|||1 ddddS#1swxYwYdS)z9A pprint that just redirects to the normal repr function.N)r splitlinesrEryrqri)rrrrMlinesr{ output_lines r rrs#YYF     E   )% 0 0  C  FF;                       sABB B ct|d|j}|j}|r |dvr|dz|z} |tt |z}n#t $r|}YnwxYw|d|zdS)z4Base pprint for all functions and builtin functions.rH)r*r+r,r-z N)r!rFrGr&rrri)rrrrrfunc_defs r _function_pprintr5$s ncl ; ;D .C  sCCCSy4Ys^^,,,xx xxxFF?X %&&&&&sA AAc t|jd|jj}|jjdvr|jjd|}|t |gt|ddRdS)zBase pprint for all exceptions.rH)r,r+r-rrIN)rrrFrGrr)rrrrs r _exception_pprintr71sv 3=.#-2H I ID }'AAA-222DD9HH^D <73#;#; < < <=====r5_exception_baserr[]{}z frozenset({z})zenviron{zmappingproxy({rcTt|d}| |t|<|S)z0 Add a pretty printer for a given type. N)rget)typfuncoldfuncs r rrhs.!!#t,,G # Nr5c\||f}t|d}| |t|<|S)z| Add a pretty printer for a type specified by the module and name of a type rather than the type object itself. N)rr>) type_module type_namer@r#rAs r rrrs9  "C&**355G (, % Nr5Tct|jj}|r-||t ddS|||jt|dSNrx)rrrrFrrdefault_factorydictrrrcls_ctors r _defaultdict_pprintrKsw%%cm&<==H ; '%..))***** #-tCyy99:::::r5ct|jj}|r-||t ddSt |r?||t|dS||dSrF) rrrrFrrrfr$r'rIs r _ordereddict_pprintrMs%%cm&<==H  '%..))***** S $syy{{++,,----- r5cxt|jj}|r-||t ddS|j4||t||jdS||t|dS)Nrx)maxlen)rrrrFrrrOr$rIs r _deque_pprintrPs%%cm&<==H & '%..))*****   $s))CJ77788888 $s))$$%%%%%r5ct|jj}|r-||t ddSt |r?||t|dS||dSrF) rrrrFrrrfrH most_commonrIs r _counter_pprintrSs%%cm&<==H  '%..))***** S $s00112233333 r5ct|jj}|r-||t ddS|||jdSrF)rrrrFrrrrIs r _userlist_pprintrUsn%%cm&<==H % '%..))***** #(##$$$$$r5 collections defaultdict OrderedDictrCounterUserList__main__) randrangeceZdZdZdZdS)Foocd|_tjd|_tt dtdd|_d|_ dd|g|_ dS)Nrsz\s+(gg@blubblah) foorcompilebarrHfromkeysranger\rbheher$rs r rVz Foo.__init__sXDHz&))DH eBii1b1A1ABBDI$DI.DIIIr5c$tddS)Nrd)printrs r get_fooz Foo.get_foos %LLLLLr5N)rFrGrHrVrlrIr5r r^r^s2 / / /     r5r^)r0r`)ir contextlibrdatetimeosrr7rrVrinspectriorwarningsrIPython.utils.decoratorsrIPython.utils.py3compatr typingr version_info annotationlibr functoolsr FORWARDREF__all__rrre_re_pattern_typer!r(rrr;rrrrr\rmrQrSrrrrrrrr rr r#r.rr5r7__annotations__ BaseExceptionr8 NameErrorrintfloatr&rr$rHset frozensetsuper FunctionTypeBuiltinFunctionTyperSimpleNamespace timedeltarenviron _env_typeMappingProxyTypeslicerhbytesrrrrgmaprEllipsisNotImplementedrrKrMrPrSrUrFrandomr\r^rIr5r rs]]]~&%%%%% ******((((((w$$$$$$!!!!!! V5FGGGI U U U4  2''       T.T.********(}}}}}&}}}@&eeeeeMeeeP     9    ))))) ))),     I   >        %"%"%"%"%"%"%"%"P         ###L,6,           ,<<<,,,!!!<     ' ' '>>> #OO   OOO     5 5c3 ? ?   5 5c3 ? ?   6 6sC @ @  5 5c3 ? ? 5 5mT J J  2   0  0    =   !"  #$ 1%, D    D!7!7 C!H!HOI*@*@AQSW*X*X&'%%%"$$###   }}SSdD%&4.6&7&78DFF;;;&&&%%% /BCCC /BCCC777 ?;;; ,<=== z               F3355$s2E55E?>E?