o
    ãË·e´  ã                   @   s`   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dZG dd	„ d	eƒZd
d„ ZdS )zXRI resolution.
é    )Ú	urlencode)Úfetchers)Úetxrd)ÚtoURINormal)ÚiterServiceszhttp://proxy.xri.net/c                   @   s.   e Zd ZdZefdd„Zd	dd„Zdd„ ZdS )
ÚProxyResolverz5Python interface to a remote XRI proxy resolver.
    c                 C   s
   || _ d S ©N)Ú	proxy_url)Úselfr	   © r   úJ/var/www/ideatree/venv/lib/python3.10/site-packages/openid/yadis/xrires.pyÚ__init__   s   
zProxyResolver.__init__Nc                 C   sN   t |ƒdd… }| j| }ddi}|r||d< n|d  d7  < t||ƒ}|S )aQ  Build a URL to query the proxy resolver.

        @param xri: An XRI to resolve.
        @type xri: unicode

        @param service_type: The service type to resolve, if you desire
            service endpoint selection.  A service type is a URI.
        @type service_type: str

        @returns: a URL
        @returntype: str
        é   NÚ_xrd_rzapplication/xrds+xmlÚ_xrd_tz
;sep=false)r   r	   Ú_appendArgs)r
   ÚxriÚservice_typeÚqxriÚhxriÚargsÚqueryr   r   r   ÚqueryURL   s   
û

zProxyResolver.queryURLc           
      C   sj   g }d}|D ]*}|   ||¡}t |¡}|jdvrqt |j¡}t ||¡}tt	|ƒƒ}	| 
|	¡ q||fS )aÏ  Resolve some services for an XRI.

        Note: I don't implement any service endpoint selection beyond what
        the resolver I'm querying does, so the Services I return may well
        include Services that were not of the types you asked for.

        May raise fetchers.HTTPFetchingError or L{etxrd.XRDSError} if
        the fetching or parsing don't go so well.

        @param xri: An XRI to resolve.
        @type xri: unicode

        @param service_types: A list of services types to query for.  Service
            types are URIs.
        @type service_types: list of str

        @returns: tuple of (CanonicalID, Service elements)
        @returntype: (unicode, list of C{ElementTree.Element}s)
        N)éÈ   éÎ   )r   r   ÚfetchÚstatusr   Ú	parseXRDSÚbodyÚgetCanonicalIDÚlistr   Úextend)
r
   r   Úservice_typesÚservicesÚcanonicalIDr   ÚurlÚresponseÚetÚsome_servicesr   r   r   r   6   s   

zProxyResolver.queryr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚDEFAULT_PROXYr   r   r   r   r   r   r   r      s
    
!r   c                 C   sX   t |dƒrt| ¡ ƒ}| ¡  t|ƒdkr| S d|  d¡v r!d}nd}d| |t|ƒf S )z,Append some arguments to an HTTP query.
    Úitemsr   ú?ú&z%s%s%s)Úhasattrr    r.   ÚsortÚlenÚrstripr   )r%   r   Úsepr   r   r   r   d   s   
	r   N)r,   Úurllib.parser   Úopenidr   Úopenid.yadisr   Úopenid.yadis.xrir   Úopenid.yadis.servicesr   r-   Úobjectr   r   r   r   r   r   Ú<module>   s   V