
    h1                        % S r SSKrSSKrSSKrSSKrSSKrSSKJr	  SSK
Jr  SSKJrJr  SSKJr  0 r\\\R&                  4   \S'   \R*                  rS rS	 rS
 r\R
                  " \R4                  \5        S rS r\R
                  " \R:                  \5        S rS r\R
                  " \R&                  \5        S r S r!S r"S r# " S S5      r$0 q%\\&S4   \S'   0 q'S r(S r)S r* " S S5      r+g)z(
Different styles of persisted objects.
    N)StringIO)Dict)logreflect)_PYPY
oldModulesc                 h    [         U R                  U R                  U R                  R                  44$ )z3support function for copy_reg to pickle method refs)unpickleMethod__name____self__	__class__)methods    _/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/persisted/styles.pypickleMethodr      s-     		&//6??+D+DE     c                     [        X5      nU$ )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     ;3Lr   c                    Uc  [        X 5      $  [        X 5      nSn[        R                  " X1/UQ76 nU$ ! [         aL    [
        R                  " SU SU5        Uc   S5       eUR                  UL a  e [        XUR                  5      s $ f = f)a3  
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))(; 
  F:F  C'>8<"M$MM" (g0A0ABBCs   6 ABBc                     U R                   S:X  a  [        SU  35      e[        [        SR	                  U R
                  U R                  /5      /5      4$ )aw  
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     	zzZ%(Gs&KLLuchhann/M&N%OPQQr   c                     SSK Jn  U" U 5      $ )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                 (    [         U R                  44$ )z3support function for copy_reg to pickle module refs)unpickleModuler   )modules    r   pickleModuler6   ~   s    FOO---r   c                     U [         ;   a8  [        R                  " SU -  5        [         U    n [        R                  " U 5        [        U 0 0 S5      $ )z5support function for copy_reg to unpickle module refszModule has moved: %sx)r   r   r   
__import__)names    r   r4   r4      sB    z&-.$dBC((r   c                 P     [         U R                  5       U R                  5       44$ )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                 ^    [        5       nUR                  U 5        UR                  U5        U$ )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GGCLFF3KHr   c                 N    [         U R                  5       U R                  5       44$ )a1  
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                 >    [        U 5      nUR                  U5        U$ )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FF3KHr   c                   *    \ rS rSrSrS rS rS rSrg)	Ephemeral   z\
This type of object is never persisted; if possible, even references to it
are eliminated.
c                     [         S4$ )z]
Serialize any subclass of L{Ephemeral} in a way which replaces it with
L{Ephemeral} itself.
r   )rN   )selfs    r   
__reduce__Ephemeral.__reduce__   s    
 2r   c                     [         R                  " SU -  5        [        (       dG  SS Kn[	        USS 5      (       a1  UR                  U 5       H  n[         R                  " SU 35        M     g )Nz!WARNING: serializing ephemeral %sr   get_referrersz referred to by )r   r   r   gcr   rU   )rQ   rV   rs      r   __getstate__Ephemeral.__getstate__   sW    3d:;ur?D11))$/AGG.qc23 0r   c                 `    [         R                  " SU R                  -  5        [        U l        g )Nz#WARNING: unserializing ephemeral %s)r   r   r   rN   rQ   states     r   __setstate__Ephemeral.__setstate__   s    5FG"r   )r   N)	r   r+   r,   __firstlineno____doc__rR   rX   r]   __static_attributes__r   r   r   rN   rN      s    
#r   rN   	VersionedversionedsToUpgradec                  j    [        [        R                  5       5       H  n [        U 5        M     0 q0 qg N)listrc   valuesrequireUpgradeupgraded)	versioneds    r   	doUpgraderk      s.    -4467	y! 8Hr   c                 z    [        U 5      nU[        ;   a&  U[        ;  a  S[        U'   U R                  5         U $ gg)z?Require that a Versioned instance be upgraded completely first.   N)idrc   ri   versionUpgrade)objobjIDs     r   rh   rh      s=    sGE##X(=
 )>#r   c                     U [         /n[        R                  " U 5       H2  nX!;  d  M
  [        U[         5      (       d  M!  UR	                  U5        M4     US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)rb   inspectgetmro
issubclassappend)clbs      r   _aybabtur{   	  sI     
IA^^A:*Q	22HHQK  QR5Lr   c                   6    \ rS rSrSrSrSrS rS
S jrS r	S	r
g)rb   i  az  
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                 4    U [         [        U 5      '   Xl        g re   )rc   rn   __dict__r[   s     r   r]   Versioned.__setstate__3  s    (,BtH%r   Nc                    [         R                   " U=(       d    U R                  5      n[        U R                  5      nUR	                  5         UR                  U R                  5        U Hg  nSUR                  ;   a  UR                   H  nXR;   d  M
  X%	 M     SUR                  ;   d  MA  UR                  U[        R                  " U5       S3'   Mi     U$ )z8Get state, adding a version number to it on its way out.persistenceForgetspersistenceVersionz.persistenceVersion)
copyr~   r{   r   reverserw   r   r   r   qual)rQ   dictdctbasesbaseslots         r   rX   Versioned.__getstate__7  s    ii-.(T^^$D#t}}4 33D{I 4 $t}}4 ++ ||D)**=>  
r   c                 x   [        U R                  5      nUR                  5         UR                  U R                  5        SU R                  ;   a  U R                  S   nU R                  S	 SnSnU H5  nSUR                  ;  a  M  UR
                  U:  d  M'  UnUR
                  nM7     U(       a&  UU R                  S[        R                  " U5      -  '   U GH[  n[        UR                  ;  a  SUR                  ;  a  M*  UR
                  nS[        R                  " U5      -  nU R                  R                  U5      =(       d    SnU(       a  U R                  U	 X::  d   S5       eX:  d  M  US-   nUR                  R                  SU-  S5      n	U	(       aj  [        R                  " S[        R                  " U5      < S	[        R                  " U R                  5      < S
[        U 5      < SU< 35        U	" U 5        O%[        R                  " SR                  XX5      5        X:  a  M  GM^     g)z (internal) Do a version upgrade.r   r   Nz%s.persistenceVersionz"Sorry, can't go backwards in time.rm   zupgradeToVersion%sz
Upgrading z (of z @ z) to version z(Warning: cannot upgrade {} to version {})r{   r   r   rw   r~   r   r   r   rb   	__bases__getr   r   rn   format)
rQ   r   pverhighestVersionhighestBaser   currentVerspverNamepersistVersr   s
             r   ro   Versioned.versionUpgradeH  s   ( 	T^^$4==0 ==!56D23NK't}}<**^;"&K%)%<%<N    +gll;.GG D /(=11K.d1CCH--++H5:KMM(+-S/SS-+)Ao**+?++MtTGG $LL.#LL8tH' 4LGGBII  ++ r   )r~   re   )r   r+   r,   r_   r`   r   r   r]   rX   ro   ra   r   r   r   rb   rb     s$    ( "?r   ),r`   r   copyregcopy_regrt   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   rc   intri   rk   rh   r{   rb   r   r   r   <module>r      s  
      %  ' '*,
De&&&' , !.. $@ 	  , /R"(& 	""O 4.
) 	  , /A*A ,# #8 /1 T#{*+ 0$l lr   