← Back
Editing: etxrd.cpython-311.pyc
� |=�^� � � � d Z g d�ZddlZddlZddlZddlmZ ddlmZ ddlm Z m Z e � � Z e � � Zddl mZ G d� d e� � Z G d � de� � Zd� Zd ZdZd� Zd� Zd� Z ed� � Z ed� � Z ed� � Z ed� � Z ed� � Z ed� � Z ed� � Zd� Zd� Z d'd�Z!d� Z"ej# G d� de$� � � � Z% e%� � Z&d� Z'd � Z(d!� Z)d"� Z*d#� Z+d$� Z,d%� Z-d&� Z.dS )(z+ ElementTree interface to an XRD document. )�nsTag�mkXRDTag�isXRDS� parseXRDS�getCanonicalID�getYadisXRD�getPriorityStrict�getPriority�prioSort�iterServices� expandService�expandServices� N)�datetime)�strptime)�importElementTree�importSafeElementTree)�xric � � e Zd ZdZdZdS )� XRDSErrorz An error with the XRDS document.N)�__name__� __module__�__qualname__�__doc__�reason� � �4/usr/lib/python3/dist-packages/openid/yadis/etxrd.pyr r $ s � � � � � �*�*� �F�F�Fr r c � � e Zd ZdZdS )� XRDSFraudzbRaised when there's an assertion in the XRDS that it does not have the authority to make. N)r r r r r r r r r + s � � � � � �� � � r r c � � t | t � � r| � d� � n| }t � |� � }t � |� � }t |� � st d� � �|S # t t t t f$ r � t $ r}t d� � }||_ |�d}~ww xY w)z�Parse the given text as an XRDS document. @return: ElementTree containing an XRDS document @raises XRDSError: When there is a parse error or the document does not contain an XRDS. �utf8zNot an XRDS documentzError parsing document as XMLN)� isinstance�str�encode�SafeElementTree�XML�ElementTreer r � SystemExit�MemoryError�AssertionError�ImportError� Exceptionr )�text� bytestring�element�tree�why�excs r r r 1 s� � �� -7�t�S�,A�,A�K�T�[�[��(�(�(�t� �!�%�%�j�1�1�� �&�&�w�/�/���d�|�|� 4��2�3�3�3���� ��^�[�A� � � � �� � � ��7�8�8���� �� ��������s �AB �'C�)C�Czxri://$xrd*($v*2.0)zxri://$xrdsc � � d| �d|��S )N�{�}r )�ns�ts r r r S s � � ��r�r�1�1��r c �, � t t | � � S )zybasestring -> basestring Create a tag name in the XRD 2.0 XML namespace suitable for using with ElementTree )r � XRD_NS_2_0�r7 s r r r W s � � ��Q���r c �, � t t | � � S )zvbasestring -> basestring Create a tag name in the XRDS XML namespace suitable for using with ElementTree )r �XRDS_NSr: s r � mkXRDSTagr= ` s � � ��!���r �XRDS�Service�XRD�Type�URI�Expires�CanonicalIDc �J � | � � � }|j t k S )z"Is this document an XRDS document?)�getroot�tag�root_tag)�xrd_tree�roots r r r u s � ������D��8�x��r c �f � d}| � t � � D ]}�|�t d� � �|S )z=Return the XRD element that should contain the Yadis servicesNzNo XRD present in tree)�findall�xrd_tagr �rI �xrds r r r { sD � � �C� ����(�(� � ��� �{��0�1�1�1��Jr c � � | � t � � }|�|S |j }t |d� � }t |dd� � S )a� Return the expiration date of this XRD element, or None if no expiration was specified. @type xrd_element: ElementTree node @param default: The value to use as the expiration if no expiration was specified in the XRD. @rtype: datetime.datetime @raises ValueError: If the xrd:Expires element is present, but its contents are not formatted according to the specification. Nz%Y-%m-%dT%H:%M:%SZr � )�find�expires_tagr- r r )�xrd_element�default�expires_element�expires_string�expires_times r �getXRDExpirationrY � sP � � "�&�&�{�3�3�O�����(�-�� ��0D�E�E����a��c�*�+�+r c � � |� t � � }|� � � t j |d � t � � d j � � }n# t $ r Y dS w xY w|� � � }|dd� D ]x}|� dd� � d }t j |� t � � � � }||� � � k rt |�d|��� � �|}�yt j | � � }t j ||� � st |�d|��� � �|S )a Return the CanonicalID from this XRDS document. @param iname: the XRI being resolved. @type iname: unicode @param xrd_tree: The XRDS output from the resolver. @type xrd_tree: ElementTree @returns: The XRI CanonicalID or None. @returntype: unicode or None r N� �!z can not come from z can not come from root )rL rM �reverser �XRI�canonicalID_tagr- � IndexError�lower�rsplit�findtextr � rootAuthority�providerIsAuthoritative) �inamerI �xrd_list�canonicalID�childIDrO � parent_sought�parentrJ s r r r � sP � � ����(�(�H���������g�h�q�k�1�1�/�B�B�1�E�J�K�K����� � � ��t�t����� ���!�!�G�����|� � �����s�A�.�.�q�1� ������o�6�6�7�7���F�L�L�N�N�*�*�����&�&�I�J�J�J������U�#�#�D��&�t�W�5�5� J��'�'�'�4�4�H�I�I�I��s �=A. �. A<�;A<c � � e Zd ZdZd� Zd� ZdS )�_Maxz� Value that compares greater than any other value. Should only be used as a singleton. Implemented for use as a priority value for when a priority is not specified. c �, � t || j � � S �N�r"