U cf@s@UddlZddlZddlZddlZddlZddlZddlmZddlmZmZm Z m Z m Z ddlm Z m Z mZddlmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z dd l!m"Z"zddl#Z$e%e$d Z&Wne'k rd Z&YnXd d l(m)Z)d dl*m+Z+d dl,m-Z-d dl.m/Z/d dl0m1Z1d dl2m3Z3d dl4m5Z5m6Z6d dl7m8Z8d dl9m:Z:erd dl;mZ>m?Z?m@Z@mAZAeeBdddZCeeddddZDeEeBdddZFeGdgZHeEeBdd d!ZIdeed#d$eBeBeeJeeJeeJeBe eKdfd% d&d'ZLeEe eMeeMd(ffeBd)d*d+ZNded#d$eBeBeeJeeJeeJeBdd, d-d.ZOGd/d0d0e5ZPeeefeeKeKeKfd1d2d3ZQd4eeKeKeKfd1d5d6ZRejSd7d8eeRe eQed9d8e d:d8eTd;d8edd8e d?d8eWd@d8eXdAd8edBd8i ZYeeMeegeeKeKeKfffeZdC<eXeY[Z\eTejSeefZ]eeBddDdEZ^e GdFdGdGZ_e GdHdIdIZ`eeBddJdKZadeeeJeeJeeJe_dLdMdNZbdOdPdddd dQeeJeJeeJeeJeeJeBeKdRdSdTZcddUdddd dVeed#eBeeJeeJeeJeBddWdXdYZdeedZkr.display_hook) BaseFormattercs:eZdZUdZeed<eedfdd ZdS)zinstall..RichFormatterTpprintrdc s,|jr t|dSt|SdS)N)rKrLrNrOrPrQrR)rjrarepr)selfrJrRrrNrQrOrPrLr6r7__call__s z'install..RichFormatter.__call__N)__name__ __module__ __qualname__rjbool__annotations__rrnr6rmr6r7 RichFormatters  rtz text/plain) pip._vendor.richrrer get_ipython NameErrorsys displayhookIPython.core.formattersridisplay_formatter formatters) rKrLrMrNrOrPrQrRrhiprirtrich_formatterr6) rKrMrRrrNrQrOrPrLr7installs   "    rc@seZdZdZddddddddddddd eedeeded eeeeeeeeeeeedd d d Zd dddddZ d dddddZ dS)r^akA rich renderable that pretty prints an object. Args: _object (Any): An object to pretty print. highlighter (HighlighterType, optional): Highlighter object to apply to result, or None for ReprHighlighter. Defaults to None. indent_size (int, optional): Number of spaces in indent. Defaults to 4. justify (JustifyMethod, optional): Justify method, or None for default. Defaults to None. overflow (OverflowMethod, optional): Overflow method, or None for default. Defaults to None. no_wrap (Optional[bool], optional): Disable word wrapping. Defaults to False. indent_guides (bool, optional): Enable indentation guides. Defaults to False. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None. max_depth (int, optional): Maximum depth of nested data structures, or None for no maximum. Defaults to None. expand_all (bool, optional): Expand all containers. Defaults to False. margin (int, optional): Subtrace a margin from width to force containers to expand earlier. Defaults to 0. insert_line (bool, optional): Insert a new line if the output has multiple new lines. Defaults to False. NFr) indent_sizejustifyrLno_wraprNrOrPrQrRrU insert_liner*r+r,)_object highlighterrrrLrrNrOrPrQrRrUrr0c CsX||_|pt|_||_||_||_||_||_||_| |_ | |_ | |_ | |_ | |_ dSN)rr#rrrrLrrNrOrPrQrRrUr)rlrrrrrLrrNrOrPrQrRrUrr6r6r7__init__s zPretty.__init__r(r)r-)rKoptionsr0c cst|j|j|j|j|j|j|j|jd}t j ||j p:|j |j pD|j t |j|jdd}|rf||nt t|jddd}|jr|js|j|jdd}|jrd|krd V|VdS) N max_widthrrOrPrQrRpretty)rrLrstylez.__repr__ returned empty stringz dim italic)rz repr.indentrYrV) pretty_reprrrrUrrOrPrQrRr' from_ansirrLrrrr4rN ascii_onlywith_indent_guidesr)rlrKr pretty_str pretty_textr6r6r7__rich_console__'s>        zPretty.__rich_console__r&c CsLt|j|j|j|j|j|j|jd}|r>tdd| Dnd}t ||S)Nrcss|]}t|VqdSrr!.0r\r6r6r7 Wsz*Pretty.__rich_measure__..r) rrrrrOrPrQrRmax splitlinesr&)rlrKrr text_widthr6r6r7__rich_measure__Js zPretty.__rich_measure__)N) rorprq__doc__rrintrrrrrr6r6r6r7r^sL  $r^)rr0cCsd|jddd|jdfS)Nz defaultdict(z, {})z, {}))default_factoryrr6r6r7_get_braces_for_defaultdict\s  rz array[Any]cCsd|jddd|jdfS)Nzarray(z, [])))typecoderr6r6r7_get_braces_for_arraydsrcCsdS)N)z environ({rz environ({})r6rr6r6r7ircCsdS)N)z Counter({rz Counter()r6rr6r6r7rlrcCsdS)N)zdeque([rzdeque()r6rr6r6r7rmrcCsdSN){}z{}r6rr6r6r7rnrcCsdSrr6rr6r6r7rorcCsdS)N)z frozenset({rz frozenset()r6rr6r6r7rprcCsdSN)[]z[]r6rr6r6r7rqrcCsdSrr6rr6r6r7rrrcCsdS)N)rrzset()r6rr6r6r7rsrcCsdS)N)(r()r6rr6r6r7rtrcCsdS)N)zmappingproxy({rzmappingproxy({})r6rr6r6r7rur_BRACEScCs.t|ts$t|s$t|ds$t|o,t| S)z3Check if an object may be expanded by pretty print. __rich_repr__)rZ _CONTAINERSr hasattrr8r r5r6r6r7 is_expandable{s rc@seZdZUdZdZeed<dZeed<dZeed<dZ eed<dZ eed<dZ e ed <dZ e ed <dZe ed <d Zeeded <dZeed<dZeed<eedddZeee dddZedddZdeee edddZd S) Nodez4A node in a repr tree. May be atomic or a container.rVkey_repr value_repr open_brace close_braceemptyFlastis_tuple is_namedtupleNchildrenz: key_separatorz, separatorr0ccs|jr|jV|jV|jr&|jVn|jdk r|jr|jV|jrt|jstt|jdkrt|jdEdHdVn(|jD] }|EdH|j sz|j Vqz|j Vn|j VdS)zGenerate tokens for this node.Nrr,) rrrrrrrlen iter_tokensrrrr)rlchildr6r6r7rs"     zNode.iter_tokens) start_lengthrOr0cCs0|}|D]}|t|7}||kr dSq dS)a*Check the length fits within a limit. Args: start_length (int): Starting length of the line (indent, prefix, suffix). max_length (int): Maximum length. Returns: bool: True if the node can be rendered within max length, otherwise False. FT)rr")rlrrO total_lengthtokenr6r6r7 check_lengths   zNode.check_lengthcCsd|}|SNrV)joinr)rl repr_textr6r6r7__str__sz Node.__str__Pr)rrrRr0cCsxt|ddg}d}|t|kr`||}|jrV|jsV|s@||sV|||||d<|d7}qddd|D}|S)alRender the node to a pretty repr. Args: max_width (int, optional): Maximum width of the repr. Defaults to 80. indent_size (int, optional): Size of indents. Defaults to 4. expand_all (bool, optional): Expand all levels. Defaults to False. Returns: str: A repr string of the original object. T)nodeis_rootrrrYcss|]}t|VqdSr)strrr6r6r7rszNode.render..)_Liner expandableexpandedrexpandr)rlrrrRlinesline_nor\repr_strr6r6r7renders    z Node.render)rrF)rorprqrrrrsrrrrrrrrrrrrrrrrrrrrr6r6r6r7rs0           rc@seZdZUdZdZeded<dZeed<dZ ee ed<dZ e ed<dZ e ed <dZe ed <dZeed <dZeed <eed ddZeedddZeeddddZe d ddZdS)rzA line in repr output.NparentFrrrVtextsuffix whitespacerrrcCst|jdk o|jjS)z"Check if the line may be expanded.N)rrrrrlr6r6r7rsz_Line.expandable)rOr0cCs:t|jt|jt|j}|jdk s,t|j||S)z4Check this line fits within a given number of cells.N)rrr"rrrrer)rlrOrr6r6r7rsz_Line.check_length)rr0c cs|j}|dk st|j}|js"t|jrJt|j|j|j|dV}nt|j|dV}|jd|}|jozt |jdk}t |jD]4\}}|rdn|j } t|||| |o| d} | Vqt|j ||j |jdVdS)z6Expand this line by adding children on their own line.N)rr rr)rrrrr)rrrr)rrerrrrrrrrrrrrr) rlrrrnew_linechild_whitespace tuple_of_onerrrr\r6r6r7rs8   z _Line.expandcCsH|jr |j|j|jpdS|j|j|jp4d|jSdSr)rrrrrr`rr6r6r7rs"z _Line.__str__)rorprqrrrrsrrrrrrrrrrrpropertyrrrrrrr6r6r6r7rs       !rcCs<zt|dd}Wntk r&YdSXt|to:t|tS)aXChecks if an object is most likely a namedtuple. It is possible to craft an object that passes this check and isn't a namedtuple, but there is only a minuscule chance of this happening unintentionally. Args: obj (Any): The object to test Returns: bool: True if the object is a namedtuple. False otherwise. _fieldsNF)getattrr?rctuple)r/r r6r6r7_is_namedtuples r)rrOrPrQr0c s\ttdfdd tjjd ttttdfdd |d d }|S) a`Traverse object and generate a tree. Args: _object (Any): Object to be traversed. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of string before truncating, or None to disable truncating. Defaults to None. max_depth (int, optional): Maximum depth of data structures, or None for no maximum. Defaults to None. Returns: Node: The root of a tree structure which can be used to render a pretty repr. r.c sdk rFt|ttfrFt|krFt|}|dd|}n@z t|}Wn2tk r}zdt|d}W5d}~XYnX|S)z0Get repr string for an object, but catch errors.N+z )rZbytesrrrkr?)r/ truncatedobj_reprerror)rPr6r7to_reprFs    "ztraverse..to_reprFr)r/rootdepthr0c"st}|krtddSt}dk o0|k}tttttttffddd}ztd}Wnt k r|d}YnXd}|sztd rt s }Wnt k rYnX|dk r|t j d d} t ||} jj} | rg} | j} |r0| rtd | d d}nt| d d}n| rRtd | dd| |dd}nt| dd| |d}t| D]h\}}t|tr|\}}||dd}||_||_d|_| |n||dd}||_| |qpn&t| rd | dn| dg|d}|ntr*|s*|g} | j} tr|rZtjjd d}ntjjdd| |d}tttttttgtffdfdd }t|D]T\}\}}}|rtt||d}n||dd}||_||_d|_| |qntjjdg|d}|nltrtts|str|g} | j} |r~tjjd d}n|tjjdd| |jjdd}tddtDD]>\}}t |j|dd}|j|_||_d|_| |q|ntrt r|jj} |rBt| d d}npg} | j} t| dd| | dd}t!"D]8\}\}}||dd}||_||_d|_| |qx|ntt#rt#D]}t|r|}qqΈ|t$|\}}}|r$t|d|d}nX|j%tj%krJt|d }n2rng} t||| |d}| j} t&}|d}tt'rt("}dk rt)|}t*|D]:\} \}}||dd}||_| |k|_| |qnRt(}!dk rt)|!}!t*|!D],\} }||dd}| |k|_| |qdk r||kr|| td!|d"d nt|g|d#}|nt|d }tt|_+t|_,|S)$zWalk the object depth first.z...)rN) rich_argsr0css|D]x}t|trvt|dkr>|\}}}||kr2q||fVq|t|dkr^|\}}||fVq|t|dkr||dVq|VqdS)Nrr)rZrr)rargkeyrdefaultr6r6r7iter_rich_argsfs        z3traverse.._traverse..iter_rich_args,awehoi234_wdfjwljet234_234wdfoijsdfmmnxpi492Frangularz(...)rr)rrrrrrr)rrrrr)r=r)rrrrc 3stD]j}|jrzt|j}Wn0tk rN}z|j|dfVW5d}~XYqX|j|t|jrf|jndfVqdS)z$Iterate over attr fields and values.N)rkrnamer?callable)attrrJr attr_fieldsr/r6r7 iter_attrss z/traverse.._traverse..iter_attrs)rrrrrcss|]}|jr|VqdSr)rk)rfieldr6r6r7rsz.traverse.._traverse..)rrrr)rrz... +T)rrr)-idrr4rrrrrrr?r rrlist __class__roappendrrZrrrrr8r9rrr r@r rrrH_asdictitemsrrr:r_MAPPING_CONTAINERSiterr enumeraterr)"r/rrobj_idobj_typereached_max_depthrfake_attributesrich_repr_resultrargs class_namerrrrrrr child_noderrrJ repr_callablercontainer_typerrr num_itemslast_item_index iter_itemsindex iter_values) _traverserQrO pop_visited push_visitedr visited_idsrr7rZs| $                                 ztraverse.._traverseT)r)Fr)rrsetaddremoverrrr)rrOrPrQrr6)rrQrOrPrrrrr7traverse1s&| r"rrr)rrrrOrPrQrRr0c Cs4t|tr|}nt||||d}|j|||d}|S)aPrettify repr string by expanding on to new lines to fit within a given width. Args: _object (Any): Object to repr. max_width (int, optional): Desired maximum width of repr string. Defaults to 80. indent_size (int, optional): Number of spaces to indent. Defaults to 4. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of string before truncating, or None to disable truncating. Defaults to None. max_depth (int, optional): Maximum depth of nested data structure, or None for no depth. Defaults to None. expand_all (bool, optional): Expand all containers regardless of available width. Defaults to False. Returns: str: A possibly multi-line representation of the object. )rOrPrQ)rrrR)rZrr"r) rrrrOrPrQrRrrr6r6r7rYs rT)rKrNrOrPrQrR)rrKrNrOrPrQrRr0c Cs6|dkrtn|}|jt||||||dddddS)aA convenience function for pretty printing. Args: _object (Any): Object to pretty print. console (Console, optional): Console instance, or None to use default. Defaults to None. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of strings before truncating, or None to disable. Defaults to None. max_depth (int, optional): Maximum depth for nested data structures, or None for unlimited depth. Defaults to None. indent_guides (bool, optional): Enable indentation guides. Defaults to True. expand_all (bool, optional): Expand all containers. Defaults to False. NrI)rOrPrQrNrRrLT) soft_wrap)rr]r^)rrKrNrOrPrQrR_consoler6r6r7rjs rj__main__c@seZdZedddZdS) BrokenReprrcCs dddS)Nrrzthis will failr6rr6r6r7r:szBrokenRepr.__repr__Nrorprqrr:r6r6r6r7r&sr&) NamedTuplec@s:eZdZUeed<eed<eed<eed<eeed<dS)StockKeepingUnitr descriptionZpricecategoryZreviewsN)rorprqrrsfloatrr6r6r6r7r)s r)fooz Hello World!gZd;Y@gʡE3t@gcA)rrrrrrZcrumbleappleZrhubarbbutterZsugarZflourZorangepearZkumquatAXduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurian)FTNzSparkling British Spring WaterzCarbonated spring waterg?Zwaterz its amazing!z its terrible!)r.barrcounterZatomic namedtupleZBroken)r])rNrPc@seZdZedddZdS)ThingrcCsdS)NzHello World!r6rr6r6r7r:szThing.__repr__Nr'r6r6r6r7r9sr9)NrIFFNNNF)NrIFFNNNF)NNN)orf collectionsr=rBosrxrrrrrrrr r r itertoolsr typesr typingrrrrrrrrrrrrZpip._vendor.rich.reprrrr2rr1 ImportErrorrVr_loopr_pickrabcr cellsr"rr#jupyterr$r%measurer&rr'rKr(r)r*r+r,r-rrr8r9objectr@r7rArHrrrar4rZrr^rr_Environdict frozensetrrrrrskeysrr rrrrr"rrjror&r(r)ddatarrur]r9r6r6r6r7s    8             /  Ph"(  TC - + %     !