
    h                        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  SSKJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJrJrJr  SS
KJrJr  \4rSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'Sr(Sr)Sr*Sr+Sr,\" \" SSSS5      SSS5        Sr-0 q.0 q/S r0S r1S  r2S! r3S" r4S8S# jr5S$ r6S% r7 " S& S'5      r8\	" \5       " S( S)5      5       r9\	" \5       " S* S+5      5       r: " S, S-5      r; " S. S/5      r< " S0 S1\=5      r> " S2 S35      r? " S4 S55      r@\@" 5       rA\AR                  5         \?" 5       SS4S6 jrC\?" 5       SS4S7 jrDg)9aM  
S-expression-based persistence of python objects.

It does something very much like L{Pickle<pickle>}; however, pickle's main goal
seems to be efficiency (both in space and time); jelly's main goals are
security, human readability, and portability to other environments.

This is how Jelly converts various objects to s-expressions.

Boolean::
    True --> ['boolean', 'true']

Integer::
    1 --> 1

List::
    [1, 2] --> ['list', 1, 2]

String::
    "hello" --> "hello"

Float::
    2.3 --> 2.3

Dictionary::
    {'a': 1, 'b': 'c'} --> ['dictionary', ['b', 'c'], ['a', 1]]

Module::
    UserString --> ['module', 'UserString']

Class::
    UserString.UserString --> ['class', ['module', 'UserString'], 'UserString']

Function::
    string.join --> ['function', 'join', ['module', 'string']]

Instance: s is an instance of UserString.UserString, with a __dict__
{'data': 'hello'}::
    ["UserString.UserString", ['dictionary', ['data', 'hello']]]

Class Method: UserString.UserString.center::
    ['method', 'center', ['None'], ['class', ['module', 'UserString'],
     'UserString']]

Instance Method: s.center, where s is an instance of UserString.UserString::
    ['method', 'center', ['instance', ['reference', 1, ['class',
    ['module', 'UserString'], 'UserString']], ['dictionary', ['data', 'd']]],
    ['dereference', 1]]

The Python 2.x C{sets.Set} and C{sets.ImmutableSet} classes are
serialized to the same thing as the builtin C{set} and C{frozenset}
classes.  (This is only relevant if you are communicating with a
version of jelly running on an older version of Python.)

@author: Glyph Lefkowitz

    N)reduce)implementer)Version)NotKnown
_Container_Dereference_DictKeyAndValue_InstanceMethod_Tuple)nativeString)deprecatedModuleAttribute)namedAnynamedObjectqual)
IJellyableIUnjellyable   None   class   module   functions   dereferences
   persistents	   references
   dictionarys   list   sets   tuples   instance	   frozensetTwisted   z'instance_atom is unused within Twisted.ztwisted.spread.jellyinstance_atoms   unpersistablec                 P    [        U [        5      (       a  U R                  U 5      $ g)a}  
Given an object, if that object is a type, return a new, blank instance
of that type which has not had C{__init__} called on it.  If the object
is not a type, return L{None}.

@param cls: The type (or class) to create an instance of.
@type cls: L{type} or something else that cannot be
    instantiated.

@return: a new blank instance or L{None} if C{cls} is not a class or type.
N)
isinstancetype__new__)clss    [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/spread/jelly.py_createBlankr"      s%     #t{{3     c                 T   ^ [        U 5      mU4S jn[        TSU5      nU" U5        T$ )z
Make a new instance of a class without calling its __init__ method.

@param state: A C{dict} used to update C{inst.__dict__} either directly or
    via C{__setstate__}, if available.

@return: A new instance of C{cls}.
c                 R   > [        U [        5      (       a  U =(       d    0 Tl        g g N)r   dict__dict__)stateinstances    r!   defaultSetter#_newInstance.<locals>.defaultSetter   s!    eT"" %H #r#   __setstate__)r"   getattr)r    r)   r+   setterr*   s       @r!   _newInstancer0      s0     C H, X~}=F
5MOr#   c                     [        U [        5      nU(       a  [        U 5      n [        U [        5      (       d  U R	                  S5      n U $ )Nutf-8)r   r   r   bytesencode)
classnamepisObjects     r!   _maybeClassr7      s>    *d+H*%
j%((&&w/
r#   c                 V    [        U 5      n U[        U '   [        R                  U 5        g)aH  
Set which local class will represent a remote type.

If you have written a Copyable class that you expect your client to be
receiving, write a local "copy" class to represent it, then call::

    jellier.setUnjellyableForClass('module.package.Class', MyCopier).

Call this at the module level immediately after its class
definition. MyCopier should be a subclass of RemoteCopy.

The classname may be a special tag returned by
'Copyable.getTypeToCopyFor' rather than an actual classname.

This call is also for cached classes, since there will be no
overlap.  The rules are the same.
N)r7   unjellyableRegistryglobalSecurity
allowTypes)	classnameunjellyables     r!   setUnjellyableForClassr>      s'    ( I&I%0	"i(r#   c                 V    [        U 5      n U[        U '   [        R                  U 5        g)a  
Set the factory to construct a remote instance of a type::

  jellier.setUnjellyableFactoryForClass('module.package.Class', MyFactory)

Call this at the module level immediately after its class definition.
C{copyFactory} should return an instance or subclass of
L{RemoteCopy<pb.RemoteCopy>}.

Similar to L{setUnjellyableForClass} except it uses a factory instead
of creating an instance.
N)r7   unjellyableFactoryRegistryr:   r;   )r<   copyFactorys     r!   setUnjellyableFactoryForClassrB      s'     I&I,7y)i(r#   c                     Uc  U R                   nU(       a  SU-  n[        U 5       H3  n[        X5      n [        XA5      nU(       a  [	        U U 3U5        M3  M5     g! [
         a     ME  f = f)a  
