a
    Šxd´  ã                   @   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
   úK/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/yadis/xrires.pyÚ__init__   s    zProxyResolver.__init__Nc                 C   sN   t |ƒdd… }| j| }ddi}|r0||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
        é   NZ_xrd_rzapplication/xrds+xmlZ_xrd_tz
;sep=false)r   r   Ú_appendArgs)r	   ÚxriÚservice_typeZqxriZhxriÚargsÚqueryr
   r
   r   ÚqueryURL   s    
û

zProxyResolver.queryURLc           
      C   sj   g }d}|D ]T}|   ||¡}t |¡}|jdvr2q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   Z	parseXRDSÚbodyZgetCanonicalIDÚlistr   Úextend)
r	   r   Zservice_typesZservicesZcanonicalIDr   ÚurlÚresponseÚetZsome_servicesr
   r
   r   r   6   s    

zProxyResolver.query)N)Ú__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 rBd}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   Zopenidr   Zopenid.yadisr   Zopenid.yadis.xrir   Zopenid.yadis.servicesr   r"   Úobjectr   r   r
   r
   r
   r   Ú<module>   s   V