
    \d
                         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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__     4lib/python3.11/site-packages/twisted/python/roots.pyr   r      s           r   r   c                   "    e Zd ZdZdZd Zd ZdS )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                 T    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|DN/K/K"KLLLr   c                 T    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^0L0L"LMMMr   )r   r   r	   r
   wireProtocolr   r   r   r   r   r   r      sK          LM M MN N N N Nr   r   c                       e Zd ZdZ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                 T    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^0L0L"LMMMr   N)r   r   r	   r
   r!   r   r   r   r   r   +   s2         N N N N Nr   r   c                   h    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dS )
CollectionzI represent a static collection of entities.

    I contain methods designed to represent collections that can be dynamically
    created.
    Nc                 *    |	|| _         dS i | _         dS )zInitialize me.Nentities)r   r&   s     r   __init__zCollection.__init__E   s    $DMMMDMMMr   c                 6    | 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                     dS )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                 l    |                      |          }||S |                     ||          }||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    ents       r   	getEntityzCollection.getEntityY   sE     ""4((?J##D'22?Jtr   c                     || j         |<   dS )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         |= dS )zaRemove a static reference for 'name'.

        Raises a KeyError if the operation fails.
        Nr%   r*   s     r   	delEntityzCollection.delEntityq   s    
 M$r   c                 T    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<3O3O OPPPr   c                 T    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"     1GL4P4P PQQQr   c                 4    | 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                 V    |                                  |                     |          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LLr   c                 4    | 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                 *    |                                  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#   >   s            ' ' '    "% % %     Q Q QR R R% % %  M M M$ $ $  & & & & &r   r#   c                       e Zd ZdZdS )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dS )Constrainedz?A collection that has constraints on its names and/or entities.c                     dS )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   	     qr   c                     dS )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                 >    t                               | ||           d S rM   )r#   r6   r4   s      r   reallyPutEntityzConstrained.reallyPutEntity   s     T400000r   c                     |                      |          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)rT   rX   rZ   rO   r4   s      r   r6   zConstrained.putEntity   sl    
 t$$ 	C$$V,, I$$T622222)*GHHH%&ABBBr   N)r   r   r	   r
   rT   rX   rZ   r6   r   r   r   rQ   rQ      s[        II    1 1 1C C C C Cr   rQ   c                   "    e Zd ZdZdZd Zd ZdS )Lockedz5A collection that can be locked from adding entities.r   c                     d| _         d S )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dS )
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                 d    t          || j                  rdS t          | d| j         d          )NrS   z of incorrect type ())
isinstance
entityTyperO   rW   s     r   rX   zHomogenous.entityConstraint   s=    fdo.. 	Y1%&W&WT_&W&W&WXXXr   c                     dS )NNamer   r   s    r   getNameTypezHomogenous.getNameType   s    vr   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      sU          JY Y Y  ( ( ( ( (r   rd   N)r
   twisted.pythonr   r   r   r   r   r#   	ExceptionrO   rQ   r]   rd   r   r   r   <module>rq      s  
  # " " " " "    +   N N N N N N N N*N N N N N N N N&j& j& j& j& j& j& j& j&Z= = = = =) = = =!C !C !C !C !C* !C !C !CH	 	 	 	 	[ 	 	 	( ( ( ( ( ( ( ( ( (r   