Ë
    hKêj7  ã                   ó�   — d dl Z d dlZd dlmZ 	  G d„ de«      Z G d„ de«      Z G d„ de«      Z G d	„ d
e«      Z	 G d„ de«      Z
y)é    N)Úwrapsc                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚRuleaR  
    A rule is a mapping between a pattern (typically a URI) and a callable
    (typically a function).
    The pattern is a regex string pattern and must match entirely a string
    (typically a URI) for the rule to be considered, i.e. for the endpoint to
    be resolved and eventually invoked for a given string (typically a URI).
    c                 ó0  — |j                  d«      j                  d«      | _        t        j                  d| j                  z   dz   «      j
                  | _        t        |«      sJ ‚t        j                  |«      r |«       }t        |«      sJ ‚|| _
        y )Nú^ú$)ÚlstripÚrstripÚpatternÚreÚcompileÚmatchÚpattern_matchÚcallableÚinspectÚisclassÚendpoint)Úselfr   r   Úobjs       ú]/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/packageurl/contrib/route.pyÚ__init__zRule.__init__@   sz   € ð —~‘~ cÓ*×1Ñ1°#Ó6ˆŒÜŸZ™Z¨¨d¯l©lÑ(:¸SÑ(@ÓA×GÑGˆÔô ˜Ô!Ð!Ð!ä�?‰?˜8Ô$Ù“*ˆCÜ˜C”=Ð �=à ˆ�ó    c                 ó~   — d| j                   › d| j                  j                  › d| j                  j                  › d�S )Nz	Rule(r"""z""", ú.ú))r   r   Ú
__module__Ú__name__©r   s    r   Ú__repr__zRule.__repr__O   s8   € Ø˜4Ÿ<™<˜.¨¨d¯m©m×.FÑ.FÐ-GÀqÈÏÉ×I_ÑI_ÐH`Ð`aÐbÐbr   c                 ó$   — | j                  |«      S )zP
        Match a string with the rule pattern, return True is matching.
        )r   )r   Ústrings     r   r   z
Rule.matchR   s   € ð ×!Ñ! &Ó)Ð)r   N)r   r   Ú__qualname__Ú__doc__r   r   r   © r   r   r   r   7   s   „ ñò!òcó*r   r   c                   ó   — e Zd ZdZy)ÚRouteAlreadyDefinedzF
    Raised when this route Rule already exists in the route map.
    N©r   r   r"   r#   r$   r   r   r&   r&   Y   ó   „ òr   r&   c                   ó   — e Zd ZdZy)ÚNoRouteAvailablez3
    Raised when there are no route available.
    Nr'   r$   r   r   r*   r*   _   r(   r   r*   c                   ó   — e Zd ZdZy)ÚMultipleRoutesDefinedz=
    Raised when there are more than one route possible.
    Nr'   r$   r   r   r,   r,   e   r(   r   r,   c                   óH   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zy)ÚRouteraî  
    A router is:
    - a container for a route map, consisting of several rules, stored in an
     ordered dictionary keyed by pattern text
    - a way to process a route, i.e. given a string (typically a URI), find the
     correct rule and invoke its callable endpoint
    - and a convenience decorator for routed callables (either a function or
     something with a __call__ method)

    Multiple routers can co-exist as needed, such as a router to collect,
    another to fetch, etc.
    Nc                 ó8   — |xs
 t        «       | _        d| _        y)zG
        'route_map' is an ordered mapping of pattern -> Rule.
        N)ÚdictÚ	route_mapÚ_is_routable)r   r1   s     r   r   zRouter.__init__y   s   € ð #Ò,¤d£fˆŒà ˆÕr   c                 ó,   — t        | j                  «      S ©N)Úreprr1   r   s    r   r   zRouter.__repr__�   s   € Ü�D—N‘NÓ#Ð#r   c                 óH   — t        | j                  j                  «       «      S r4   )Úiterr1   Úitemsr   s    r   Ú__iter__zRouter.__iter__„   s   € Ü�D—N‘N×(Ñ(Ó*Ó+Ð+r   c                 ó6   — | j                   j                  «       S r4   )r1   Úkeysr   s    r   r;   zRouter.keys‡   s   € Ø�~‰~×"Ñ"Ó$Ð$r   c                 óh   — || j                   v rt        |«      ‚t        ||«      | j                   |<   y)zŠ
        Append a new pattern and endpoint Rule at the end of the map.
        Use this as an alternative to the route decorator.
        N)r1   r&   r   )r   r   r   s      r   ÚappendzRouter.appendŠ   s0   € ð
 �d—n‘nÑ$Ü% gÓ.Ð.Ü"& w°Ó"9ˆ�‰�wÒr   c                 ó   ‡ ‡— ˆˆ fd„}|S )a  
        Decorator to make a callable 'endpoint' routed to one or more patterns.

        Example:
        >>> my_router = Router()
        >>> @my_router.route('http://nexb.com', 'http://deja.com')
        ... def somefunc(uri):
        ...    pass
        c                 óh   •— ‰sJ ‚‰D ]  }‰j                  || «       Œ t        | «      ˆfd„«       }|S )Nc                  ó(   •—  ‰j                   | i |¤ŽS r4   )Úprocess)ÚargsÚkwargsr   s     €r   Ú	decoratedz2Router.route.<locals>.decorator.<locals>.decorated£   s   ø€ à#�t—|‘| TÐ4¨VÑ4Ð4r   )r=   r   )r   ÚpatrD   Úpatternsr   s      €€r   Ú	decoratorzRouter.route.<locals>.decoratorž   sG   ø€ ÙˆO�8Øò +�Ø—‘˜C Õ*ð+ô �8‹_ó5ó ð5ð Ðr   r$   )r   rF   rG   s   `` r   ÚroutezRouter.route“   s   ù€ õ		ð Ðr   c                 ót   — | j                  |«      }t        j                  |«      r |«       } ||g|¢­i |¤ŽS )zí
        Given a string (typically a URI), resolve this string to an endpoint
        by searching available rules then execute the endpoint callable for
        that string passing down all arguments to the endpoint invocation.
        )Úresolver   r   )r   r!   rB   rC   r   s        r   rA   zRouter.process«   s<   € ð —<‘< Ó'ˆÜ�?‰?˜8Ô$ñ  “zˆHá˜Ð0 Ò0¨Ñ0Ð0r   c                 óR  — | j                   j                  «       D �cg c]  }|j                  |«      sŒ|‘Œ }}|st        |«      ‚t	        |«      dkD  r;t        |D �cg c]  }|j                  ‘Œ c}«      }dt        «       z  }t        |«      ‚|d   j                  S c c}w c c}w )a}  
        Resolve a string: given a string (typically a URI) resolve and
        return the best endpoint function for that string.

        Ambiguous resolution is not allowed in order to keep things in
        check when there are hundreds rules: if multiple routes are
        possible for a string (typically a URI), a MultipleRoutesDefined
        TypeError is raised.
        é   z-%(string)r matches multiple patterns %(pats)rr   )
