
    h
                         S r SSKJr   " S S\5      r " S S5      r " S S5      r " S	 S
5      r " S S\5      r	 " S S\5      r
 " S S\
5      r " S S\
5      rg)zf
Twisted Python Roots: an abstract hierarchy representation for Twisted.

Maintainer: Glyph Lefkowitz
    )reflectc                       \ rS rSrSrSrg)NotSupportedError   zj
An exception meaning that the tree-manipulation operation
you're attempting to perform is not supported.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/python/roots.pyr   r      s    r   r   c                   (    \ rS rSrSrSrS rS rSrg)Request   zI 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                 Z    [        S[        R                  " U R                  5      -  5      e)z.Add some data to the response to this request.z%s.writeNotImplementedErrorr   qual	__class__)selfdatas     r   writeRequest.write"   s    !*w||DNN/K"KLLr   c                 Z    [        S[        R                  " U R                  5      -  5      e)zOThe response to this request is finished; flush all data to the network stream.z	%s.finishr   r   s    r   finishRequest.finish&   s    !+T^^0L"LMMr   r   )	r	   r
   r   r   r   wireProtocolr   r   r   r   r   r   r   r      s     LMNr   r   c                       \ rS rSrSrS rSrg)Entity+   aB  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                 Z    [        S[        R                  " U R                  5      -  5      e)z_
I produce a stream of bytes for the request, by calling request.write()
and request.finish().
z	%s.renderr   r   requests     r   renderEntity.render6   s!    
 "+T^^0L"LMMr   r   N)r	   r
   r   r   r   r(   r   r   r   r   r#   r#   +   s    Nr   r#   c                   p    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rSrg)
Collection>   zI represent a static collection of entities.

I contain methods designed to represent collections that can be dynamically
created.
Nc                 &    Ub  Xl         g0 U l         g)zInitialize me.Nentities)r   r/   s     r   __init__Collection.__init__E   s    $MDMr   c                 8    U R                   R                  U5      $ )zaGet an entity that was added to me using putEntity.

This method will return 'None' if it fails.
)r/   getr   names     r   getStaticEntityCollection.getStaticEntityL   s    
 }}  &&r   c                     g)z^Subclass this to generate an entity on demand.

This method should return 'None' if it fails.
Nr   r   r5   r'   s      r   getDynamicEntityCollection.getDynamicEntityS   s    r   c                 \    U R                  U5      nUb  U$ U R                  X5      nUb  U$ g)zRetrieve 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)r6   r:   )r   r5   r'   ents       r   	getEntityCollection.getEntityY   s;     ""4(?J##D2?Jr   c                      X R                   U'   g)z\Store a static reference on 'name' for 'entity'.

Raises a KeyError if the operation fails.
Nr.   r   r5   entitys      r   	putEntityCollection.putEntityj   s    
 %dr   c                     U R                   U	 g)zQRemove a static reference for 'name'.

Raises a KeyError if the operation fails.
Nr.   r4   s     r   	delEntityCollection.delEntityq   s    
 MM$r   c                 Z    [        S[        R                  " U R                  5      -  5      e)z>Store an entity for 'name', based on the content of 'request'.z%s.storeEntityr   r   r   r   r9   s      r   storeEntityCollection.storeEntityx   s      07<<3O OPPr   c                 Z    [        S[        R                  " U R                  5      -  5      e)z?Remove an entity for 'name', based on the content of 'request'.z%s.removeEntityrI   r9   s      r   removeEntityCollection.removeEntity|   s      1GLL4P PQQr   c                 6    U R                   R                  5       $ )z\Retrieve a list of all name, entity pairs that I store references to.

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

See getDynamicEntity.
r   r&   s     r   listDynamicEntitiesCollection.listDynamicEntities   	    
 	r   c                 F    U R                  5       U R                  U5      -   $ )zERetrieve a list of all name, entity pairs I contain.

See getEntity.
)rQ   rT   r&   s     r   listEntitiesCollection.listEntities   s#    
 &&(4+C+CG+LLLr   c                 6    U R                   R                  5       $ )z[Retrieve a list of the names of entities that I store references to.

See getStaticEntity.
)r/   keysr   s    r   listStaticNamesCollection.listStaticNames   s    
 }}!!##r   c                     / $ )z\Retrieve a list of the names of entities that I store references to.

See getDynamicEntity.
r   r   s    r   listDynamicNamesCollection.listDynamicNames   rV   r   c                 "    U R                  5       $ )zJRetrieve a list of all names for entities that I contain.

See getEntity.
)r\   r&   s     r   	listNamesCollection.listNames   s    
 ##%%r   r.   N)r	   r
   r   r   r   r0   r6   r:   r>   rC   rF   rJ   rM   rQ   rT   rX   r\   r_   rb   r   r   r   r   r+   r+   >   sP    '"% QR%M$&r   r+   c                       \ rS rSrSrSrg)ConstraintViolation   z2An exception raised when a constraint is violated.r   Nr   r   r   r   rf   rf      s    <r   rf   c                   0    \ rS rSrSrS rS rS rS rSr	g)	Constrained   z?A collection that has constraints on its names and/or entities.c                     g)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   r4   s     r   nameConstraintConstrained.nameConstraint        r   c                     g)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.
rl   r   r   rB   s     r   entityConstraintConstrained.entityConstraint   ro   r   c                 0    [         R                  XU5        g rd   )r+   rC   rA   s      r   reallyPutEntityConstrained.reallyPutEntity   s    T0r   c                     U R                  U5      (       a3  U R                  U5      (       a  U R                  X5        g[        S5      e[        S5      e)zVStore an entity if it meets both constraints.

Otherwise raise a ConstraintViolation.
zEntity constraint violated.zName constraint violated.N)rm   rr   ru   rf   rA   s      r   rC   Constrained.putEntity   sL    
 t$$$$V,,$$T2)*GHH%&ABBr   r   N)
r	   r
   r   r   r   rm   rr   ru   rC   r   r   r   r   ri   ri      s    I1Cr   ri   c                   (    \ rS rSrSrSrS rS rSrg)Locked   z5A collection that can be locked from adding entities.r   c                     SU l         g )Nrl   lockedr   s    r   lockLocked.lock   s	    r   c                 $    U R                   (       + $ rd   r}   rq   s     r   rr   Locked.entityConstraint   s    ;;r   r}   N)	r	   r
   r   r   r   r~   r   rr   r   r   r   r   rz   rz      s    ?Fr   rz   c                   .    \ rS rSrSr\rS rS rS r	Sr
g)
Homogenous   zA homogenous collection of entities.

I will only contain entities that are an instance of the class or type
specified by my 'entityType' attribute.
c                 n    [        XR                  5      (       a  g[        U SU R                   S35      e)Nrl   z of incorrect type ())
isinstance
entityTyperf   rq   s     r   rr   Homogenous.entityConstraint   s3    foo..%0DT__DUUV&WXXr   c                     g)NNamer   r   s    r   getNameTypeHomogenous.getNameType   s    r   c                 .    U R                   R                  $ rd   )r   r	   r   s    r   getEntityTypeHomogenous.getEntityType   s    '''r   r   N)r	   r
   r   r   r   objectr   rr   r   r   r   r   r   r   r   r      s     JY(r   r   N)r   twisted.pythonr   r   r   r   r#   r+   	Exceptionrf   ri   rz   r   r   r   r   <module>r      st   
 #+ N N*N N&j& j&Z=) =!C* !CH	[ 	( (r   