o
    Óó·i
  ã                   @   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
   úZC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-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.writeN©Ú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.finishNr   ©r   r
   r
   r   Úfinish&   r   zRequest.finish)r   r   r   r	   Z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.renderNr   ©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.
        N)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.storeEntityN©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.removeEntityNr/   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.
        N)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.
        Nr
   r   r
   r
   r   ÚlistDynamicEntities‡   ó   zCollection.listDynamicEntitiesc                 C   s   |   ¡ |  |¡ S )zURetrieve a list of all name, entity pairs I contain.

        See getEntity.
        N)r4   r7   r   r
   r
   r   ÚlistEntitiesŽ   s   zCollection.listEntitiesc                 C   r2   )zkRetrieve a list of the names of entities that I store references to.

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

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

        See getEntity.
        N)r;   r   r
   r
   r   Ú	listNames£   s   zCollection.listNames©N)r   r   r   r	   r    r$   r(   r*   r-   r.   r0   r1   r4   r7   r9   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.
        é   Nr
   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.
        rA   Nr
   ©r   r,   r
   r
   r   ÚentityConstraintº   rC   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)rB   rE   rF   r?   r+   r
   r
   r   r-   Å   s
   

zConstrained.putEntityN)r   r   r   r	   rB   rE   rF   r-   r
   r
   r
   r   r@   ¯   s    r@   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 )NrA   ©Úlockedr   r
   r
   r   ÚlockØ   s   
zLocked.lockc                 C   s   | j  S r>   rH   rD   r
   r
   r   rE   Û   ó   zLocked.entityConstraintN)r   r   r   r	   rI   rJ   rE   r
   r
   r
   r   rG   Ó   s
    rG   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�ƒ‚)NrA   z of incorrect type (ú))Ú
isinstanceÚ
entityTyper?   rD   r
   r
   r   rE   è   s   zHomogenous.entityConstraintc                 C   r&   )NÚNamer
   r   r
   r
   r   ÚgetNameTypeî   s   zHomogenous.getNameTypec                 C   s   | j jS r>   )rO   r   r   r
   r
   r   ÚgetEntityTypeñ   rK   zHomogenous.getEntityTypeN)	r   r   r   r	   ÚobjectrO   rE   rQ   rR   r
   r
   r
   r   rL   ß   s    rL   N)r	   Ztwisted.pythonr   r   r   r   r   r   Ú	Exceptionr?   r@   rG   rL   r
   r
   r
   r   Ú<module>   s   m$