o
    ¯b
  ã                   @   sŽ   d Z ddlmZ G dd„ deƒZG dd„ dƒZG dd„ dƒZG d	d
„ d
ƒZG dd„ deƒZ	G dd„ deƒZ
G dd„ de
ƒZG dd„ de
ƒZdS )zf
Twisted Python Roots: an abstract hierarchy representation for Twisted.

Maintainer: Glyph Lefkowitz
é    )Úreflectc                   @   ó   e Zd ZdZdS )ÚNotSupportedErrorzv
    An exception meaning that the tree-manipulation operation
    you're attempting to perform is not supported.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r
   r
   ú6/usr/lib/python3/dist-packages/twisted/python/roots.pyr      ó    r   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚRequestzãI am an abstract representation of a request for an entity.

    I also function as the response.  The request is responded to by calling
    self.write(data) until there is no data left and then calling
    self.finish().
    Nc                 C   ó   t dt | j¡ ƒ‚)z.Add some data to the response to this request.z%s.write©ÚNotImplementedErrorr   ÚqualÚ	__class__)ÚselfÚdatar
   r
   r   Úwrite"   ó   zRequest.writec                 C   r   )zOThe response to this request is finished; flush all data to the network stream.z	%s.finishr   ©r   r
   r
   r   Úfinish&   r   zRequest.finish)r   r   r   r	   ÚwireProtocolr   r   r
   r
   r
   r   r      s
    	r   c                   @   s   e Zd ZdZdd„ ZdS )ÚEntityaZ  I am a terminal object in a hierarchy, with no children.

    I represent a null interface; certain non-instance objects (strings and
    integers, notably) are Entities.

    Methods on this class are suggested to be implemented, but are not
    required, and will be emulated on a per-protocol basis for types which do
    not handle them.
    c                 C   r   )zw
        I produce a stream of bytes for the request, by calling request.write()
        and request.finish().
        z	%s.renderr   ©r   Úrequestr
   r
   r   Úrender6   s   zEntity.renderN)r   r   r   r	   r   r
   r
   r
   r   r   +   s    
r   c                   @   s‚   e Zd ZdZd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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS ) Ú
Collectionz�I represent a static collection of entities.

    I contain methods designed to represent collections that can be dynamically
    created.
    Nc                 C   s   |dur	|| _ dS i | _ dS )zInitialize me.N©Úentities)r   r    r
   r
   r   Ú__init__E   s   

zCollection.__init__c                 C   s   | j  |¡S )zqGet an entity that was added to me using putEntity.

        This method will return 'None' if it fails.
        )r    Úget©r   Únamer
   r
   r   ÚgetStaticEntityL   ó   zCollection.getStaticEntityc                 C   ó   dS )znSubclass this to generate an entity on demand.

        This method should return 'None' if it fails.
        Nr
   ©r   r$   r   r
   r
   r   ÚgetDynamicEntityS   s    zCollection.getDynamicEntityc                 C   s2   |   |¡}|dur|S |  ||¡}|dur|S dS )a  Retrieve an entity from me.

        I will first attempt to retrieve an entity statically; static entities
        will obscure dynamic ones.  If that fails, I will retrieve the entity
        dynamically.

        If I cannot retrieve an entity, I will return 'None'.
        N)r%   r)   )r   r$   r   Úentr
   r
   r   Ú	getEntityY   s   
	zCollection.getEntityc                 C   s   || j |< dS )zlStore a static reference on 'name' for 'entity'.

        Raises a KeyError if the operation fails.
        Nr   ©r   r$   Úentityr
   r
   r   Ú	putEntityj   s   zCollection.putEntityc                 C   s   | j |= dS )zaRemove a static reference for 'name'.

        Raises a KeyError if the operation fails.
        Nr   r#   r
   r
   r   Ú	delEntityq   r&   zCollection.delEntityc                 C   r   )z>Store an entity for 'name', based on the content of 'request'.z%s.storeEntity©r   r   r   r   r(   r
   r
   r   ÚstoreEntityx   r   zCollection.storeEntityc                 C   r   )z?Remove an entity for 'name', based on the content of 'request'.z%s.removeEntityr0   r(   r
   r
   r   ÚremoveEntity|   r   zCollection.removeEntityc                 C   ó
   | j  ¡ S )zlRetrieve a list of all name, entity pairs that I store references to.

        See getStaticEntity.
        )r    Úitemsr   r
   r
   r   ÚlistStaticEntities€   ó   
