Ë
    oj1  ã                   óð  — U 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mZ	 ddl
mZ ddlmZmZ ddlmZ i Zeeej&                  f   ed<   ej*                  Zd„ Zd	„ Zd
„ Z ej
                  ej4                  e«       d„ Zd„ Z ej
                  ej:                  e«       d„ Zd„ Z ej
                  ej&                  e«       d„ Z d„ Z!d„ Z"d„ Z# G d„ d«      Z$i a%ee&df   ed<   i a'd„ Z(d„ Z)d„ Z* G d„ d«      Z+y)z(
Different styles of persisted objects.
é    N)ÚStringIO)ÚDict)ÚlogÚreflect)Ú_PYPYÚ
oldModulesc                 óh   — t         | j                  | j                  | j                  j                  ffS )z3support function for copy_reg to pickle method refs)ÚunpickleMethodÚ__name__Ú__self__Ú	__class__)Úmethods    ú:/usr/lib/python3/dist-packages/twisted/persisted/styles.pyÚpickleMethodr      s-   € ô 	Ø	�‰˜&Ÿ/™/¨6¯?©?×+DÑ+DÐEðð ó    c                 ó   — t        | |«      }|S )a³  
    Retrieve the function object implementing a method name given the class
    it's on and a method name.

    @param classObject: A class to retrieve the method's function from.
    @type classObject: L{type}

    @param methodName: The name of the method whose function to retrieve.
    @type methodName: native L{str}

    @return: the function object corresponding to the given method name.
    @rtype: L{types.FunctionType}
    )Úgetattr)ÚclassObjectÚ
methodNameÚmethodObjects      r   Ú_methodFunctionr   "   s   € ô ˜;¨
Ó3€LØÐr   c                 ó  — |€t        || «      S 	 t        || «      }d}t        j                  ||g|¢­Ž }|S # t        $ rJ t        j                  d| d|«       |€J d«       ‚|j                  |u r‚ t        | ||j                  «      cY S w xY w)aS  
    Support function for copy_reg to unpickle method refs.

    @param im_name: The name of the method.
    @type im_name: native L{str}

    @param im_self: The instance that the method was present on.
    @type im_self: L{object}

    @param im_class: The class where the method was declared.
    @type im_class: L{type} or L{None}
    © ÚMethodznot on classz'No recourse: no instance to guess from.)	r   r   ÚtypesÚ
MethodTypeÚAttributeErrorr   Úmsgr   r
   )Úim_nameÚim_selfÚim_classÚmethodFunctionÚ
maybeClassÚbounds         r   r
   r
   4   s©   € ð €Ü�x Ó)Ð)ðÜ(¨°7Ó;ˆð ˆ
Ü× Ñ  °ÐF¸:ÒFˆØˆøô ò CÜ�‰�˜' >°8Ô<ØÐ"ÐMÐ$MÓMÐ"ð ×Ñ Ñ(ØÜ˜g w°×0AÑ0AÓBÒBðCús   �7 ·AB
Â	B
c                 óª   — | j                   dk(  rt        d| › �«      ‚t        t        dj	                  | j
                  | j                  g«      g«      fS )a—  
    Reduce, in the sense of L{pickle}'s C{object.__reduce__} special method, a
    function object into its constituent parts.

    @param f: The function to reduce.
    @type f: L{types.FunctionType}

    @return: a 2-tuple of a reference to L{_unpickleFunction} and a tuple of
        its arguments, a 1-tuple of the function's fully qualified name.
    @rtype: 2-tuple of C{callable, native string}
    z<lambda>zCannot pickle lambda function: ú.)r   Ú_UniversalPicklingErrorÚ_unpickleFunctionÚtupleÚjoinÚ
