ó
[³XMc           @   sÉ  d  Z  d d l Z d d l Z d d l Z y d d l Z Wn e k
 rY d d l Z n Xd d l m Z y d d l	 m
 Z
 Wn d d l m Z e Z
 n Xi  Z d „  Z d „  Z e j e j e e ƒ d „  Z d	 „  Z e j e j e e ƒ d
 „  Z d „  Z e e d ƒ r.e j e j e e ƒ n  d „  Z d „  Z e e d ƒ rhe j e j e e ƒ n  d d d „  ƒ  YZ i  a i  a d „  Z d „  Z  d d l m! Z! d „  Z" d d d „  ƒ  YZ# d S(   s(   
Different styles of persisted objects.
iÿÿÿÿN(   t   log(   t   instancemethod(   t   PyMethodc         C   s   t  |  j j |  j |  j f f S(   s3   support function for copy_reg to pickle method refs(   t   unpickleMethodt   im_funct   __name__t   im_selft   im_class(   t   method(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   pickleMethod#   s    c         C   sÊ   y< t  | |  ƒ } | d k r" | St | j | | ƒ } | SWn‡ t k
 rÅ t j d |  d | ƒ | d k	 sw t d ‚ t  | j |  ƒ } t j d | ƒ | d k r© | St | j | | j ƒ } | SXd S(   s5   support function for copy_reg to unpickle method refst   Methods   not on classs'   No recourse: no instance to guess from.s   Attempting fixup withN(	   t   getattrt   NoneR   R   t   AttributeErrorR    t   msgt   AssertionErrort	   __class__(   t   im_nameR   R   t   unboundt   bound(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR   )   s&    			c         C   s   t  |  j f f S(   s3   support function for copy_reg to pickle module refs(   t   unpickleModuleR   (   t   module(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   pickleModuleH   s    c         C   sM   t  j |  ƒ r: t j d |  ƒ t  |  }  t j |  ƒ n  t |  i  i  d ƒ S(   s5   support function for copy_reg to unpickle module refss   Module has moved: %st   x(   t
   oldModulest   has_keyR    R   t
   __import__(   t   name(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR   L   s
    
c         C   s   t  |  j ƒ  |  j ƒ  f f S(   s<   support function for copy_reg to pickle StringIO.OutputTypes(   t   unpickleStringOt   getvaluet   tell(   t   stringo(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   pickleStringOY   s    c         C   s*   t  j  ƒ  } | j |  ƒ | j | ƒ | S(   N(   t   StringIOt   writet   seek(   t   valt   sekR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR   ]   s    t
   OutputTypec         C   s   t  |  j ƒ  |  j ƒ  f f S(   N(   t   unpickleStringIR   R   (   t   stringi(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   pickleStringIh   s    c         C   s    t  j  |  ƒ } | j | ƒ | S(   N(   R!   R#   (   R$   R%   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR'   k   s    t	   InputTypet	   Ephemeralc           B   s    e  Z d  Z d „  Z d „  Z RS(   sh   
    This type of object is never persisted; if possible, even references to it
    are eliminated.
    c         C   sd   t  j d |  ƒ d d  l } t | d d  ƒ r` x. | j |  ƒ D] } t  j d | f ƒ q? Wn  d  S(   Ns!   WARNING: serializing ephemeral %siÿÿÿÿt   get_referrerss    referred to by %s(   R    R   t   gcR   R   R,   (   t   selfR-   t   r(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   __getstate__|   s    c         C   s!   t  j d |  j ƒ t |  _ d  S(   Ns#   WARNING: unserializing ephemeral %s(   R    R   R   R+   (   R.   t   state(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   __setstate__„   s    (   R   t
   __module__t   __doc__R0   R2   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR+   v   s   	c          C   s1   x t  j ƒ  D] }  t |  ƒ q Wi  a  i  a d  S(   N(   t   versionedsToUpgradet   valuest   requireUpgradet   upgraded(   t	   versioned(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt	   doUpgradeŒ   s    c         C   s@   t  |  ƒ } | t k r< | t k r< d t | <|  j ƒ  |  Sd S(   sD   Require that a Versioned instance be upgraded completely first.
    i   N(   t   idR5   R8   t   versionUpgrade(   t   objt   objID(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR7   “   s
    

(   t   reflectc         C   sO   g  } xB t  j |  t ƒ D]. } | | k r | t k	 r | j | ƒ q q W| S(   N(   R?   t   allYourBaset	   Versionedt   append(   t   ct   lt   b(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   _aybabtuž   s
    RA   c           B   s8   e  Z d  Z d Z d Z d „  Z d d „ Z d „  Z RS(   s²  
    This type of object is persisted with versioning information.

    I have a single class attribute, the int persistenceVersion.  After I am
    unserialized (and styles.doUpgrade() is called), self.upgradeToVersionX()
    will be called for each version upgrade I must undergo.

    For example, if I serialize an instance of a Foo(Versioned) at version 4
    and then unserialize it when the code is at version 9, the calls::

      self.upgradeToVersion5()
      self.upgradeToVersion6()
      self.upgradeToVersion7()
      self.upgradeToVersion8()
      self.upgradeToVersion9()

    will be made.  If any of these methods are undefined, a warning message
    will be printed.
    i    c         C   s   |  t  t |  ƒ <| |  _ d  S(   N(   R5   R;   t   __dict__(   R.   R1   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR2   ¼   s    c         C   sÇ   t  j  | p |  j ƒ } t |  j ƒ } | j ƒ  | j |  j ƒ x | D]w } | j j d ƒ r x- | j D] } | j | ƒ rj | | =qj qj Wn  | j j d ƒ rH | j | d t	 j
 | ƒ <qH qH W| S(   sA   Get state, adding a version number to it on its way out.
        t   persistenceForgetst   persistenceVersions   %s.persistenceVersion(   t   copyRG   RF   R   t   reverseRB   R   RH   RI   R?   t   qual(   R.   t   dictt   dctt   basest   baset   slot(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR0   À   s    
!c   
   	   C   sÿ  t  |  j ƒ } | j ƒ  | j |  j ƒ |  j j d ƒ rÎ |  j d } |  j d =d } d	 } xG | D]? } | j j d ƒ sƒ qe n  | j | k re | } | j } qe qe W| rÎ | |  j d t j	 | ƒ <qÎ n  x*| D]"} t
 | j k r| j j d ƒ rqÕ n  | j } d t j	 | ƒ } |  j j | ƒ p4d } | rJ|  j | =n  | | k s_t d ‚ x• | | k  rö| d } | j j d | d	 ƒ }	 |	 rÜt j d t j	 | ƒ t j	 |  j ƒ t |  ƒ | f ƒ |	 |  ƒ qbt j d | | f ƒ qbWqÕ Wd	 S(
   s)   (internal) Do a version upgrade.
        RI   i    s   %s.persistenceVersions"   Sorry, can't go backwards in time.i   s   upgradeToVersion%ss'   Upgrading %s (of %s @ %s) to version %ss(   Warning: cannot upgrade %s to version %sN(   RF   R   RK   RB   RG   R   R   RI   R?   RL   RA   t	   __bases__t   getR   R    R   R;   (
   R.   RO   t   pvert   highestVersiont   highestBaseRP   t   currentVerst   pverNamet   persistVersR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR<   Ð   sB    


 	
8(    N(	   R   R3   R4   RI   RH   R2   R   R0   R<   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyRA   ¥   s   	(    (    ($   R4   t   typest   copy_regRJ   t	   cStringIOR!   t   ImportErrort   twisted.pythonR    t   newR   t   org.python.coreR   R   R	   R   t   picklet
   MethodTypeR   R   t
   ModuleTypeR    R   t   hasattrR&   R)   R'   R*   R+   R5   R8   R:   R7   R?   RF   RA   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   <module>	   sX   
							
		
				