
[XMc           @   s   d  Z  d d l Z d d l m Z d e f d     YZ d d d     YZ d d d	     YZ d
 d d     YZ d e	 f d     YZ
 d e f d     YZ d e f d     YZ d e f d     YZ d S(   sf   
Twisted Python Roots: an abstract hierarchy representation for Twisted.

Maintainer: Glyph Lefkowitz
iN(   t   reflectt   NotSupportedErrorc           B   s   e  Z d  Z RS(   sv   
    An exception meaning that the tree-manipulation operation
    you're attempting to perform is not supported.
    (   t   __name__t
   __module__t   __doc__(    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR      s   t   Requestc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s   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().
    c         C   s    t  d t j |  j    d S(   s7   Add some data to the response to this request.
        s   %s.writeN(   t   NotImplementedErrorR    t   qualt	   __class__(   t   selft   data(    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   write    s    c         C   s    t  d t j |  j    d S(   sX   The response to this request is finished; flush all data to the network stream.
        s	   %s.finishN(   R   R    R   R   (   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   finish%   s    N(   R   R   R   t   Nonet   wireProtocolR   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR      s   	t   Entityc           B   s   e  Z d  Z d   Z RS(   sZ  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   s    t  d t j |  j    d S(   sw   
        I produce a stream of bytes for the request, by calling request.write()
        and request.finish().
        s	   %s.renderN(   R   R    R   R   (   R	   t   request(    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   render5   s    (   R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR   +   s   	t
   Collectionc           B   s   e  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 RS(   s   I represent a static collection of entities.

    I contain methods designed to represent collections that can be dynamically
    created.
    c         C   s%   | d k	 r | |  _ n	 i  |  _ d S(   s   Initialize me.
        N(   R   t   entities(   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   __init__D   s    c         C   s   |  j  j |  S(   sq   Get an entity that was added to me using putEntity.

        This method will return 'None' if it fails.
        (   R   t   get(   R	   t   name(    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   getStaticEntityL   s    c         C   s   d S(   sn   Subclass this to generate an entity on demand.

        This method should return 'None' if it fails.
        N(    (   R	   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   getDynamicEntityS   s    c         C   sE   |  j  |  } | d k	 r | S|  j | |  } | d k	 rA | Sd S(   s  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   R   t   ent(    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt	   getEntityY   s    	c         C   s   | |  j  | <d S(   sl   Store a static reference on 'name' for 'entity'.

        Raises a KeyError if the operation fails.
        N(   R   (   R	   R   t   entity(    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt	   putEntityj   s    c         C   s   |  j  | =d S(   sa   Remove a static reference for 'name'.

        Raises a KeyError if the operation fails.
        N(   R   (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt	   delEntityq   s    c         C   s    t  d t j |  j    d S(   sG   Store an entity for 'name', based on the content of 'request'.
        s   %s.storeEntityN(   R   R    R   R   (   R	   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   storeEntityx   s    c         C   s    t  d t j |  j    d S(   sH   Remove an entity for 'name', based on the content of 'request'.
        s   %s.removeEntityN(   R   R    R   R   (   R	   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   removeEntity}   s    c         C   s   |  j  j   S(   sl   Retrieve a list of all name, entity pairs that I store references to.

        See getStaticEntity.
        (   R   t   items(   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   listStaticEntities   s    c         C   s   g  S(   sa   A list of all name, entity that I can generate on demand.

        See getDynamicEntity.
        (    (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   listDynamicEntities   s    c         C   s   |  j    |  j |  S(   sU   Retrieve a list of all name, entity pairs I contain.

        See getEntity.
        (   R!   R"   (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   listEntities   s    c         C   s   |  j  j   S(   sk   Retrieve a list of the names of entities that I store references to.

        See getStaticEntity.
        (   R   t   keys(   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   listStaticNames   s    c         C   s   g  S(   sl   Retrieve a list of the names of entities that I store references to.

        See getDynamicEntity.
        (    (   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   listDynamicNames   s    c         C   s
   |  j    S(   sZ   Retrieve a list of all names for entities that I contain.

        See getEntity.
        (   R%   (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt	   listNames   s    N(   R   R   R   R   R   R   R   R   R   R   R   R   R!   R"   R#   R%   R&   R'   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR   =   s   												t   ConstraintViolationc           B   s   e  Z d  Z RS(   s7   An exception raised when a constraint is violated.
    (   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR(      s   t   Constrainedc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s?   A collection that has constraints on its names and/or entities.c         C   s   d S(   s   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.
        i   (    (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   nameConstraint   s    c         C   s   d S(   s   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.
        i   (    (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   entityConstraint   s    c         C   s   t  j |  | |  d  S(   N(   R   R   (   R	   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   reallyPutEntity   s    c         C   sP   |  j  |  r@ |  j |  r1 |  j | |  qL t d   n t d   d S(   sf   Store an entity if it meets both constraints.

        Otherwise raise a ConstraintViolation.
        s   Entity constraint violated.s   Name constraint violated.N(   R*   R+   R,   R(   (   R	   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR      s
    (   R   R   R   R*   R+   R,   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR)      s
   			t   Lockedc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s5   A collection that can be locked from adding entities.i    c         C   s   d |  _  d  S(   Ni   (   t   locked(   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   lock   s    c         C   s   |  j  S(   N(   R.   (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR+      s    (   R   R   R   R.   R/   R+   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR-      s   	t
   Homogenousc           B   s2   e  Z d  Z e j Z d   Z d   Z d   Z RS(   s   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   s3   t  | |  j  r d St d | |  j f   d  S(   Ni   s   %s of incorrect type (%s)(   t
   isinstancet
   entityTypeR(   (   R	   R   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR+      s    c         C   s   d S(   Nt   Name(    (   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   getNameType   s    c         C   s
   |  j  j S(   N(   R2   R   (   R	   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   getEntityType   s    (	   R   R   R   t   typest   InstanceTypeR2   R+   R4   R5   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyR0      s
   			(    (    (    (   R   R6   t   twisted.pythonR    R   R   R   R   R   t	   ExceptionR(   R)   R-   R0   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/python/roots.pyt   <module>	   s   r$