__module__Ú__qualname__)Úfs    r   Ú_pickleFunctionr.   W   sL   € ð 	‡z�z�ZÒÜ%Ð(GÈÀsÐ&KÓLÐLÜœu c§h¡h°·±¸a¿n¹nÐ/MÓ&NÐ%OÓPÐQÐQr   c                 ó   — ddl m}  || «      S )aù  
    Convert a function name into a function by importing it.

    This is a synonym for L{twisted.python.reflect.namedAny}, but imported
    locally to avoid circular imports, and also to provide a persistent name
    that can be stored (and deprecated) independently of C{namedAny}.

    @param fullyQualifiedName: The fully qualified name of a function.
    @type fullyQualifiedName: native C{str}

    @return: A function object imported from the given location.
    @rtype: L{types.FunctionType}
    r   )ÚnamedAny)Útwisted.python.reflectr0   )ÚfullyQualifiedNamer0   s     r   r(   r(   h   s   € õ 0áÐ&Ó'Ð'r   c                 ó(   — t         | j                  ffS )z3support function for copy_reg to pickle module refs)ÚunpickleModuler   )Úmodules    r   ÚpickleModuler6   ~   s   € ä˜FŸO™OÐ-Ð-Ð-r   c                 óš   — | t         v r6t        j                  d| z  «       t         |    } t        j                  | «       t        | i i d«      S )z5support function for copy_reg to unpickle module refszModule has moved: %sÚx)r   r   r   Ú
__import__)Únames    r   r4   r4   ƒ   sB   € àŒzÑÜ�‰Ð&¨Ñ-Ô.Ü˜$ÑˆÜ�‰�ŒÜ�d˜B  CÓ(Ð(r   c                 óP   — 	 t         | j                  «       | j                  «       ffS )zá
    Reduce the given cStringO.

    This is only called on Python 2, because the cStringIO module only exists
    on Python 2.

    @param stringo: The string output to pickle.
    @type stringo: C{cStringIO.OutputType}
    )ÚunpickleStringOÚgetvalueÚtell)Ústringos    r   ÚpickleStringOr@   �   s'   € ð CÜ˜W×-Ñ-Ó/°·±³Ð@Ð@Ð@r   c                 ó^   — t        «       }|j                  | «       |j                  |«       |S )aÚ  
    Convert the output of L{pickleStringO} into an appropriate type for the
    current python version.  This may be called on Python 3 and will convert a
    cStringIO into an L{io.StringIO}.

    @param val: The content of the file.
    @type val: L{bytes}

    @param sek: The seek position of the file.
    @type sek: L{int}

    @return: a file-like object which you can write bytes to.
    @rtype: C{cStringIO.OutputType} on Python 2, L{io.StringIO} on Python 3.
    )Ú
_cStringIOÚwriteÚseek©ÚvalÚsekr8   s      r   r<   r<   �   s&   € ô 	‹€AØ‡G�GˆC„LØ‡F�Fˆ3„KØ€Hr   c                 óN   — t         | j                  «       | j                  «       ffS )aQ  
    Reduce the given cStringI.

    This is only called on Python 2, because the cStringIO module only exists
    on Python 2.

    @param stringi: The string input to pickle.
    @type stringi: C{cStringIO.InputType}

    @return: a 2-tuple of (C{unpickleStringI}, (bytes, pointer))
    @rtype: 2-tuple of (function, (bytes, int))
    )ÚunpickleStringIr=   r>   )Ústringis    r   ÚpickleStringIrK   ²   s#   € ô ˜W×-Ñ-Ó/°·±³Ð@Ð@Ð@r   c                 ó>   — t        | «      }|j                  |«       |S )aß  
    Convert the output of L{pickleStringI} into an appropriate type for the
    current Python version.

    This may be called on Python 3 and will convert a cStringIO into an
    L{io.StringIO}.

    @param val: The content of the file.
    @type val: L{bytes}

    @param sek: The seek position of the file.
    @type sek: L{int}

    @return: a file-like object which you can read bytes from.
    @rtype: C{cStringIO.OutputType} on Python 2, L{io.StringIO} on Python 3.
    )rB   rD   rE   s      r   rI   rI   Â   s   € ô" 	�3‹€AØ‡F�Fˆ3„KØ€Hr   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)Ú	Ephemeralzh
    This type of object is never persisted; if possible, even references to it
    are eliminated.
    c                 ó   — t         dfS )zu
        Serialize any subclass of L{Ephemeral} in a way which replaces it with
        L{Ephemeral} itself.
        r   )rN   )Úselfs    r   Ú