Set all classes in a module derived from C{baseClass} as copiers for
a corresponding remote class.

When you have a hierarchy of Copyable (or Cacheable) classes on one
side, and a mirror structure of Copied (or RemoteCache) classes on the
other, use this to setUnjellyableForClass all your Copieds for the
Copyables.

Each copyTag (the "classname" argument to getTypeToCopyFor, and
what the Copyable's getTypeToCopyFor returns) is formed from
adding a prefix to the Copied's class name.  The prefix defaults
to module.__name__.  If you wish the copy tag to consist of solely
the classname, pass the empty string ''.

@param module: a module object from which to pull the Copied classes.
    (passing sys.modules[__name__] might be useful)

@param baseClass: the base class from which all your Copied classes derive.

@param prefix: the string prefixed to classnames to form the
    unjellyableRegistry.
Nz%s.)__name__dirr.   
issubclassr>   	TypeError)module	baseClassprefixnameloadedyess         r!   setUnjellyableForClassTreerN      sw    0 ~F&	BV/C &&$'8&A    	 	 s   A
A-,A-c                 *   [        U S5      (       a  U R                  5       nOU R                  nUR                  U 5      nUR	                  [        U R                  5      R                  S5      UR                  U5      /5        UR                  X5      $ )zE
Utility method to default to 'normal' state rules in serialization.
__getstate__r2   )
hasattrrP   r(   prepareextendr   	__class__r4   jellypreserve)instjellierr)   sxps       r!   getInstanceStaterZ     su     t^$$!!#
//$
CJJT^^$++G4gmmE6JKLD&&r#   c                     UR                  US   5      n[        U S5      (       a  U R                  U5        U $ X0l        U $ )zG
Utility method to default to 'normal' state rules in unserialization.
   r-   )unjellyrQ   r-   r(   )rW   	unjellier	jellyListr)   s       r!   setInstanceStater`     sF     il+Et^$$%  K Kr#   c                   ,    \ rS rSrSrS rS\4S jrSrg)Unpersistablei   zX
This is an instance of a class that comes back when something couldn't be
unpersisted.
c                     Xl         g)zI
Initialize an unpersistable object with a descriptive C{reason} string.
Nreason)selfre   s     r!   __init__Unpersistable.__init__&  s	     r#   returnc                 2    S[        U R                  5      -  $ )NzUnpersistable(%s))reprre   rf   s    r!   __repr__Unpersistable.__repr__,  s    "T$++%666r#   rd   N)	rD   
__module____qualname____firstlineno____doc__rg   strrm   __static_attributes__ r#   r!   rb   rb      s    
7# 7r#   rb   c                   $    \ rS rSrSrS rS rSrg)	Jellyablei0  zW
Inherit from me to Jelly yourself directly with the `getStateFor'
convenience method.
c                     U R                   $ r&   r(   )rf   rX   s     r!   getStateForJellyable.getStateFor7  s    }}r#   c                     UR                  U 5      nUR                  [        U R                  5      R	                  S5      UR                  U R                  U5      5      /5        UR                  X5      $ )z8
@see: L{twisted.spread.interfaces.IJellyable.jellyFor}
r2   )rR   rS   r   rT   r4   rU   rz   rV   )rf   rX   rY   s      r!   jellyForJellyable.jellyFor:  sd     ood#

T^^$++G4d..w78	
 **r#   ru   N)rD   ro   rp   rq   rr   rz   r}   rt   ru   r#   r!   rw   rw   0  s    