r1   Úvaluesr   r*   Úlenr5   r   Úlocalsr,   r   )r   r!   ÚrÚ
candidatesÚpatsÚmsgs         r   rJ   zRouter.resolve¹   s•   € ð "&§¡×!6Ñ!6Ó!8ÖL˜A¸A¿G¹GÀF½O’aÐLˆ
ÐLáÜ" 6Ó*Ð*äˆz‹?˜QÒô ¨JÖ7 q˜Ÿ›Ò7Ó8ˆDØAÄFÃHÑLˆCÜ'¨Ó,Ð,à˜!‰}×%Ñ%Ð%ùò Mùò 8s   �B´BÁB$c                 ó
  — |sy| j                   s[ddj                  d„ | j                  D «       «      z   dz   }t        j                  |t        j
                  «      j                  | _         t        | j                  |«      «      S )z{
        Return True if `string` is routable by this router, e.g. if it
        matches any of the route patterns.
        Nz^(ú|c              3   ó    K  — | ]  }|–— Œ y ­wr4   r$   )Ú.0rE   s     r   ú	<genexpr>z%Router.is_routable.<locals>.<genexpr>Ý   s   è ø€ Ò'F°¬Ñ'Fùs   ‚z)$)r2   Újoinr1   r   r   ÚUNICODEr   Úbool)r   r!   Ú	routabless      r   Úis_routablezRouter.is_routableÓ   sh   € ñ
 Øà× Ò à˜sŸx™xÑ'F°t·~±~Ô'FÓFÑFÈÑMˆIÜ "§
¡
¨9´b·j±jÓ A× GÑ GˆDÔä�D×%Ñ% fÓ-Ó.Ð.r   r4   )r   r   r"   r#   r   r   r9   r;   r=   rH   rA   rJ   r]   r$   r   r   r.   r.   k   s4   „ ñó!ò$ò,ò%ò:òò01ò&ó4/r   r.   )r   r   Ú	functoolsr   Úobjectr   Ú	TypeErrorr&   r*   r,   r.   r$   r   r   ú<module>ra      sT   ðó6 Û 	Ý ðô0*ˆ6ô *ôD˜)ô ô�yô ô˜Iô ôu/ˆVõ u/r   