
    Ϫf
                         d Z ddlmZ  G d de      Z G d d      Z G d d      Z G d	 d
      Z G d de      Z	 G d de      Z
 G d de
      Z G d de
      Zy)zf
Twisted Python Roots: an abstract hierarchy representation for Twisted.

Maintainer: Glyph Lefkowitz
    )reflectc                       e Zd ZdZy)NotSupportedErrorzv
    An exception meaning that the tree-manipulation operation
    you're attempting to perform is not supported.
    N__name__
__module____qualname____doc__     6/usr/lib/python3/dist-packages/twisted/python/roots.pyr   r      s    r   r   c                        e Zd ZdZdZd Zd Zy)RequestzI 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                 X    t        dt        j                  | j                        z        )z.Add some data to the response to this request.z%s.writeNotImplementedErrorr   qual	__class__)selfdatas     r   writezRequest.write"   s    !*w||DNN/K"KLLr   c                 X    t        dt        j                  | j                        z        )zOThe response to this request is finished; flush all data to the network stream.z	%s.finishr   r   s    r   finishzRequest.finish&   s    !+T^^0L"LMMr   )r   r   r	   r
   wireProtocolr   r   r   r   r   r   r      s     LMNr   r   c                       e Zd ZdZd Zy)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                 X    t        dt        j                  | j                        z        )zw
        I produce a stream of bytes for the request, by calling request.write()
        and request.finish().
        z	%s.renderr   r   requests     r   renderzEntity.render6   s!    
 "+T^^0L"LMMr   N)r   r   r	   r
   r!   r   r   r   r   r   +   s    Nr   r   c                   f    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zy)
CollectionzI represent a static collection of entities.

    I contain methods designed to represent collections that can be dynamically
    created.
    Nc                 &    ||| _         yi | _         y)zInitialize me.Nentities)r   r&   s     r   __init__zCollection.__init__E   s    $DMDMr   c                 8    | j                   j                  |      S )zqGet an entity that was added to me using putEntity.

        This method will return 'None' if it fails.
        )r&   getr   names     r   getStaticEntityzCollection.getStaticEntityL   s    
 }}  &&r   c                      y)znSubclass this to generate an entity on demand.

        This method should return 'None' if it fails.
        Nr   r   r+   r    s      r   getDynamicEntityzCollection.getDynamicEntityS   s    r   c                 Z    | j                  |      }||S | j                  ||      }||S y)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    ents       r   	getEntityzCollection.getEntityY   s=     ""4(?J##D'2?Jr   c                 "    || j                   |<   y)zlStore a static reference on 'name' for 'entity'.

        Raises a KeyError if the operation fails.
        Nr%   r   r+   entitys      r   	putEntityzCollection.putEntityj   s    
 %dr   c                     | j                   |= y)zaRemove a static reference for 'name'.

        Raises a KeyError if the operation fails.
        Nr%   r*   s     r   	delEntityzCollection.delEntityq   s    
 MM$r   c                 X    t        dt        j                  | j                        z        )z>Store an entity for 'name', based on the content of 'request'.z%s.storeEntityr   r   r   r   r.   s      r   storeEntityzCollection.storeEntityx   s      07<<3O OPPr   c                 X    t        dt        j                  | j                        z        )z?Remove an entity for 'name', based on the content of 'request'.z%s.removeEntityr:   r.   s      r   removeEntityzCollection.removeEntity|   s      1GLL4P PQQr   c                 6    | j                   j                         S )zlRetrieve a list of all name, entity pairs that I store references to.

        See getStaticEntity.
        )r&   itemsr   s    r   listStaticEntitieszCollection.listStaticEntities   s    
 }}""$$r   c                     g S )zaA list of all name, entity that I can generate on demand.

        See getDynamicEntity.
        r   r   s     r   listDynamicEntitieszCollection.listDynamicEntities   	    
 	r   c                 F    | j                         | j                  |      z   S )zURetrieve a list of all name, entity pairs I contain.

        See getEntity.
        )r@   rB   r   s     r   listEntitieszCollection.listEntities   s#    
 &&(4+C+CG+LLLr   c                 6    | j                   j                         S )zkRetrieve a list of the names of entities that I store references to.

        See getStaticEntity.
        )r&   keysr   s    r   listStaticNameszCollection.listStaticNames   s    
 }}!!##r   c                     g S )zlRetrieve a list of the names of entities that I store references to.

        See getDynamicEntity.
        r   r   s    r   listDynamicNameszCollection.listDynamicNames   rC   r   c                 "    | j                         S )zZRetrieve a list of all names for entities that I contain.

        See getEntity.
        )rH   r   s     r   	listNameszCollection.listNames   s    
 ##%%r   N)r   r   r	   r
   r'   r,   r/   r2   r6   r8   r;   r=   r@   rB   rE   rH   rJ   rL   r   r   r   r#   r#   >   sP    '"% QR%M$&r   r#   c                       e Zd ZdZy)ConstraintViolationz2An exception raised when a constraint is violated.Nr   r   r   r   rO   rO      s    <r   rO   c                   (    e Zd ZdZd Zd Zd Zd Zy)Constrainedz?A collection that has constraints on its names and/or entities.c                      y)zA 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*   s     r   nameConstraintzConstrained.nameConstraint        r   c                      y)zA 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.
        rS   r   r   r5   s     r   entityConstraintzConstrained.entityConstraint   rU   r   c                 2    t         j                  | ||       y rM   )r#   r6   r4   s      r   reallyPutEntityzConstrained.reallyPutEntity   s    T40r   c                     | j                  |      r/| j                  |      r| j                  ||       y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)rT   rX   rZ   rO   r4   s      r   r6   zConstrained.putEntity   sH    
 t$$$V,$$T62)*GHH%&ABBr   N)r   r   r	   r
   rT   rX   rZ   r6   r   r   r   rQ   rQ      s    I1Cr   rQ   c                        e Zd ZdZdZd Zd Zy)Lockedz5A collection that can be locked from adding entities.r   c                     d| _         y )NrS   lockedr   s    r   lockzLocked.lock   s	    r   c                     | j                    S rM   r_   rW   s     r   rX   zLocked.entityConstraint   s    ;;r   N)r   r   r	   r
   r`   ra   rX   r   r   r   r]   r]      s    ?Fr   r]   c                   &    e Zd ZdZeZd Zd Zd Zy)
HomogenouszA homogenous collection of entities.

    I will only contain entities that are an instance of the class or type
    specified by my 'entityType' attribute.
    c                 f    t        || j                        ryt        | d| j                   d      )NrS   z of incorrect type ())
isinstance
entityTyperO   rW   s     r   rX   zHomogenous.entityConstraint   s2    fdoo.%0DT__DUUV&WXXr   c                      y)NNamer   r   s    r   getNameTypezHomogenous.getNameType   s    r   c                 .    | j                   j                  S rM   )rh   r   r   s    r   getEntityTypezHomogenous.getEntityType   s    '''r   N)	r   r   r	   r
   objectrh   rX   rk   rm   r   r   r   rd   rd      s     JY(r   rd   N)r
   twisted.pythonr   r   r   r   r   r#   	ExceptionrO   rQ   r]   rd   r   r   r   <module>rq      st   
 #+ N N*N N&j& j&Z=) =!C* !CH	[ 	( (r   