File: //usr/lib/python3/dist-packages/twisted/spread/__pycache__/jelly.cpython-310.pyc
o
�bY� � @ s d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
mZmZmZmZmZ ddlmZ ddlmZ dd lmZmZmZ dd
lmZmZ efZdZ dZ!d
Z"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,eedddd�ddd� dZ-i a.i a/dd� Z0d d!� Z1d"d#� Z2d$d%� Z3d&d'� Z4dBd(d)�Z5d*d+� Z6d,d-� Z7G d.d/� d/�Z8e e�G d0d1� d1��Z9e e�G d2d3� d3��Z:G d4d5� d5�Z;G d6d7� d7�Z<G d8d9� d9e=�Z>G d:d;� d;�Z?G d<d=� d=�Z@e@� ZAeA�B� e?� ddfd>d?�ZCe?� ddfd@dA�ZDdS )CaM
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.ztwisted.spread.jelly�
instance_atoms
unpersistablec C s t | t�r
| �| �S dS )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__)�cls� r �6/usr/lib/python3/dist-packages/twisted/spread/jelly.py�_createBlank� s
�r! c s, t | �� � fdd�}t� d|�}||� � S )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 s
| � _ d S �N��__dict__)�state��instancer r �
defaultSetter� �
z#_newInstance.<locals>.defaultSetter�__setstate__)r! �getattr)r r% r( �setterr r&