o b @sdZddlmZGdddeZGdddZGdddZGd d d ZGd d d eZ Gd ddeZ Gddde Z Gddde Z dS)zf Twisted Python Roots: an abstract hierarchy representation for Twisted. Maintainer: Glyph Lefkowitz )reflectc@eZdZdZdS)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.pyrrc@s$eZdZdZdZddZddZdS)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(). NcCtdt|j)z.Add some data to the response to this request.z%s.writeNotImplementedErrorrqual __class__)selfdatar r r write"z Request.writecCr)zOThe response to this request is finished; flush all data to the network stream.z %s.finishrrr r r finish&rzRequest.finish)rrrr wireProtocolrrr r r r r s   r c@seZdZdZddZdS)EntityaZI 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. cCr)zw I produce a stream of bytes for the request, by calling request.write() and request.finish(). z %s.renderrrrequestr r r render6sz Entity.renderN)rrrr rr r r r r+s rc@seZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS) CollectionzI represent a static collection of entities. I contain methods designed to represent collections that can be dynamically created. NcCs|dur ||_dSi|_dS)zInitialize me.Nentities)rr r r r __init__Es  zCollection.__init__cCs |j|S)zqGet an entity that was added to me using putEntity. This method will return 'None' if it fails. )r getrnamer r r getStaticEntityL zCollection.getStaticEntitycCdS)znSubclass this to generate an entity on demand. This method should return 'None' if it fails. Nr rr$rr r r getDynamicEntitySszCollection.getDynamicEntitycCs2||}|dur |S|||}|dur|SdS)aRetrieve 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))rr$rentr r r getEntityYs  zCollection.getEntitycCs||j|<dS)zlStore a static reference on 'name' for 'entity'. Raises a KeyError if the operation fails. Nrrr$entityr r r putEntityjszCollection.putEntitycCs |j|=dS)zaRemove a static reference for 'name'. Raises a KeyError if the operation fails. Nrr#r r r delEntityqr&zCollection.delEntitycCr)z>Store an entity for 'name', based on the content of 'request'.z%s.storeEntityrrrrr(r r r storeEntityxrzCollection.storeEntitycCr)z?Remove an entity for 'name', based on the content of 'request'.z%s.removeEntityr0r(r r r removeEntity|rzCollection.removeEntitycC |jS)zlRetrieve a list of all name, entity pairs that I store references to. See getStaticEntity. )r itemsrr r r listStaticEntities zCollection.listStaticEntitiescCgS)zaA list of all name, entity that I can generate on demand. See getDynamicEntity. r rr r r listDynamicEntitieszCollection.listDynamicEntitiescCs|||S)zURetrieve a list of all name, entity pairs I contain. See getEntity. )r5r8rr r r listEntitiesszCollection.listEntitiescCr3)zkRetrieve a list of the names of entities that I store references to. See getStaticEntity. )r keysrr r r listStaticNamesr6zCollection.listStaticNamescCr7)zlRetrieve a list of the names of entities that I store references to. See getDynamicEntity. r rr r r listDynamicNamesr9zCollection.listDynamicNamescCs|S)zZRetrieve a list of all names for entities that I contain. See getEntity. )r<rr r r listNamesszCollection.listNamesN)rrrr r!r%r)r+r.r/r1r2r5r8r:r<r=r>r r r r r>s   rc@r)ConstraintViolationz2An exception raised when a constraint is violated.Nrr r r r r@r r@c@s0eZdZdZddZddZddZdd Zd S) Constrainedz?A collection that has constraints on its names and/or entities.cCr')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#r r r nameConstraintzConstrained.nameConstraintcCr')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. rBr rr-r r r entityConstraintrDzConstrained.entityConstraintcCst|||dSr?)rr.r,r r r reallyPutEntityszConstrained.reallyPutEntitycCs4||r||r|||dStdtd)zfStore an entity if it meets both constraints. Otherwise raise a ConstraintViolation. zEntity constraint violated.zName constraint violated.N)rCrFrGr@r,r r r r.s  zConstrained.putEntityN)rrrr rCrFrGr.r r r r rAs  rAc@s$eZdZdZdZddZddZdS)Lockedz5A collection that can be locked from adding entities.rcCs d|_dS)NrBlockedrr r r locks z Locked.lockcCs|j Sr?rIrEr r r rFzLocked.entityConstraintN)rrrr rJrKrFr r r r rHs  rHc@s,eZdZdZeZddZddZddZdS) HomogenouszA homogenous collection of entities. I will only contain entities that are an instance of the class or type specified by my 'entityType' attribute. cCs&t||jrdSt|d|jd)NrBz of incorrect type ()) isinstance entityTyper@rEr r r rFs zHomogenous.entityConstraintcCr')NNamer rr r r getNameTypeszHomogenous.getNameTypecCs|jjSr?)rPrrr r r getEntityTyperLzHomogenous.getEntityTypeN) rrrr objectrPrFrRrSr r r r rMs  rMN) r twisted.pythonrrrr rr Exceptionr@rArHrMr r r r s m$