3
d๗  ใ               @   s<   d Z dZG dd deZG dd deZG dd deZdS )	zTrung Dong Huynhztrungdong@donggiang.comc               @   sL   e Zd ZdZdd Zedd Zdd Zdd	 Zd
d Z	dd Z
dd ZdS )ฺ
Identifierz>Base class for all identifiers and also represents xsd:anyURI.c             C   s   t || _dS )za
        Constructor.

        :param uri: URI string for the long namespace identifier.
        N)ฺstrฺ_uri)ฺselfฺuriฉ r   ๚//tmp/pip-build-7vycvbft/prov/prov/identifier.pyฺ__init__   s    zIdentifier.__init__c             C   s   | j S )zIdentifier's URI.)r   )r   r   r   r   r      s    zIdentifier.uric             C   s   | j S )N)r   )r   r   r   r   ฺ__str__   s    zIdentifier.__str__c             C   s   t |tr| j|jkS dS )NF)ฺ
isinstancer   r   )r   ฺotherr   r   r   ฺ__eq__   s    zIdentifier.__eq__c             C   s   t | j| jfS )N)ฺhashr   ฺ	__class__)r   r   r   r   ฺ__hash__   s    zIdentifier.__hash__c             C   s   d| j j| jf S )Nz<%s: %s>)r   ฺ__name__r   )r   r   r   r   ฺ__repr__!   s    zIdentifier.__repr__c             C   s
   d| j  S )z4PROV-N representation of qualified name in a string.z"%s" %%%% xsd:anyURI)r   )r   r   r   r   ฺprovn_representation$   s    zIdentifier.provn_representationN)r   ฺ
__module__ฺ__qualname__ฺ__doc__r   ฺpropertyr   r	   r   r   r   r   r   r   r   r   r      s   r   c               @   sP   e Zd ZdZdd Zedd Zedd Zdd	 Zd
d Z	dd Z
dd ZdS )ฺQualifiedNamez:Qualified name of an identifier in a particular namespace.c             C   sD   t j| dj|j|g || _|| _|jr:dj|j|gn|| _dS )zป
        Constructor.

        :param namespace: Namespace to use for qualified name resolution.
        :param localpart: Portion of identifier not part of the namespace prefix.
        ฺ ๚:N)r   r   ฺjoinr   ฺ
_namespaceฺ
_localpartฺprefixฺ_str)r   ฺ	namespaceฺ	localpartr   r   r   r   ,   s    zQualifiedName.__init__c             C   s   | j S )zNamespace of qualified name.)r   )r   r   r   r   r   :   s    zQualifiedName.namespacec             C   s   | j S )zLocal part of qualified name.)r   )r   r   r   r   r    ?   s    zQualifiedName.localpartc             C   s   | j S )N)r   )r   r   r   r   r	   D   s    zQualifiedName.__str__c             C   s   d| j j| jf S )Nz<%s: %s>)r   r   r   )r   r   r   r   r   G   s    zQualifiedName.__repr__c             C   s
   t | jS )N)r   r   )r   r   r   r   r   J   s    zQualifiedName.__hash__c             C   s
   d| j  S )z4PROV-N representation of qualified name in a string.z'%s')r   )r   r   r   r   r   M   s    z"QualifiedName.provn_representationN)r   r   r   r   r   r   r   r    r	   r   r   r   r   r   r   r   r   )   s   r   c               @   sh   e Zd ZdZdd Zedd Zedd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd ZdS )ฺ	NamespacezPROV Namespace.c             C   s   || _ || _t | _dS )zค
        Constructor.

        :param prefix: String short hand prefix for the namespace.
        :param uri: URI string for the long namespace identifier.
        N)ฺ_prefixr   ฺdictฺ_cache)r   r   r   r   r   r   r   U   s    zNamespace.__init__c             C   s   | j S )zNamespace URI.)r   )r   r   r   r   r   `   s    zNamespace.uric             C   s   | j S )zNamespace prefix.)r"   )r   r   r   r   r   e   s    zNamespace.prefixc             C   s6   t |tr|nt |tr|jnd}|r2|j| jS dS )zข
        Indicates whether the identifier provided is contained in this namespace.

        :param identifier: Identifier to check.
        :return: bool
        NF)r
   r   r   r   ฺ
startswithr   )r   ฺ
identifierr   r   r   r   ฺcontainsj   s    	zNamespace.containsc             C   sR   t |tr|nt |tr|jnd}|rJ|j| jrJt| |t| jd S dS dS )zฺ
        Returns the qualified name of the identifier given using the namespace
        prefix.

        :param identifier: Identifier to resolve to a qualified name.
        :return: :py:class:`QualifiedName`
        N)r
   r   r   r   r%   r   r   ฺlen)r   r&   r   r   r   r   ฺqnamex   s
    
zNamespace.qnamec             C   s&   t |tr"| j|jko$| j|jkS dS )NF)r
   r!   r   r   r"   r   )r   r   r   r   r   r      s    "zNamespace.__eq__c             C   s$   t |t p"| j|jkp"| j|jkS )N)r
   r!   r   r   r"   r   )r   r   r   r   r   ฺ__ne__   s    zNamespace.__ne__c             C   s   t | j| jfS )N)r   r   r"   )r   r   r   r   r      s    zNamespace.__hash__c             C   s   d| j j| j| jf S )Nz<%s: %s {%s}>)r   r   r"   r   )r   r   r   r   r      s    zNamespace.__repr__c             C   s0   || j kr| j | S t| |}|| j |< |S d S )N)r$   r   )r   r    r)   r   r   r   ฺ__getitem__   s
    



zNamespace.__getitem__N)r   r   r   r   r   r   r   r   r'   r)   r   r*   r   r   r+   r   r   r   r   r!   R   s   r!   N)ฺ
__author__ฺ	__email__ฺobjectr   r   r!   r   r   r   r   ฺ<module>   s   $)