Ë
    �yfL1  ã                   ó„   — d dl Zd dlZd dlZd dlZd dlZd dlZd dlZ	ddl
mZmZmZmZmZmZmZ edddeddœd„Zd„ Zd
d	„Zy)é    Né   )ÚIDENTITYÚ
NO_DEFAULTÚLazyListÚdeprecation_warningÚis_iterable_likeÚtry_callÚvariadicTF)ÚdefaultÚexpected_typeÚget_allÚ	casesenseÚis_user_inputÚtraverse_stringc          	      ó,  ‡‡‡‡‡‡‡‡‡‡‡— |t         urt        d«       d„ Št        ‰t        «      rˆfd„Šnˆfd„Šˆˆˆˆˆˆfd„Šd„ Šˆˆˆˆfd„Šˆˆˆfd„Št	        |d	«      D ]"  \  }}	 ‰| |	|t        |«      k(  d
«      }
|
€Œ |
c S  ‰t         u rdS ‰S )a4  
    Safely traverse nested `dict`s and `Iterable`s

    >>> obj = [{}, {"key": "value"}]
    >>> traverse_obj(obj, (1, "key"))
    'value'

    Each of the provided `paths` is tested and the first producing a valid result will be returned.
    The next path will also be tested if the path branched but no results could be found.
    Supported values for traversal are `Mapping`, `Iterable`, `re.Match`,
    `xml.etree.ElementTree` (xpath) and `http.cookies.Morsel`.
    Unhelpful values (`{}`, `None`) are treated as the absence of a value and discarded.

    The paths will be wrapped in `variadic`, so that `'key'` is conveniently the same as `('key', )`.

    The keys in the path can be one of:
        - `None`:           Return the current object.
        - `set`:            Requires the only item in the set to be a type or function,
                            like `{type}`/`{type, type, ...}/`{func}`. If a `type`, return only
                            values of this type. If a function, returns `func(obj)`.
        - `str`/`int`:      Return `obj[key]`. For `re.Match`, return `obj.group(key)`.
        - `slice`:          Branch out and return all values in `obj[key]`.
        - `Ellipsis`:       Branch out and return a list of all values.
        - `tuple`/`list`:   Branch out and return a list of all matching values.
                            Read as: `[traverse_obj(obj, branch) for branch in branches]`.
        - `function`:       Branch out and return values filtered by the function.
                            Read as: `[value for key, value in obj if function(key, value)]`.
                            For `Iterable`s, `key` is the index of the value.
                            For `re.Match`es, `key` is the group number (0 = full match)
                            as well as additionally any group names, if given.
        - `dict`:           Transform the current object and return a matching dict.
                            Read as: `{key: traverse_obj(obj, path) for key, path in dct.items()}`.
        - `any`-builtin:    Take the first matching object and return it, resetting branching.
        - `all`-builtin:    Take all matching objects and return them as a list, resetting branching.

        `tuple`, `list`, and `dict` all support nested paths and branches.

    @params paths           Paths which to traverse by.
    @param default          Value to return if the paths do not match.
                            If the last key in the path is a `dict`, it will apply to each value inside
                            the dict instead, depth first. Try to avoid if using nested `dict` keys.
    @param expected_type    If a `type`, only accept final values of this type.
                            If any other callable, try to call the function on each result.
                            If the last key in the path is a `dict`, it will apply to each value inside
                            the dict instead, recursively. This does respect branching paths.
    @param get_all          If `False`, return the first matching result, otherwise all matching ones.
    @param casesense        If `False`, consider string dictionary keys as case insensitive.

    `traverse_string` is only meant to be used by YoutubeDL.prepare_outtmpl and is not part of the API

    @param traverse_string  Whether to traverse into objects as strings.
                            If `True`, any non-compatible object will first be
                            converted into a string and then traversed into.
                            The return value of that path will be a string instead,
                            not respecting any further branching.


    @returns                The result of the object traversal.
                            If successful, `get_all=True`, and the path branches at least once,
                            then a list of results is returned instead.
                            If no `default` is given and the last path branches, a `list` of results
                            is always returned. If a path ends on a `dict` that result will always be a `dict`.
    z=The is_user_input parameter is deprecated and no longer worksc                 óF   — t        | t        «      r| j                  «       S | S ©N)Ú
isinstanceÚstrÚcasefold)Úks    ú8/usr/lib/python3/dist-packages/yt_dlp/utils/traversal.pyú<lambda>ztraverse_obj.<locals>.<lambda>Y   s   € ¬°A´sÔ);˜Ÿ™›€ À€ ó    c                 ó$   •— t        | ‰«      r| S d S r   )r   ©Úvalr   s    €r   r   ztraverse_obj.<locals>.<lambda>\   s   ø€ ¤z°#°}Ô'E € È4€ r   c                 ó0   •— t        ‰xs t        | f¬«      S )N©Úargs)r	   r   r   s    €r   r   ztraverse_obj.<locals>.<lambda>^   s   ø€ ¤¨Ò)B¼(È#ÈÔ P€ r   c                 ó,  •‡ ‡‡‡— d}d }‰€(‰r&‰ du st        ‰ «      st        ‰ t        «      �r´d}d}�n®‰ €‰}�n¨t        ‰ t        «      rpt	        t        ‰ «      «      }t        ‰ «      dkD  st        |t        «      r.t        d„ ‰ D «       «      sJ ‚t        ‰t        ‰ «      «      �r<‰}�n8t        |‰f¬«      }�n(t        ‰ t        t        f«      r.d}t        j                  j                  ˆˆˆfd„‰ D «       «      }�nä‰ du rüd}t        ‰t        j                   j"                  «      r"t%        ‰‰j&                  ‰j(                  ¬	«      Št        ‰t*        j,                  j.                  «      r‰j1                  «       }�nbt3        ‰«      s.t        ‰t4        j6                  j8                  j:                  «      r‰}�n%t        ‰t<        j>                  «      r‰jA                  «       }�nù‰rd}tC        ‰«      }�nèd}�nät        ‰ «      �rtd}t        ‰t        j                   j"                  «      r"t%        ‰‰j&                  ‰j(                  ¬	«      Št        ‰t*        j,                  j.                  «      r‰jE                  «       }nÖt3        ‰«      s.t        ‰t4        j6                  j8                  j:                  «      rtG        ‰«      }n‘t        ‰t<        j>                  «      r\t        j                  tG        ‰jI                  «       g‰jA                  «       ¢­«      ‰jK                  «       jE                  «       «      }n‰rd}tG        tC        ‰«      «      }nd}ˆ fd
„|D «       }|�swdjM                  |«      }�ndt        ‰ t$        «      rEˆˆˆfd„‰ jE                  «       D «       }|D ��ci c]  \  }}|€‰tN        ur||�|n‰“Œ c}}xs d }�nt        ‰t*        j,                  j.                  «      ržt        ‰t        j                   j"                  «      r"t%        ‰‰j&                  ‰j(                  ¬	«      Š‰st        ‰jP                  ‰ f¬«      rt        ‰jR                  ‰ f¬«      n#t	        ˆˆ fd„‰jE                  «       D «       d «      }�nMt        ‰t<        j>                  «      rŒt        ‰ tT        «      s‰r5tW        jX                  tZ        «      5  ‰jI                  ‰ «      }d d d «       �nìt        ‰ tB        «      �rÛt	        ˆˆ fd„‰jK                  «       jE                  «       D «       d «      }�n§t        ‰ tT        t        f«      rµt3        ‰t*        j,                  j\                  t4        j6                  j8                  j:                  f«      r9t        ‰ t        «      }tW        jX                  tZ        «      5  ‰‰    }d d d «       �n‰�rtW        jX                  tZ        «      5  tC        ‰«      ‰    }d d d «       nÜt        ‰t4        j6                  j8                  j:                  «      r®t        ‰ tB        «      rž‰ j_                  d«      \  }	}
Š‰ja                  d«      s‰jc                  d«      s‰ }	d Š|	ja                  d«      rd|	› �}	n|	r|	ja                  d«      sd|	› �}	ˆfd„}|	r%t        te        |‰jg                  |	«      «      «      }n |‰«      }||r|fS |ffS c c}}w # 1 sw Y   ŒxY w# 1 sw Y   Œ%xY w# 1 sw Y   Œ1xY w)NF.T© r   c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr   )r   Útype©Ú.0Úitems     r   ú	<genexpr>z2traverse_obj.<locals>.apply_key.<locals>.<genexpr>o   s   è ø€ ÒB°dœ: d¬D×1ÑBùs   ‚r   c              3   ó8   •K  — | ]  } ‰‰|‰«      d    –— Œ y­w)r   Nr"   )r&   ÚbranchÚ
apply_pathÚis_lastÚobjs     €€€r   r(   z2traverse_obj.<locals>.apply_key.<locals>.<genexpr>w   s&   øè ø€ ò 3GØ8>‘
˜3 ¨Ó0°Õ3ñ3Gùs   ƒ)ÚkeyÚvaluec              3   óH   •K  — | ]  \  }}t        ‰||f¬ «      sŒ|–— Œ y­w)r   N)r	   )r&   r   Úvr.   s      €r   r(   z2traverse_obj.<locals>.apply_key.<locals>.<genexpr>œ   s"   øè ø€ ÒK™D˜A˜q´¸ÀAÀqÀ6Ö0J”aÑKùs   ƒ"›"Ú c              3   ó>   •K  — | ]  \  }}| ‰‰|d ‰«      f–— Œ y­w)FNr"   )r&   r   r1   Ú_traverse_objr,   r-   s      €€€r   r(   z2traverse_obj.<locals>.apply_key.<locals>.<genexpr>¡   s%   øè ø€ Ò[ÁtÀqÈ!˜™M¨#¨q°%¸ÓAÔBÑ[ùs   ƒc              3   ó@   •K  — | ]  \  }} ‰|«      ‰k(  sŒ|–— Œ y ­wr   r"   ©r&   r   r1   r   r.   s      €€r   r(   z2traverse_obj.<locals>.apply_key.<locals>.<genexpr>«   s    øè ø€ ÒL¡$ ! Q¹À!»ÈÓ9KœAÑLùó   ƒ—c              3   ó@   •K  — | ]  \  }} ‰|«      ‰k(  sŒ|–— Œ y ­wr   r"   r6   s      €€r   r(   z2traverse_obj.<locals>.apply_key.<locals>.<genexpr>³   s"   øè ø€ Ò[¡T Q¨ÉÐQRËÐWZÓHZœqÑ[ùr7   ú/ú@z()ú.z./c                 óØ   •— ‰€| S ‰dk(  r| j                   S ‰j                  d«      r%t        | j                   j                  ‰dd  f¬«      S ‰dk(  r| j                  S t        d‰›�«      ‚)Nr:   r   r   ztext()z#apply_specials is missing case for )ÚattribÚ
startswithr	   ÚgetÚtextÚSyntaxError)ÚelementÚspecials    €r   Úapply_specialsz7traverse_obj.<locals>.apply_key.<locals>.apply_specialsÊ   sp   ø€ Ø�?Ø"�NØ˜c’>Ø"Ÿ>™>Ð)Ø×%Ñ% cÔ*Ü# G§N¡N×$6Ñ$6¸gÀaÀb¸k¸^ÔLÐLØ˜hÒ&Ø"Ÿ<™<Ð'Ü!Ð$GÈÀ{Ð"SÓTÐTr   )4Úcallabler   ÚsliceÚsetÚnextÚiterÚlenr$   ÚallÚtupler	   ÚlistÚ	itertoolsÚchainÚfrom_iterableÚhttpÚcookiesÚMorselÚdictr.   r/   ÚcollectionsÚabcÚMappingÚvaluesr   ÚxmlÚetreeÚElementTreeÚElementÚreÚMatchÚgroupsr   ÚitemsÚ	enumerateÚgroupÚ	groupdictÚjoinr   Ú__contains__r?   ÚintÚ
contextlibÚsuppressÚ
IndexErrorÚSequenceÚ
rpartitionr>   ÚendswithÚmapÚiterfind)r.   r-   r,   Ú	branchingÚresultr'   Úiter_objr   r1   ÚxpathÚ_rD   rC   r4   r+   r   r   r   r   s   ```         @€€€€€€r   Ú	apply_keyztraverse_obj.<locals>.apply_key`   sh  ü€ Øˆ	Øˆàˆ;™?Ø�c‰zœX cœ]¬j¸¼eÕ.DØ �	Ø’àˆ[ØŠFä˜œSÔ!Üœ˜S›	“?ˆDÜ�3‹x˜!Š|œz¨$´Ô5ÜÑB¸cÔBÔBÐBÐBÜ˜c¤5¨£:Õ.Ø ’Fä! $¨c¨VÔ4’ä˜œd¤E˜]Ô+ØˆIÜ—_‘_×2Ñ2õ 3GØBEô3Gó GŠFð �C‰ZØˆIÜ˜#œtŸ|™|×2Ñ2Ô3Ü˜3 C§G¡G°3·9±9Ô=�Ü˜#œ{Ÿ™×6Ñ6Ô7ØŸ™›’Ü! #Ô&¬*°S¼#¿)¹)×:OÑ:O×:WÑ:WÔ*XØ’Ü˜C¤§¡Ô*ØŸ™›’Ù Ø!�	Ü˜S›’à’ä�c�]ØˆIÜ˜#œtŸ|™|×2Ñ2Ô3Ü˜3 C§G¡G°3·9±9Ô=�Ü˜#œ{Ÿ™×6Ñ6Ô7ØŸ9™9›;‘Ü! #Ô&¬*°S¼#¿)¹)×:OÑ:O×:WÑ:WÔ*XÜ$ S›>‘Ü˜C¤§¡Ô*Ü$Ÿ?™?Ü˜sŸy™y›{Ð:¨S¯Z©Z«\Ñ:Ó;Ø—M‘M“O×)Ñ)Ó+ó-‘ñ !Ø!�	Ü$¤S¨£XÓ.‘à�ãK HÔKˆFÚØŸ™ ›’ä˜œTÔ"Ý[ÈsÏyÉyË{Ô[ˆHà?G÷Ù7;°q¸!Ø�= G´:Ñ$=ð ˜˜‘1¨7Ñ2óò ð ò ô
 ˜œ[Ÿ_™_×4Ñ4Ô5Ü˜#œtŸ|™|×2Ñ2Ô3Ü˜3 C§G¡G°3·9±9Ô=�Ù8AÄXÈc×N^ÑN^ÐfiÐekÕEl”h˜sŸw™w¨c¨VÕ4ÜÔL¨#¯)©)«+ÔLÈdÓSò ô ˜œRŸX™XÔ&Ü˜#œsÔ#¡yÜ×(Ñ(¬Ó4ñ ,Ø ŸY™Y s›^�F÷,ñ ,ô ˜C¤Õ%ÜÔ[¨S¯]©]«_×-BÑ-BÓ-DÔ[Ð]aÓb’ä˜œc¤5˜\Ô*Ü ¤k§o¡o×&>Ñ&>ÄÇ	Á	×@UÑ@U×@]Ñ@]Ð%^Ô_Ü& s¬EÓ2�	Ü×(Ñ(¬Ó4ñ &Ø  ™X�F÷&ñ &â Ü×(Ñ(¬Ó4ñ +Ü  ›X c™]�F÷+ð +ô ˜œSŸY™Y×2Ñ2×:Ñ:Ô;Ä
È3ÔPSÔ@TØ #§¡¨sÓ 3ÑˆE�1�gØ×%Ñ% cÔ*°7×3CÑ3CÀDÔ3IØ�Ø�ð ×Ñ Ô$Ø˜E˜7˜‘Ù˜u×/Ñ/°Ô5Ø˜U˜G˜�ô	Uñ Üœc .°#·,±,¸uÓ2EÓFÓG‘á'¨Ó,�à¡I˜&Ð<Ð<°F°9Ð<Ð<ùóq÷,ð ,ú÷&ð &ú÷+ð +ús*   Î.[,Ó[2×[>×.\
Û2[;Û>\Ü
\c              3   ó~   K  — t        | «      }t        |t        «      }|t        u ry |D ]
  }d|f–— |}Œ d|f–— y ­w)NFT)rI   rH   r   )ÚiterableÚiteratorÚprevr'   s       r   Ú	lazy_lastztraverse_obj.<locals>.lazy_lastÜ   sP   è ø€ Ü˜“>ˆÜ�HœjÓ)ˆØ”:ÑØàò 	ˆDØ˜�+ÒØ‰Dð	ð �DˆjÓùs   ‚;=c           	      ó˜  •— | f}d}d } ‰t        |t        t        t        t        f«      «      D ]Þ  \  }}‰s t        |t        «      r|j                  «       }|t        t        fv r.d}d„ |D «       }|t        u rt        |d «      f}nt        |«      f}Œdt        |«      r%t        j                  |«      j                  d d «       g }|D ]%  }	 ‰||	|«      \  }
}||
z  }|j                  |«       Œ' t         j"                  j%                  |«      }Œà |r't        |t        t        t&        f«      st)        ‰|«      }||t        |t        «      fS )NFc              3   ó.   K  — | ]  }|d i fvsŒ
|–— Œ y ­wr   r"   )r&   r-   s     r   r(   z3traverse_obj.<locals>.apply_path.<locals>.<genexpr>ó   s   è ø€ Ò N¨¸ÀDÈ"À:Ò8M¤Ñ Nùó   ‚Ž)r
   r   ÚbytesrT   rG   r   r   ÚanyrK   rH   rM   rE   ÚinspectÚ	signatureÚbindÚappendrN   rO   rP   rL   rm   )Ú	start_objÚpathÚ	test_typeÚobjsÚhas_branchedr.   ÚlastÚfiltered_objsÚnew_objsr-   ro   Úresultsrt   r   ry   Ú	type_tests               €€€€r   r+   z traverse_obj.<locals>.apply_pathè   s>  ø€ Øˆ|ˆØˆàˆÙ"¤8¨D´3¼¼tÄSÐ2IÓ#JÓKò 	;‰IˆD�#Ù¤¨C´Ô!5Ø—l‘l“n�à”sœC�jÑ Ø$�Ù N°Ô N�Øœ#‘:Ü  °Ó5Ð7‘Dä  Ó/Ð1�DØä% cœ]ä×!Ñ! #Ó&×+Ñ+¨D°$Ô7àˆHØò )�Ù%.¨s°C¸Ó%>Ñ"�	˜7Ø 	Ñ)�Ø—‘ Õ(ð)ô
 —?‘?×0Ñ0°Ó:‰Dð/	;ñ2 œZ¨¬d´D¼%Ð-@ÔAÜ�y $Ó'ˆDà�\¤:¨c´4Ó#8Ð8Ð8r   c                 ó¬   •—  ‰| ||«      \  }}}t        d„ |D «       «      }‰	r#|r!|r|j                  «       S |r‰t        u rg S ‰S y |r|d   S |r|ri S d S )Nc              3   ó.   K  — | ]  }|d i fvsŒ
|–— Œ y ­wr   r"   r%   s     r   r(   z6traverse_obj.<locals>._traverse_obj.<locals>.<genexpr>  s   è ø€ ÒN D°tÀDÈ"À:Ò7Mœ4ÑNùr|   r   )r   Úexhaustr   )
r-   r„   Úallow_emptyr…   r‹   r‡   Úis_dictr+   r   r   s
          €€€r   r4   z#traverse_obj.<locals>._traverse_obj  so   ø€ Ù)3°C¸¸yÓ)IÑ&ˆ�˜wÜÑN¨GÔNÓNˆÙ‘|ÙØ—‘Ó(Ð(ÙØ$¬
Ñ2�rÐ?¸Ð?Øá$ˆw�q‰zÐQ±Á¨"ÐQÈTÐQr   r   TN)r   r   r   r$   ra   rJ   )r-   r   r   r   r   r   r   ÚpathsÚindexr„   rp   r4   rt   r+   r   ry   rŒ   s    ```` `    @@@@@@r   Útraverse_objr”      s£   ÿú€ ðD œJÑ&ÜÐ[Ô\áB€Hä�-¤Ô&ÛO‰	ãPˆ	÷z=ñ z=òx
÷!9öF
Rô ! ¨Ó*ò ‰ˆˆtÙ˜s D¨%´3°u³:Ñ*=¸tÓDˆØÑØŠMðð
 œjÑ(ˆ4Ð5¨gÐ5r   c                 ó6   — t        | gd„ |D «       ¢­i |¤ddi¤ŽS )Nc              3   ó:   K  — | ]  }d gt        |«      ¢­–— Œ y­w).N)r
   )r&   Úkeyss     r   r(   zget_first.<locals>.<genexpr>   s   è ø€ ÒH¸$ Ð5¤h¨t£nÕ5ÑHùs   ‚r   F)r”   )r-   r’   Úkwargss      r   Ú	get_firstr™     s#   € Ü˜ÐbÑHÀ%ÔHÒbÈFÑbÐ\aÒbÐbr   c                 ód   — t        | j                  t        |«      «      D ]  }|€Œ|s|rŒ|c S  |S r   )rm   r?   r
   )ÚdÚkey_or_keysr   Úskip_false_valuesr   s        r   Údict_getrž   #  s7   € Ü�1—5‘5œ( ;Ó/Ó0ò ˆØ‰?¡Ò+<ØŠJðð €Nr   )NT)Úcollections.abcrU   rg   Úhttp.cookiesrQ   r   rN   r]   Úxml.etree.ElementTreerY   Ú_utilsr   r   r   r   r   r	   r
   r”   r™   rž   r"   r   r   ú<module>r£      sK   ðÛ Û Û Û Û Û 	Û ÷÷ ñ ð (°tÀTØ jÀ%ôH6òVcôr   