ó
[³XMc           @   sŠ  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d k Z e Z d e j f d „  ƒ  YZ e ƒ  Z d e j f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ i e e j 6e e j 6e e j 6e e j 6e e j 6e e j  6e e j! 6e e j" 6e e j# 6e e j$ 6e e j% 6e e j& 6e e j' 6e e j( 6e e j) 6Z* d e j+ f d „  ƒ  YZ, d  d& d! „  ƒ  YZ- d" d' d# „  ƒ  YZ. d$ d( d% „  ƒ  YZ/ d S()   s  Support for python object introspection and exploration.

Note that Explorers, what with their list of attributes, are much like
manhole.coil.Configurables.  Someone should investigate this further. (TODO)

Also TODO: Determine how much code in here (particularly the function
signature stuff) can be replaced with functions available in the
L{inspect} module available in Python 2.1.
iÿÿÿÿN(   t   pb(   t   reflecti   t   Poolc           B   s   e  Z d  „  Z RS(   c         C   s{   t  | ƒ } |  j j | ƒ r) |  j | St j t | ƒ t ƒ } t j | i  ƒ } | |  j | <| j	 | | | ƒ | Sd  S(   N(
   t   idt   datat   has_keyt	   typeTablet   gett   typet   ExplorerGenerict   newt   instancet   __init__(   t   selft   objectt
   identifiert   oidt   klasst   e(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   getExplorer   s    (   t   __name__t
   __module__R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR      s   t   Explorerc           B   sJ   e  Z d  d g Z g  Z d g Z d Z d Z d „  Z d „  Z	 d „  Z
 RS(   R   R   t   get_refcountc         C   s‹   | |  _  | |  _ t | ƒ |  _ g  |  _ t j |  j d |  j ƒ g  |  _ t j |  j d |  j ƒ g  |  _ t j |  j d |  j ƒ d  S(   Nt
   propertiest   attributeGroupst	   accessors(	   R   R   R   R   R   t   accumulateClassListt	   __class__R   R   (   R   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   5   s    			
	
	c         C   sƒ   d d d g } | j  |  j ƒ | j  |  j ƒ i  } x! | D] } t |  | ƒ | | <q< Wt j | |  ƒ | d <|  j j | d <| S(   NR   R   R   t   viewt   explorerClass(   t   extendR   R   t   getattrR    t	   ViewPointR   R   (   R   t   perspectivet   allt   statet   key(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   getStateToCopyForF   s    c         C   s   t  j |  ƒ S(   N(   t   syst   getrefcount(   R   R"   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   view_get_refcountS   s    N(   R   R   R   R   R   t   NoneR   R   R   R&   R)   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   -   s   			R	   c           B   s    e  Z d  d d g Z d „  Z RS(   t   strt   reprt   typenamec         C   sG   t  j |  | | ƒ t | ƒ |  _ t | ƒ |  _ t | ƒ j |  _ d  S(   N(   R   R   R+   R,   R   R   R-   (   R   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   Y   s    (   R   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR	   V   s   t   ExplorerImmutablec           B   s   e  Z d  g Z d „  Z RS(   t   valuec         C   s    t  j |  | | ƒ | |  _ d  S(   N(   R   R   R/   (   R   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   c   s    (   R   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR.   `   s   	t   ExplorerSequencec           B   s>   e  Z d  g Z d g Z d g Z d „  Z d „  Z d „  Z RS(   t   lent   elementst   get_elementsc         C   s8   t  j |  | | ƒ | |  _ t | ƒ |  _ g  |  _ d  S(   N(   R   R   t   seqR1   R2   (   R   R4   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   m   s    	c         C   si   t  |  j ƒ |  _  g  } xJ t |  j  ƒ D]9 } d |  j | f } | j t j |  j | | ƒ ƒ q( W| S(   Ns   %s[%s](   R1   R4   t   xrangeR   t   appendt   explorerPoolR   (   R   t   lt   iR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR3   u   s    $c         C   s
   |  j  ƒ  S(   N(   R3   (   R   R"   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   view_get_elements€   s    (   R   R   R   R   R   R   R3   R:   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR0   h   s   					t   ExplorerMappingc           B   sJ   e  Z d  g Z d g Z d d g Z d „  Z d „  Z d „  Z d „  Z RS(   R1   t   keyst   get_keyst   get_itemc         C   s8   t  j |  | | ƒ | |  _ t | ƒ |  _ g  |  _ d  S(   N(   R   R   t   dctR1   R<   (   R   R?   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   Š   s    	c         C   sr   |  j  j ƒ  } t | ƒ |  _ g  } xG t |  j ƒ D]6 } d |  j | f } | j t j | | | ƒ ƒ q4 W| S(   Ns   %s.keys()[%s](   R?   R<   R1   R5   R   R6   R7   R   (   R   R<   R8   R9   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR=   “   s    !c         C   s
   |  j  ƒ  S(   N(   R=   (   R   R"   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   view_get_keysŸ   s    c         C   s]   t  | ƒ t j k r! | j } n  |  j | } d |  j t | ƒ f } t j | | ƒ } | S(   Ns   %s[%s](	   R   t   typest   InstanceTypeR   R?   R   R,   R7   R   (   R   R"   R%   t   itemR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   view_get_item£   s    (	   R   R   R   R   R   R   R=   R@   RD   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR;   …   s   						t   ExplorerBuiltinc           B   s&   e  Z d  Z d d d g Z d „  Z RS(   sÂ   
    @ivar name: the name the function was defined as
    @ivar doc: function's docstring, or C{None} if unavailable
    @ivar self: if not C{None}, the function is a method of this object.
    t   doct   nameR   c         C   s;   t  j |  | | ƒ | j |  _ | j |  _ | j |  _ d  S(   N(   R   R   t   __doc__RF   R   RG   t   __self__R   (   R   t   functionR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   ¶   s    (   R   R   RH   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRE   ¯   s   t   ExplorerInstancec           B   s,   e  Z d  Z d g Z d d g Z d „  Z RS(   sq  
    Attribute groups:
        - B{methods} -- dictionary of methods
        - B{data} -- dictionary of data members

    Note these are only the *instance* methods and members --
    if you want the class methods, you'll have to look up the class.

    TODO: Detail levels (me, me & class, me & class ancestory)

    @ivar klass: the class this is an instance of.
    R   t   methodsR   c   	      C   sò   t  j |  | | ƒ i  } i  } x› t | ƒ D] } | d d k rH q, n  t j | | g d ƒ } t | | ƒ } t | ƒ } | t j k r£ t	 j
 | | ƒ | | <q, t	 j
 | | ƒ | | <q, Wt	 j
 | j |  j d ƒ |  _ | |  _ | |  _ d  S(   Ni    t   _t   .s
   .__class__(   R   R   t   dirt   stringt   joinR    R   RA   t
   MethodTypeR7   R   R   R   R   R   RL   (	   R   R   R   t   membersRL   R9   t   mIdentifiert   membert   mType(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   Í   s"    	(   R   R   RH   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRK   ½   s   	t   ExplorerClassc           B   s5   e  Z d  Z d d d d g Z d d g Z d „  Z RS(   s6  
    @ivar name: the name the class was defined with
    @ivar doc: the class's docstring
    @ivar bases: a list of this class's base classes.
    @ivar module: the module the class is defined in

    Attribute groups:
        - B{methods} -- class methods
        - B{data} -- other members of the class
    RG   RF   t   basest   moduleRL   R   c   	      C   s@  t  j |  | | ƒ | s% | j } n  i  } i  } x§ t | ƒ D]™ } | d d k rf | d k rf q> n  t j | | g d ƒ } t | | ƒ } t | ƒ } | t j	 k rÁ t
 j | | ƒ | | <q> t
 j | | ƒ | | <q> W| j |  _ t j | ƒ |  _ | |  _ | |  _ t
 j | j | d ƒ |  _ t | d d  ƒ |  _ d  S(   Ni    RM   R   RN   s
   .__bases__R   (   R   R   R   RO   RP   RQ   R    R   RA   RR   R7   R   RG   t   inspectt   getdocRF   R   RL   t	   __bases__RX   R*   RY   (	   R   t   theClassR   RS   RL   R9   RT   RU   RV   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   ò   s*    		(   R   R   RH   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRW   å   s   
t   ExplorerFunctionc           B   s&   e  Z d  d d d d g Z d „  Z RS(   RG   RF   t   filet   linet	   signaturec         C   sc  t  j |  | | ƒ | j } | j } | j d @o5 d } | j d @oH d } | | | } t | j |  ƒ } | j rè d }	 xj t | t	 | j ƒ | ƒ D]I }
 | j |	 } t
 j | d | |	 f ƒ } | j |
 | ƒ |	 d }	 q˜ Wn  | r| j | d ƒ n  | r | j | d | ƒ n  | j |  _ | |  _ t j | ƒ |  _ | j |  _ | j |  _ d  S(   Ni   i   i   i    s   %s.func_defaults[%d](   R   R   t	   func_codet   co_argcountt   co_flagst	   Signaturet   co_varnamest   func_defaultsR5   R1   R7   R   t   set_defaultt   set_keywordt   set_varlistR   RG   Ra   RZ   R[   RF   t   co_filenameR_   t   co_firstlinenoR`   (   R   RJ   R   t   codet   argcountt	   takesListt   takesKeywordst   nRa   t   i_dR9   t   default(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR     s2    				(   R   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR^     s   t   ExplorerMethodc           B   s   e  Z d  d g Z d „  Z RS(   R   R   c         C   s¤   | j  } t | ƒ t j k r- | j j  } n  t j |  | | ƒ t | ƒ |  _ t j	 | j
 | d ƒ |  _ t j	 | j | d ƒ |  _ | j r  |  j j ƒ  n  d  S(   Ns	   .im_classs   .im_self(   t   im_funcR   RA   RB   t   __call__R^   R   R   R7   R   t   im_classR   t   im_selfR   Ra   t   discardSelf(   R   t   methodR   RJ   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   D  s    		(   R   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRt   =  s   t   ExplorerModulec           B   s5   e  Z d  Z d d d g Z d d d g Z d „  Z RS(   sÄ  
    @ivar name: the name the module was defined as
    @ivar doc: documentation string for the module
    @ivar file: the file the module is defined in

    Attribute groups:
        - B{classes} -- the public classes provided by the module
        - B{functions} -- the public functions provided by the module
        - B{data} -- the public data members provided by the module

    ("Public" is taken to be "anything that doesn't start with _")
    RG   RF   R_   t   classest	   functionsR   c   	      C   sG  t  j |  | | ƒ i  } i  } i  } xÍ | j j ƒ  D]¼ \ } } | d d k rW q5 n  d | | f } t | ƒ t j k r• t j | | ƒ | | <q5 t | ƒ t j	 k rÃ t j | | ƒ | | <q5 t | ƒ t j
 k rÛ q5 t j | | ƒ | | <q5 W| j |  _ t j | ƒ |  _ t | d d  ƒ |  _ | |  _ | |  _ | |  _ d  S(   Ni    RM   s   %s.%st   __file__(   R   R   t   __dict__t   itemsR   RA   t	   ClassTypeR7   R   t   FunctionTypet
   ModuleTypeR   RG   RZ   R[   RF   R    R*   R_   R|   R}   R   (	   R   RY   R   R}   R|   R   R%   R/   RT   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   f  s.    				(   R   R   RH   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR{   V  s   Re   c           B   s’   e  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 „  Z d „  Z d „  Z d „  Z RS(   s   I represent the signature of a callable.

    Signatures are immutable, so don't expect my contents to change once
    they've been set.
    i   i   i   c         C   s9   | |  _  d  g t | ƒ |  _ d  g t | ƒ |  _ d  S(   N(   RG   R*   R1   Rs   t   flavour(   R   t   argNames(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   Ÿ  s    	c         C   s   |  j  | S(   N(   RG   (   R   t   arg(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   get_name¤  s    c         C   sY   | t  j k r$ |  j j | ƒ } n  |  j | |  j k rK t |  j | f St d  f Sd  S(   N(
   RA   t
   StringTypeRG   t   indexR„   t   _HAS_DEFAULTt   TrueRs   t   FalseR*   (   R   R†   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   get_default§  s
    c         C   sE   | t  j k r$ |  j j | ƒ } n  |  j |  j | <| |  j | <d  S(   N(   RA   Rˆ   RG   R‰   RŠ   R„   Rs   (   R   R†   R/   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRh   ³  s    c         C   s8   | t  j k r$ |  j j | ƒ } n  |  j |  j | <d  S(   N(   RA   Rˆ   RG   R‰   t	   _VAR_LISTR„   (   R   R†   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRj   º  s    c         C   s8   | t  j k r$ |  j j | ƒ } n  |  j |  j | <d  S(   N(   RA   Rˆ   RG   R‰   t   _KEYWORD_DICTR„   (   R   R†   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRi   À  s    c         C   s8   | t  j k r$ |  j j | ƒ } n  |  j | |  j k S(   N(   RA   Rˆ   RG   R‰   R„   RŽ   (   R   R†   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt
   is_varlistÆ  s    c         C   s8   | t  j k r$ |  j j | ƒ } n  |  j | |  j k S(   N(   RA   Rˆ   RG   R‰   R„   R   (   R   R†   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt
   is_keywordÌ  s    c         C   s4   |  j  d |  _  |  j j d ƒ |  j j d ƒ d S(   sK   Invoke me to discard the first argument if this is a bound method.
        i   i    N(   RG   Rs   t   popR„   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRy   Ò  s    c         C   s4   i t  |  j ƒ d 6t  |  j ƒ d 6t  |  j ƒ d 6S(   NRG   R„   Rs   (   t   tupleRG   R„   Rs   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   getStateToCopyÜ  s    c         C   s   t  |  j ƒ S(   N(   R1   RG   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   __len__á  s    c         C   sÁ   g  } x¨ t  t |  ƒ ƒ D]” } |  j | ƒ } |  j | ƒ \ } } | r\ d | | f } nD |  j | ƒ r{ d | f } n% |  j | ƒ rš d | f } n | } | j | ƒ q Wt j | d ƒ S(   Ns   %s=%ss   *%ss   **%ss   , (	   R5   R1   R‡   R   R   R‘   R6   RP   RQ   (   R   t   arglistR†   RG   t
   hasDefaultRs   t   a(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   __str__ä  s    N(   R   R   RH   R*   t   _FLAVOURLESSRŠ   RŽ   R   R   R‡   R   Rh   Rj   Ri   R   R‘   Ry   R”   R•   R™   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRe   ”  s"   									
		t   CRUFT_WatchyThingiec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s+   t  | |  j |  j ƒ } |  j | | | ƒ S(   så   Watch the object returned by evaluating the identifier.

        Whenever I think the object might have changed, I'll send an
        ObjectLink of it to the callback.

        WARNING: This calls eval() on its argument!
        (   t   evalt   globalNamespacet   localNamespacet   watchObject(   R   R   t   callbackR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   watchIdentifier  s    c         C   s9  t  | ƒ t j k	 r! t d ‚ n  i  } t j | j | d ƒ x! | j j ƒ  D] } d | | <qM W| j ƒ  } i  } t	 j
 d | j j t | ƒ f t | j f | ƒ } t	 j | |  | d „ d | ƒ | d <| | _ x] | D]U }	 t | |	 ƒ }
 t  |
 ƒ t j k rÜ |
 j d k	 rÜ t | ƒ } | j |	 ƒ qÜ qÜ Wd S(   s  Watch the given object.

        Whenever I think the object might have changed, I'll send an
        ObjectLink of it to the callback.

        The identifier argument is used to generate identifiers for
        objects which are members of this one.
        s+   Sorry, can only place a watch on Instances.t    i   s   Watching%s%Xc         S   s   | | j  |  | ƒ ƒ S(   N(   t   browseObject(   t   slfR9   t   bt   cb(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   <lambda>.  s    t   _watchEmitChangedN(   R   RA   RB   t	   TypeErrorR   t   addMethodNamesToDictR   R   R<   R
   t   classobjR   R   t   _MonkeysSetattrMixint   instancemethodR*   R    RR   Rx   t   _WatchMonkeyt   install(   R   R   R   R    R?   t   kRS   t   clazzNSt   clazzRG   t   mt   monkey(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRŸ     s,    				(   R   R   R¡   RŸ   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR›   ù  s   	R®   c           B   s8   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z RS(   s¶   I hang on a method and tell you what I see.

    TODO: Aya!  Now I just do browseObject all the time, but I could
    tell you what got called with what when and returning what.
    c         C   s   | |  _  d S(   s7   Make a monkey to hang on this instance object.
        N(   R   (   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR   R  s    c         C   s_   t  |  j | d ƒ } | |  k	 r[ t j |  |  j |  j j ƒ |  j j | <| | f |  _ n  d S(   s?   Install myself on my instance in place of this method.
        N(   R    R   R*   R
   R­   R   R   t	   oldMethod(   R   t   methodIdentifierRµ   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR¯   W  s
    c         C   se   |  j  d k r d S|  j  d d k r@ t |  j |  j  d ƒ n! t |  j |  j  d |  j  d ƒ d S(   s]   Remove myself from this instance and restore the original method.

        (I hope.)
        Ni   i    (   Rµ   R*   t   delattrR   t   setattr(   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt	   uninstalld  s
    c         O   s=   |  j  d r) t |  j  d | | ƒ } n d } | j ƒ  | S(   s@   Pretend to be the method I replaced, and ring the bell.
        i   N(   Rµ   t   applyR*   R¨   (   R   R   R˜   t   kwt   rval(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyRv   s  s
    
N(	   R   R   RH   R*   Rµ   R   R¯   R¹   Rv   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR®   J  s   			R¬   c           B   s   e  Z d  Z d „  Z RS(   sD   A mix-in class providing __setattr__ for objects being watched.
    c         C   sT   t  |  j j d d ƒ r9 |  j j d j |  | | ƒ n | |  j | <|  j ƒ  d S(   s-   Set the attribute and ring the bell.
        i   t   __setattr__N(   t   hasattrR   R\   R½   R   R¨   (   R   R°   t   v(    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR½   ‚  s     (   R   R   RH   R½   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyR¬     s   (    (    (    (0   RH   RZ   R
   RP   R'   RA   t   UserDictt   twisted.spreadR    t   twisted.pythonR   R‹   RŒ   R   R7   t	   CacheableR   R	   R.   R0   R;   RE   RK   RW   R^   Rt   R{   RB   R   RR   R‚   Rƒ   t   BuiltinFunctionTypet   ListTypet	   TupleTypet   DictTypeRˆ   t   NoneTypet   IntTypet	   FloatTypet   LongTypet   ComplexTypeR   t   CopyableRe   R›   R®   R¬   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/manhole/explorer.pyt   <module>   sL   <	)
*()/-












eQ5