zCollection.listStaticEntitiesc                 C   ó   g S )zaA list of all name, entity that I can generate on demand.

        See getDynamicEntity.
        r
   r   r
   r
   r   ÚlistDynamicEntities‡   ó   zCollection.listDynamicEntitiesc                 C   s   |   ¡ |  |¡ S )zURetrieve a list of all name, entity pairs I contain.

        See getEntity.
        )r5   r8   r   r
   r
   r   ÚlistEntitiesŽ   s   zCollection.listEntitiesc                 C   r3   )zkRetrieve a list of the names of entities that I store references to.

        See getStaticEntity.
        )r    Úkeysr   r
   r
   r   ÚlistStaticNames•   r6   zCollection.listStaticNamesc                 C   r7   )zlRetrieve a list of the names of entities that I store references to.

        See getDynamicEntity.
        r
   r   r
   r
   r   ÚlistDynamicNamesœ   r9   zCollection.listDynamicNamesc                 C   s   |   ¡ S )zZRetrieve a list of all names for entities that I contain.

        See getEntity.
        )r<   r   r
   r
   r   Ú	listNames£   s   zCollection.listNames©N)r   r   r   r	   r!   r%   r)   r+   r.   r/   r1   r2   r5   r8   r:   r<   r=   r>   r
   r
   r
   r   r   >   s     
r   c                   @   r   )ÚConstraintViolationz2An exception raised when a constraint is violated.Nr   r
   r
   r
   r   r@   «   r   r@   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚConstrainedz?A collection that has constraints on its names and/or entities.c                 C   r'   )zôA method that determines whether an entity may be added to me with a given name.

        If the constraint is satisfied, return 1; if the constraint is not
        satisfied, either return 0 or raise a descriptive ConstraintViolation.
        é   r
   r#   r
   r
   r   ÚnameConstraint²   ó   zConstrained.nameConstraintc                 C   r'   )zâA method that determines whether an entity may be added to me.

        If the constraint is satisfied, return 1; if the constraint is not
        satisfied, either return 0 or raise a descriptive ConstraintViolation.
        rB   r
   ©r   r-   r
   r
   r   ÚentityConstraintº   rD   zConstrained.entityConstraintc                 C   s   t  | ||¡ d S r?   )r   r.   r,   r
   r
   r   ÚreallyPutEntityÂ   s   zConstrained.reallyPutEntityc                 C   s4   |   |¡r|  |¡r|  ||¡ dS tdƒ‚tdƒ‚)zfStore an entity if it meets both constraints.

        Otherwise raise a ConstraintViolation.
        zEntity constraint violated.zName constraint violated.N)rC   rF   rG   r@   r,   r
   r
   r   r.   Å   s
   

zConstrained.putEntityN)r   r   r   r	   rC   rF   rG   r.   r
   r
   r
   r   rA   ¯   s    rA   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚLockedz5A collection that can be locked from adding entities.r   c                 C   s
   d| _ d S )NrB   ©Úlockedr   r
   r
   r   ÚlockØ   s   
zLocked.lockc                 C   s   | j  S r?   rI   rE   r
   r
   r   rF   Û   ó   zLocked.entityConstraintN)r   r   r   r	   rJ   rK   rF   r
   r
   r
   r   rH   Ó   s
    rH   c                   @   s,   e Zd ZdZeZdd„ Zdd„ Zdd„ ZdS )	Ú
Homogenousz¡A homogenous collection of entities.

    I will only contain entities that are an instance of the class or type
    specified by my 'entityType' attribute.
    c                 C   s&   t || jƒrdS t|› d| j› d�ƒ‚)NrB   z of incorrect type (ú))Ú
isinstanceÚ
entityTyper@   rE   r
   r
   r   rF   è   s   zHomogenous.entityConstraintc                 C   r'   )NÚNamer
   r   r
   r
   r   ÚgetNameTypeî   s   zHomogenous.getNameTypec                 C   s   | j jS r?   )rP   r   r   r
   r
   r   ÚgetEntityTypeñ   rL   zHomogenous.getEntityTypeN)	r   r   r   r	   ÚobjectrP   rF   rR   rS   r
   r
   r
   r   rM   ß   s    rM   N)r	   Útwisted.pythonr   r   r   r   r   r   Ú	Exceptionr@   rA   rH   rM   r
   r
   r
   r   Ú<module>   s   m$