__reduce__zEphemeral.__reduce__Þ   s   € ô
 ˜2ˆÐr   c                 ó¾   — t        j                  d| z  «       t        s?dd l}t	        |dd «      r.|j                  | «      D ]  }t        j                  d|› �«       Œ y )Nz!WARNING: serializing ephemeral %sr   Úget_referrersz referred to by )r   r   r   Úgcr   rS   )rP   rT   Úrs      r   Ú__getstate__zEphemeral.__getstate__å   sW   € Ü�‰Ð3°dÑ:Ô;ÝÛä�r˜?¨DÔ1Ø×)Ñ)¨$Ó/ò 4�AÜ—G‘GÐ.¨q¨cÐ2Õ3ð4àr   c                 ó^   — t        j                  d| j                  z  «       t        | _        y )Nz#WARNING: unserializing ephemeral %s)r   r   r   rN   ©rP   Ústates     r   Ú__setstate__zEphemeral.__setstate__ï   s   € Ü�‰Ð5¸¿¹ÑFÔGÜ"ˆ�r   N)r   r+   r,   Ú__doc__rQ   rV   rZ   r   r   r   rN   rN   Ø   s   „ ñò
òó#r   rN   Ú	VersionedÚversionedsToUpgradec                  óf   — t        t        j                  «       «      D ]  } t        | «       Œ i ai ay ©N)Úlistr]   ÚvaluesÚrequireUpgradeÚupgraded)Ú	versioneds    r   Ú	doUpgradere   ø   s3   € äÔ-×4Ñ4Ó6Ó7ò "ˆ	Ü�yÕ!ð"àÐØ�Hr   c                 ór   — t        | «      }|t        v r$|t        vrdt        |<   | j                  «        | S yy)z?Require that a Versioned instance be upgraded completely first.é   N)Úidr]   rc   ÚversionUpgrade)ÚobjÚobjIDs     r   rb   rb      s=   € äˆs‹G€EØÔ#Ñ#¨´XÑ(=ØŒ�‰Ø×ÑÔØˆ
ð )>Ð#r   c                 óž   — | t         g}t        j                  | «      D ])  }||vsŒt        |t         «      sŒ|j	                  |«       Œ+ |dd S )z±
    Get all of the parent classes of C{c}, not including C{c} itself, which are
    strict subclasses of L{Versioned}.

    @param c: a class
    @returns: list of classes
    é   N)r\   ÚinspectÚgetmroÚ
issubclassÚappend)ÚcÚlÚbs      r   Ú_aybabturu   	  sM   € ð 
ŒIˆ€AÜ�^‰^˜AÓò ˆØ�AŠ:œ* Q¬	Õ2Ø�H‰H�Q�Kðð ˆQˆRˆ5€Lr   c                   ó,   — e Zd ZdZdZdZd„ Zdd„Zd„ Zy)	r\   a²  
    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.
    r   r   c                 ó6   — | t         t        | «      <   || _        y r_   )r]   rh   Ú__dict__rX   s     r   rZ   zVersioned.__setstate__3  s   € Ø(,ÔœB˜t›HÑ%Øˆ�r   Nc                 ó�  — t        j                   |xs | j                  «      }t        | j                  «      }|j	                  «        |j                  | j                  «       |D ]]  }d|j                  v r|j                  D ]
  }||v sŒ||= Œ d|j                  v sŒ9|j                  |t        j                  |«      › d�<   Œ_ |S )z8Get state, adding a version number to it on its way out.ÚpersistenceForgetsÚpersistenceVersionz.persistenceVersion)
