ó
i¸gNc           @   s­  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z y d d l Z Wn e k
 rq d d l Z n Xd d l	 m
 Z
 d d l	 m Z i  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 ƒ r\e j e j e e ƒ n  d d d „  ƒ  YZ i  a i  a d „  Z d „  Z d „  Z  d d d „  ƒ  YZ! d S(   s(   
Different styles of persisted objects.
iÿÿÿÿN(   t   log(   t   reflectc         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 | j | | ƒ } | SWn t k
 rÎ t j d |  d | ƒ | d k	 s} t d ƒ ‚ t  | j	 |  ƒ } t j d | ƒ | d k r¯ | St j | 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   Nonet   typest
   MethodTypeR   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   pickleModuleA   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   E   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   pickleStringOR   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   V   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   pickleStringIa   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(   d   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   sv   t  j d |  ƒ d d  l } d t j k rr t | d d  ƒ rr x. | j |  ƒ D] } t  j d | f ƒ qN Wqr n  d  S(   Ns!   WARNING: serializing ephemeral %siÿÿÿÿt   __pypy__t   get_referrerss    referred to by %s(   R    R   t   gct   syst   builtin_module_namesR
   R   R.   (   t   selfR/   t   r(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   __getstate__u   s    c         C   s!   t  j d |  j ƒ t |  _ d  S(   Ns#   WARNING: unserializing ephemeral %s(   R    R   R   R,   (   R2   t   state(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   __setstate__~   s    (   R   t
   __module__t   __doc__R4   R6   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR,   o   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   idR9   R<   t   versionUpgrade(   t   objt   objID(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR;      s
    

c         C   sY   |  t  g } xB t j |  ƒ D]1 } | | k r t | t  ƒ r | j | ƒ q q W| d S(   s4  
    Get all of the parent classes of C{c}, not including C{c} itself, which are
    strict subclasses of L{Versioned}.

    The name comes from "all your base are belong to us", from the deprecated
    L{twisted.python.reflect.allYourBase} function.

    @param c: a class
    @returns: list of classes
    i   (   t	   Versionedt   inspectt   getmrot
   issubclasst   append(   t   ct   lt   b(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   _aybabtu–   s
    RC   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(   R9   R?   t   __dict__(   R2   R5   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR6   Á   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   copyRL   RK   R   t   reverseRG   R   RM   RN   R   t   qual(   R2   t   dictt   dctt   basest   baset   slot(    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR4   Å   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 sbt d ƒ ‚ x• | | k  rù| d } | j j d | d	 ƒ }	 |	 rßt j d t j	 | ƒ t j	 |  j ƒ t |  ƒ | f ƒ |	 |  ƒ qet j d | | f ƒ qeWqÕ Wd	 S(
   s)   (internal) Do a version upgrade.
        RN   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(   RK   R   RP   RG   RL   R   R   RN   R   RQ   RC   t	   __bases__t   getR   R    R   R?   (
   R2   RT   t   pvert   highestVersiont   highestBaseRU   t   currentVerst   pverNamet   persistVersR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyR@   Õ   sB    


 	
8(    N(	   R   R7   R8   RN   RM   R6   R   R4   R@   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyRC   ª   s   	(    (    ("   R8   R   t   copy_regRO   RD   R0   t	   cStringIOR"   t   ImportErrort   twisted.pythonR    R   R   R   R   t   pickleR   R   R   t
   ModuleTypeR!   R   t   hasattrR'   R*   R(   R+   R,   R9   R<   R>   R;   RK   RC   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/persisted/styles.pyt   <module>	   sR   							
		
				