+r#   rw   c                   $    \ rS rSrSrS rS rSrg)UnjellyableiH  zZ
Inherit from me to Unjelly yourself directly with the
C{setStateFor} convenience method.
c                     X l         g r&   ry   )rf   r^   r)   s      r!   setStateForUnjellyable.setStateForO  s    r#   c                 P    UR                  US   5      nU R                  X5        U $ )zu
Perform the inverse operation of L{Jellyable.jellyFor}.

@see: L{twisted.spread.interfaces.IUnjellyable.unjellyFor}
r\   )r]   r   )rf   r^   r_   r)   s       r!   
unjellyForUnjellyable.unjellyForR  s+     !!)A,/*r#   ry   N)rD   ro   rp   rq   rr   r   r   rt   ru   r#   r!   r   r   H  s    
r#   r   c                   R    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSS jrSrg)_Jellieri]  z;
(Internal) This class manages state for a call to jelly()
c                 `    Xl         0 U l        0 U l        0 U l        SU l        X l        X0l        g)z
Initialize.
r\   N)taster	preservedcookedcooker_ref_idpersistentStoreinvoker)rf   r   r   r   s       r!   rg   _Jellier.__init__b  s2      .r#   c                     U R                   [        U5         n[        R                  " U5      nU R                  nU R                  S-   U l        [        XC/USS& [
        U/U R                  [        U5      '   U$ )aW  
(internal) Backreference an object.

Notes on this method for the hapless future maintainer: If I've already
gone through the prepare/preserve cycle on the specified object (it is
being referenced after the serializer is "done with" it, e.g. this
reference is NOT circular), the copy-in-place of aList is relevant,
since the list being modified is the actual, pre-existing jelly
expression that was returned for that object. If not, it's technically
superfluous, since the value in self.preserved didn't need to be set,
but the invariant that self.preserved[id(object)] is a list is
convenient because that means we don't have to test and create it or
not create it here, creating fewer code-paths.  that's why
self.preserved is always set to a list.

Sorry that this code is so hard to follow, but Python objects are
tricky to persist correctly. -glyph
r\   N)r   idcopyr   reference_atomdereference_atomr   )rf   objectaListnewListrefids        r!   _cook_Jellier._cookq  si    & r&z*))E"||a' #E3a#3U";BvJr#   c                 d    / U R                   [        U5      '   XR                  [        U5      '   / $ )a  
(internal) Create a list for persisting an object to.  This will allow
backreferences to be made internal to the object. (circular
references).

The reason this needs to happen is that we don't generate an ID for
every object, so we won't necessarily know which ID the object will
have in the future.  When it is 'cooked' ( see _cook ), it will be
assigned an ID, and the temporary placeholder list created here will be
modified in-place to create an expression that gives this object an ID:
[reference id# [object-jelly]].
)r   r   r   )rf   r   s     r!   rR   _Jellier.prepare  s-     &(r&z" #)BvJ	r#   c                     [        U5      U R                  ;   a4  X R                  [        U5         S'   U R                  [        U5         nU$ X R                  [        U5      '   U$ )zA
(internal) Mark an object's persistent list for later referral.
   )r   r   r   )rf   r   sexps      r!   rV   _Jellier.preserve  sY    
 f:$,0NN2f:&q)>>"V*-D  *.NN2f:&r#   c                     [        U5      nX R                  ;   a  U R                  U   $ X R                  ;   a   U R                  U5        U R                  U   $ g r&   )r   r   r   r   )rf   objobjIds      r!   _checkMutable_Jellier._checkMutable  sM    3KK;;u%%NN"JJsO;;u%% #r#   c           
         [        U[        5      (       a+  U R                  U5      nU(       a  U$ UR                  U 5      $ [	        U5      nU R
                  R                  [        U5      R                  S5      5      (       GaY  U[        [        [        4;   a  U$ [        U[        R                  5      (       aR  UR                  nUR                  nUR                   nSUR"                  U R%                  U5      U R%                  U5      /$ U[&        L a  SUR                  S5      /$ [        U[	        S 5      5      (       a  S/$ [        U[        R(                  5      (       a  SUR*                  S-   UR,                  -   /$ [        U[        R.                  5      (       a  SUR"                  /$ U[0        L a  S	U=(       a    S
=(       d    S/$ U[2        R2                  L a  UR4                  (       a  [7        S5      eSSR9                  UR:                  UR<                  UR>                  UR@                  URB                  URD                  URF                  4 Vs/ s H  n['        U5      PM     sn5      R                  S5      /$ U[2        RH                  L a  UR4                  (       a  [7        S5      eSSR9                  UR@                  URB                  URD                  URF                  4 Vs/ s H  n['        U5      PM     sn5      R                  S5      /$ U[2        RJ                  L a]  SSR9                  UR:                  UR<                  UR>                  4 Vs/ s H  n['        U5      PM     sn5      R                  S5      /$ U[2        RL                  L a]  SSR9                  URN                  URP                  URR                  4 Vs/ s H  n['        U5      PM     sn5      R                  S5      /$ [U        U[        5      (       a  S[        U5      R                  S5      /$ U[V        RX                  L a  U R[                  U5      $ U R                  U5      nU(       a  U$ U R]                  U5      nU[^        L a'  URa                  U Rc                  [d        U5      5        GOU[f        L a'  URa                  U Rc                  [h        U5      5        GOU[j        ;   aa  URm                  [n        5        URq                  5        H6  u  pURm                  U R%                  U	5      U R%                  U
5      /5        M8     GOU[r        L a'  URa                  U Rc                  [t        U5      5        GOTU[v        L a'  URa                  U Rc                  [x        U5      5        GO$[        UR                   5      R                  S5      nS nU Rz                  (       a  U R{                  X5      nUb'  URm                  [|        5        URm                  U5        OU R
                  R                  UR                   5      (       a`  URm                  U5        [        US5      (       a  UR                  5       nOUR                  nURm                  U R%                  U5      5        O(U R                  S[        UR                   5      -  U5        U R                  X5      $ [        SU SU 35      es  snf s  snf s  snf s  snf )Nr2   s   method   unicodeUTF-8r   r   .r      boolean   true   falsez2Currently can't jelly datetime objects with tzinfo   datetime    time   date	   timedeltar   rP   z$instance of class %s deemed insecurezType not allowed for object: )Fr   rw   r   r}   r   r   isTypeAllowedr   r4   r3   intfloattypes
MethodType__self____func__rT   rD   rU   rs   FunctionTypero   rp   
ModuleTypebooldatetimetzinfoNotImplementedErrorjoinyearmonthdayhourminutesecondmicrosecondtimedate	timedeltadayssecondsmicrosecondsrF   decimalDecimaljelly_decimalrR   listrS   _jellyIterable	list_atomtuple
tuple_atom	DictTypesappenddictionary_atomitemssetset_atom	frozensetfrozenset_atomr   persistent_atomisClassAllowedrQ   rP   r(   unpersistablerV   InsecureJelly)rf   r   preRefobjTypeaSelfaFuncaClassxrY   keyval	className
persistentr)   s                 r!   rU   _Jellier.jelly  s   c9%%'',F<<%%s);;$$T']%9%9'%BCC5#u--
C!1!122NNJJu%JJv&	  C"CJJw$788Cd,,y C!3!344#S^^c%9C<L<L%LMMC!1!122!3<<00D"COG$?x@@H---::-L   HH !$ #		 # # #

 #

 #&&  F& fWo " HMM)::-L  HH '*hh

CJJ%X%X  F%X
 fWo  HMM)HHsxxCGG.LM.Lc!f.LMNUU  H... HH*-((CKKAQAQ)RS)RAQ)RSfWo	  GT** $s)"2"27";<<GOO+))#..++C0!Mll3'd?JJt229cBC%JJt22:sCD	)JJ/$'IIK

DJJsOTZZ_#EF %0^JJt228SAB	)JJt22>3GH $S]] 3 : :7 CI!%J++%)%9%9#%D
!-

?3

:.33CMMBB

9-"377$'$4$4$6E$'LLE

4::e#45**B"3==12
 }}S.."?y# OPPo, N Ts   [/
2[4
"[9
[>
c              #   L   #    Uv   U H  nU R                  U5      v   M     g7f)z
Jelly an iterable object.

@param atom: the identifier atom of the object.
@type atom: C{str}

@param obj: any iterable object.
@type obj: C{iterable}

@return: a generator of jellied data.
@rtype: C{generator}
N)rU   )rf   atomr   items       r!   r   _Jellier._jellyIterable=  s%      
D**T"" s   "$c                 ^    UR                  5       u  p#n[        S U5      nU(       a  U* nSXT/$ )z
Jelly a decimal object.

@param d: a decimal object to serialize.
@type d: C{decimal.Decimal}

@return: jelly for the decimal object.
@rtype: C{list}
c                     U S-  U-   $ )N
   ru   )leftrights     r!   <lambda>(_Jellier.jelly_decimal.<locals>.<lambda>Y  s    4"9u+<r#      decimal)as_tupler   )rf   dsigngutsexponentvalues         r!   r   _Jellier.jelly_decimalN  s6      !zz|H<dCFEE,,r#   Nc                     Uc  / nUR                  [        5        [        U[        5      (       a  UR	                  S5      nUR                  U5        U$ )z
(internal) Returns an sexp: (unpersistable "reason").  Utility method
for making note that a particular object could not be serialized.
r2   )r   unpersistable_atomr   rs   r4   )rf   re   rY   s      r!   r   _Jellier.unpersistable^  sG    
 ;C

%&fc""]]7+F

6
r#   )r   r   r   r   r   r   r   r&   )rD   ro   rp   rq   rr   rg   r   rR   rV   r   rU   r   r   r   rt   ru   r#   r!   r   r   ]  s7    <0&~Q@#"- r#   r   c                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r Sr!g )!
_Unjellieril  c                 D    Xl         X l        0 U l        / U l        X0l        g r&   )r   persistentLoad
referencespostCallbacksr   )rf   r   r  r   s       r!   rg   _Unjellier.__init__m  s!    ,r#   c                 \    U R                  U5      nU R                   H
  nU" 5         M     U$ r&   )r]   r	  )rf   r   oms       r!   unjellyFull_Unjellier.unjellyFullt  s*    LL##AC $r#   c                 r    [        US5      (       a%  U R                  R                  UR                  5        U$ )z
If the given object has support for the C{postUnjelly} hook, set it up
to be called at the end of deserialization.

@param unjellied: an object that has already been unjellied.

@return: C{unjellied}
postUnjelly)rQ   r	  r   r  )rf   	unjellieds     r!   _maybePostUnjelly_Unjellier._maybePostUnjellyz  s1     9m,,%%i&;&;<r#   c                 0   [        U5      [        La  U$ US   nU R                  R                  U5      (       d  [	        U5      e[
        R                  U5      nUb-  [        [        U5      SU5      nU R                  U" X5      5      $ [        R                  U5      nUb)  U R                  U" U R                  US   5      5      5      $ [        U5      n[        U SU-  S 5      nUb  U" USS  5      $ UR                  S5      nSR                  US S 5      n	U R                  R                  U	5      (       d  [	        SU	 SU S	35      e[!        U5      n
U R                  R#                  U
5      (       d  [	        S
U-  5      eU R%                  XS   5      $ )Nr   r   r\   z_unjelly_%sr   zModule z not allowed (in type z).zClass %s not allowed.)r   r   r   r   r   r9   getr.   r"   r  r@   r]   r   splitr   isModuleAllowedr   r   _genericUnjelly)rf   r   jelTypeBytesregClassmethod
regFactoryjelTypeTextthunk	nameSplitmodNameclzs              r!   r]   _Unjellier.unjelly  s   9D J1v{{((66--&**<8\(3\8LF))&*;<</33LA
!))*T\\#a&5I*JKK"<0mk94@QR>!#))#.Ihhy"~.G;;..w77#gY&<[ML  k*C;;--c22#$;k$IJJ''V44r#   c                 T    U R                  [        XR                  U5      5      5      $ )a~  
Unjelly a type for which no specific unjellier is registered, but which
is nonetheless allowed.

@param cls: the class of the instance we are unjellying.
@type cls: L{type}

@param state: The jellied representation of the object's state; its
    C{__dict__} unless it has a C{__setstate__} that takes something
    else.
@type state: L{list}

@return: the new, unjellied instance.
)r  r0   r]   )rf   r    r)   s      r!   r  _Unjellier._genericUnjelly  s#     %%l3U8K&LMMr#   c                     g r&   ru   rf   exps     r!   _unjelly_None_Unjellier._unjelly_None  s    r#   c                      [        US   S5      $ )Nr   r   )rs   r(  s     r!   _unjelly_unicode_Unjellier._unjelly_unicode  s    3q67##r#   c                     US   nUS   nUS:  a  SnOSn[         R                  " U5      R                  5       S   n[         R                  " XEU45      $ )z
Unjelly decimal objects.
r   r\   )r   r   r   )rf   r)  r   r   r   r   s         r!   _unjelly_decimal_Unjellier._unjelly_decimal  sW     Aq619DDu%..03H566r#   c                 (    US   S;   d   eUS   S:H  $ )Nr   )r   r   r   ru   r(  s     r!   _unjelly_boolean_Unjellier._unjelly_boolean  s$    1v,,,,1v  r#   c                 f    [         R                   " [        [        US   R                  5       5      6 $ Nr   )r   mapr   r  r(  s     r!   _unjelly_datetime_Unjellier._unjelly_datetime  s$      #c3q6<<>":;;r#   c                 f    [         R                  " [        [        US   R	                  5       5      6 $ r6  )r   r   r7  r   r  r(  s     r!   _unjelly_date_Unjellier._unjelly_date  "    }}c#s1v||~677r#   c                 f    [         R                  " [        [        US   R	                  5       5      6 $ r6  )r   r   r7  r   r  r(  s     r!   _unjelly_time_Unjellier._unjelly_time  r=  r#   c                 t    [        [        US   R                  5       5      u  p#n[        R                  " X#US9$ )Nr   )r   r   r   )r7  r   r  r   r   )rf   r)  r   r   r   s        r!   _unjelly_timedelta_Unjellier._unjelly_timedelta  s0    &)#s1v||~&>#|!!t<XXr#   c                 |    U R                  U5      n[        U[        5      (       a  UR                  X5        XAU'   U$ r&   )r]   r   r   addDependant)rf   r   locjelr  s        r!   unjellyInto_Unjellier.unjellyInto  s5    LLa""NN3$Cr#   c                     US   nU R                   R                  U5      nUb  U$ [        U5      nX@R                   U'   U$ r6  )r  r  r   )rf   lstr   r   ders        r!   _unjelly_dereference_Unjellier._unjelly_dereference  sD    AOO&=H5!!$
r#   c                    US   nUS   nU R                  U5      nU R                  R                  U5      nUc  X@R                  U'   U$ [        U[        5      (       a!  UR                  U5        X@R                  U'   U$  S5       e)Nr   r\   z!Multiple references with same ID!)r]   r  r  r   r   resolveDependants)rf   rK  r   r)  r  refs         r!   _unjelly_reference_Unjellier._unjelly_reference  s    A!fLLoo!!%(;%&OOE"  X&&!!!$%&OOE"  :991r#   c           	          [        [        [        U5      5      5      nSnU H.  n[        U R	                  X$X   5      [
        5      (       d  M,  SnM0     U(       a  [        U5      $ [        U5      $ )Nr\   r   )r   rangelenr   rH  r   r   r   )rf   rK  lfinishedelems        r!   _unjelly_tuple_Unjellier._unjelly_tuple  s\    s3x!D$**1CI>II  8O!9r#   c                 z    [        [        [        U5      5      5      nU H  nU R                  X#X   5        M     U$ r&   )r   rU  rV  rH  )rf   rK  rW  rY  s       r!   _unjelly_list_Unjellier._unjelly_list  s5    s3x!DQci0 r#   c                     [        [        [        U5      5      5      nSnU H0  nU R                  X5X   5      n[	        U[
        5      (       d  M.  SnM2     U(       d  [        X25      $ U" U5      $ )z
Helper method to unjelly set or frozenset.

@param lst: the content of the set.
@type lst: C{list}

@param containerType: the type of C{set} to use.
TF)r   rU  rV  rH  r   r   r   )rf   rK  containerTyperW  rX  rY  datas          r!   _unjellySetOrFrozenset!_Unjellier._unjellySetOrFrozenset	  sf     s3x!D##ASY7D$))   a// ##r#   c                 .    U R                  U[        5      $ )z'
Unjelly set using the C{set} builtin.
)rb  r   rf   rK  s     r!   _unjelly_set_Unjellier._unjelly_set  s     **344r#   c                 .    U R                  U[        5      $ )z3
Unjelly frozenset using the C{frozenset} builtin.
)rb  r   re  s     r!   _unjelly_frozenset_Unjellier._unjelly_frozenset#  s     **3	::r#   c                     0 nU H6  u  p4[        U5      nU R                  USU5        U R                  USU5        M8     U$ )Nr   r\   )r	   rH  )rf   rK  r   kvkvds         r!   _unjelly_dictionary_Unjellier._unjelly_dictionary)  sH    DA"1%CS!Q'S!Q'  r#   c                     [        US   5      n[        U5      [        :w  a  [        S5      eU R                  R                  U5      (       d  [        SU< 35      e[        U0 0 S5      nU$ )Nr   z5Attempted to unjelly a module with a non-string name.z"Attempted to unjelly module named r   )r   r   rs   r   r   r  
__import__)rf   rest
moduleNamemods       r!   _unjelly_module_Unjellier._unjelly_module1  sf    !$q'*

s" WXX{{**:66"DZN STTRS1
r#   c                    [        US   5      nUR                  [        S5      5      n[        S5      R                  US S 5      nU R                  R	                  U5      (       d  [        SU-  5      e[        U5      n[        U5      nU[        La  [        SU< SU< 35      eU R                  R                  U5      (       d  [        S[        U5      -  5      eU$ )Nr   r   r  zmodule %s not allowedzclass z, unjellied to something that isn't a class: zclass not allowed: %s)
r   r  r   r   r  r   r   r   r   r   )rf   rs  cnameclistr"  klausr   s          r!   _unjelly_class_Unjellier._unjelly_class:  s    T!W%L-.s#((s4{{**733 7' ABBE"u+$%!  {{))%00 7$u+ EFFr#   c                    [        US   5      nUR                  [        S5      5      n[        S5      R                  US S 5      nU R                  R	                  U5      (       d  [        SU-  5      e[        U5      nU$ )Nr   r   r  zModule not allowed: %s)r   r  r   r   r  r   r   )rf   rs  fnamemodSplitr"  functions         r!   _unjelly_function_Unjellier._unjelly_functionK  sr    T!W%;;|C01s#((#27{{**733 87 BCCE?r#   c                 h    U R                   (       a  U R                  US   U 5      nU$ [        S5      $ )Nr   zPersistent callback not found)r  rb   )rf   rs  ploads      r!   _unjelly_persistent_Unjellier._unjelly_persistentU  s2    ''Q6EL !@AAr#   c                     [         R                  " S[        SSS9  U R                  US   5      nU R	                  X!S   5      $ )z
(internal) Unjelly an instance.

Called to handle the deprecated I{instance} token.

@param rest: The s-expression representing the instance.

@return: The unjellied instance.
ztUnjelly support for the instance atom is deprecated since Twisted 15.0.0.  Upgrade peer for modern instance support. r   )categoryfilenamelinenor\   )warningswarn_explicitDeprecationWarningr]   r  )rf   rs  r#  s      r!   _unjelly_instance_Unjellier._unjelly_instance\  sJ     	I'	
 ll47###Ca11r#   c                 $    [        SUS    35      $ )NzUnpersistable data: r   )rb   )rf   rs  s     r!   _unjelly_unpersistable!_Unjellier._unjelly_unpersistableq  s    3DG9=>>r#   c                    US   nU R                  US   5      nU R                  US   5      n[        U[        5      (       d  [        S5      eX$R                  ;   a_  Uc  [        XB5      nU$ [        U[        5      (       a  [        X#U5      nU$ [        R                  " UR                  U   U/U/S-  Q76 n U$ [        S5      e)z
(internal) Unjelly a method.
r   r\   r   z"Method found with non-class class.Fzinstance method changed)r]   r   r   r   r(   r.   r   r
   r   r   rG   )rf   rs  im_nameim_selfim_classims         r!   _unjelly_method_Unjellier._unjelly_methodt  s     q',,tAw'<<Q((D)) DEE'''X/ 	 GX..$Wx@ 	 %%%%g.<D:;O
 	 566r#   )r   r  r	  r  r   N)"rD   ro   rp   rq   rg   r  r  r]   r  r*  r-  r0  r3  r8  r;  r?  rB  rH  rM  rR  rZ  r]  rb  rf  ri  ro  rv  r|  r  r  r  r  r  rt   ru   r#   r!   r  r  l  s    5<N"$7!<88Y	$(5;"B2*?r#   r  c                       \ rS rSrSrSrg)r   i  z
This exception will be raised when a jelly is deemed `insecure'; e.g. it
contains a type, class, or module disallowed by the specified `taster'
ru   N)rD   ro   rp   rq   rr   rt   ru   r#   r!   r   r     s    r#   r   c                   *    \ rS rSrSrS rS rS rSrg)DummySecurityOptionsi  zo
DummySecurityOptions() -> insecure security options
Dummy security options -- this class will allow anything.
c                     g)zx
DummySecurityOptions.isModuleAllowed(moduleName) -> boolean
returns 1 if a module by that name is allowed, 0 otherwise
r\   ru   rf   rt  s     r!   r  $DummySecurityOptions.isModuleAllowed      
 r#   c                     g)z
DummySecurityOptions.isClassAllowed(class) -> boolean
Assumes the module has already been allowed.  Returns 1 if the given
class is allowed, 0 otherwise.
r\   ru   rf   klasss     r!   r   #DummySecurityOptions.isClassAllowed  s     r#   c                     g)zn
DummySecurityOptions.isTypeAllowed(typeName) -> boolean
Returns 1 if the given type is allowed, 0 otherwise.
r\   ru   rf   typeNames     r!   r   "DummySecurityOptions.isTypeAllowed  r  r#   ru   N)	rD   ro   rp   rq   rr   r  r   r   rt   ru   r#   r!   r  r    s    
r#   r  c                   P    \ rS rSrSr/ SQrS rS rS rS r	S r
S	 rS
 rS rSrg)SecurityOptionsi  z>
This will by default disallow everything, except for 'none'.
)

dictionaryr   r   	referencedereferencer   r   long_intlongr'   c                     0 SS_SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_U l         0 U l        0 U l        g)z
SecurityOptions() initialize.
r   r\   s   boolr   s   strings   strs   ints   floatr   r   r   r   s   NoneTyper   r   r   r   N)allowedTypesallowedModulesallowedClassesrl   s    r!   rg   SecurityOptions.__init__  s    
Q
Q
 
 q	

 A
 A
 a
 
 Q
 Q
 !
 
 
 
 A
  !!
$ ! r#   c                 6    U R                   " U R                  6   g)zb
Allow all `basic' types.  (Dictionary and list.  Int, string, and float
are implicitly allowed.)
N)r;   
basicTypesrl   s    r!   allowBasicTypesSecurityOptions.allowBasicTypes  s    
 	)r#   c                     U HX  n[        U[        5      (       a  UR                  S5      n[        U[        5      (       d  [	        U5      nSU R
                  U'   MZ     g)zO
SecurityOptions.allowTypes(typeString): Allow a particular type, by its
name.
r2   r\   N)r   rs   r4   r3   r   r  )rf   r   typs      r!   r;   SecurityOptions.allowTypes  sO    
 C#s##jj)c5))3i%&Dc" r#   c                     U R                  5         U R                  SSSS5        U HG  nU R                  [        U5      5        U R                  UR                  5        SU R
                  U'   MI     g)z
SecurityOptions.allowInstances(klass, klass, ...): allow instances
of the specified classes

This will also allow the 'instance', 'class' (renamed 'classobj' in
Python 2.3), and 'module' types, as well as basic types.
r*   classclassobjrH   r\   N)r  r;   r   allowModulesro   r  )rf   classesr  s      r!   allowInstancesOf SecurityOptions.allowInstancesOf  s`     	
GZBEOODK(e../)*D& r#   c                     U Ha  n[        U5      [        R                  :X  a  UR                  n[	        U[
        5      (       d  UR                  S5      nSU R                  U'   Mc     g)zs
SecurityOptions.allowModules(module, module, ...): allow modules by
name. This will also allow the 'module' type.
r2   r\   N)r   r   r   rD   r   r3   r4   r  )rf   modulesrH   s      r!   r  SecurityOptions.allowModules  sT    
 FF|u///fe,,w/*+D' r#   c                 j    [        U[        5      (       d  UR                  S5      nXR                  ;   $ )zs
SecurityOptions.isModuleAllowed(moduleName) -> boolean
returns 1 if a module by that name is allowed, 0 otherwise
r2   )r   r3   r4   r  r  s     r!   r  SecurityOptions.isModuleAllowed  s0    
 *e,,#**73J0000r#   c                     XR                   ;   $ )z
SecurityOptions.isClassAllowed(class) -> boolean
Assumes the module has already been allowed.  Returns 1 if the given
class is allowed, 0 otherwise.
)r  r  s     r!   r   SecurityOptions.isClassAllowed  s     ++++r#   c                     [        U[        5      (       d  UR                  S5      nXR                  ;   =(       d    SU;   $ )zi
SecurityOptions.isTypeAllowed(typeName) -> boolean
Returns 1 if the given type is allowed, 0 otherwise.
r2      .)r   r3   r4   r  r  s     r!   r   SecurityOptions.isTypeAllowed!  s8    
 (E**w/H,,,@0@@r#   )r  r  r  N)rD   ro   rp   rq   rr   r  rg   r  r;   r  r  r  r   r   rt   ru   r#   r!   r  r    s7    J!6*
'+,1,Ar#   r  c                 8    [        XU5      R                  U 5      $ )z
Serialize to s-expression.

Returns a list which is the serialized representation of an object.  An
optional 'taster' argument takes a SecurityOptions and will mark any
insecure objects as unpersistable rather than serializing them.
)r   rU   )r   r   r   r   s       r!   rU   rU   0  s     FW5;;FCCr#   c                 8    [        XU5      R                  U 5      $ )a<  
Unserialize from s-expression.

Takes a list that was the result from a call to jelly() and unserializes
an arbitrary object from it.  The optional 'taster' argument, an instance
of SecurityOptions, will cause an InsecureJelly exception to be raised if a
disallowed type, module, or class attempted to unserialize.
)r  r  )r   r   r  r   s       r!   r]   r]   ;  s     fg6BB4HHr#   r&   )Err   r   r   r   r   r  	functoolsr   zope.interfacer   incrementalr   twisted.persisted.crefutilr   r   r   r	   r
   r   twisted.python.compatr   twisted.python.deprecater   twisted.python.reflectr   r   r   twisted.spread.interfacesr   r   r'   r   	None_atom
class_atommodule_atomfunction_atomr   r   r   r   r   r   r   r   r   r  r9   r@   r"   r0   r7   r>   rB   rN   rZ   r`   rb   rw   r   r   r  	Exceptionr   r  r  r:   r  rU   r]   ru   r#   r!   <module>r     s  
8t       &   / > > > >G		
 "   	 
 Ir1a -	 &     (	)2)(&BR
'	7 7  Z+ + +. \  (L L^\ \D	I  :wA wAt !"      ./t D ./d 	Ir#   