Úcopyrx   ru   r   Úreverserq   rz   r{   r   Úqual)rP   ÚdictÚdctÚbasesÚbaseÚslots         r   rV   zVersioned.__getstate__7  s½   € ä�i‰i˜Ò- §¡Ó.ˆÜ˜Ÿ™Ó(ˆØ�‰ŒØ�‰�T—^‘^Ô$Øò 	,ˆDØ# t§}¡}Ñ4Ø ×3Ñ3ò &�DØ˜s’{Ø ™Ið&ð $ t§}¡}Ò4ð ×+Ñ+ð Ü—|‘| DÓ)Ð*Ð*=Ð>òð	,ð ˆ
r   c                 ó  — t        | j                  «      }|j                  «        |j                  | j                  «       d| j                  v r{| j                  d   }| j                  d= d}d}|D ]/  }d|j                  vrŒ|j
                  |kD  sŒ"|}|j
                  }Œ1 |r%|| j                  dt        j                  |«      z  <   |D �]<  }t        |j                  vrd|j                  vrŒ%|j
                  }dt        j                  |«      z  }| j                  j                  |«      xs d}|r| j                  |= ||k  sJ d«       ‚||k  sŒ‰|dz   }|j                  j                  d|z  d«      }	|	rct        j                  dt        j                  |«      ›d	t        j                  | j                  «      ›d
t        | «      ›d|›�«        |	| «       n%t        j                  dj                  ||«      «       ||k  rŒ´�Œ? y)z (internal) Do a version upgrade.r{   r   Nz%s.persistenceVersionz"Sorry, can't go backwards in time.rg   zupgradeToVersion%sz
Upgrading z (of z @ z) to version z(Warning: cannot upgrade {} to version {})ru   r   r}   rq   rx   r{   r   r~   r\   Ú	__bases__Úgetr   r   rh   Úformat)
rP   r�   ÚpverÚhighestVersionÚhighestBaser‚   ÚcurrentVersÚpverNameÚpersistVersr   s
             r   ri   zVersioned.versionUpgradeH  sç  € ä˜Ÿ™Ó(ˆð 	�‰ŒØ�‰�T—^‘^Ô$à 4§=¡=Ñ0ð —=‘=Ð!5Ñ6ˆDØ—‘Ð2Ð3ØˆNØˆKØò =�Ø'¨t¯}©}Ñ<ØØ×*Ñ*¨^Ó;Ø"&�KØ%)×%<Ñ%<‘Nð=ñ ð ð —‘Ø+¬g¯l©l¸;Ó.GÑGñð ó  	ˆDô  §¡Ñ/Ø(°·±Ñ=àØ×1Ñ1ˆKØ.´·±¸dÓ1CÑCˆHØŸ-™-×+Ñ+¨HÓ5Ò:¸ˆKÙØ—M‘M (Ð+Ø +Ò-ÐSÐ/SÓSÐ-Ø Ó+Ø)¨A™o�ØŸ™×*Ñ*Ð+?À+Ñ+MÈtÓT�ÙÜ—G’Gô $ŸL™L¨Õ.Ü#ŸL™L¨¯©Õ8Ü˜t�HÙ'ðôñ ˜4•Lä—G‘GØB×IÑIØ  +óôð  Õ+ñ 	r   r_   )	r   r+   r,   r[   r{   rz   rZ   rV   ri   r   r   r   r\   r\     s$   „ ñð( ÐØÐòóó"?r   ),r[   r|   ÚcopyregÚcopy_regrn   Úpickler   Úior   rB   Útypingr   Útwisted.pythonr   r   Útwisted.python.compatr   r   ÚstrÚ
ModuleTypeÚ__annotations__ÚPicklingErrorr'   r   r   r
   r   r.   r(   ÚFunctionTyper6   r4   r@   r<   rK   rI   rN   r]   Úintrc   re   rb   ru   r\   r   r   r   ú<module>r›      s  ðò
ó Û Û Û Û Ý %Ý ç 'Ý 'à*,€
ˆD��e×&Ñ&Ð&Ñ'Ó ,ð !×.Ñ.Ð òòò$ð@ €‡��× Ñ  ,Ô /òRò"(ð& €‡��×"Ñ" OÔ 4ò.ò
)ð €‡��× Ñ  ,Ô /òAòò*Aò ÷,#ñ #ð8 /1Ð �T˜#˜{Ð*Ñ+Ó 0Ø€òòò÷$lò lr   