Table of Contents

Module: jelly | Twisted-0.19.0/twisted/spread/jelly.py
--- | ---
S-expression-based persistence of python objects. I do something very much like 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: 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']]] # [`instance`, [`class`, [`module`, '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]]
Imported modules |
--- | ---
import copy from new import instance, instancemethod import pickle import string import sys from twisted.persisted.crefutil import NotKnown, _Tuple, _InstanceMethod, _DictKeyAndValue, _Dereference from twisted.python import runtime from twisted.python.reflect import namedObject, namedModule import types from types import StringType, IntType, TupleType, ListType, DictType, LongType, FloatType, FunctionType, MethodType, ModuleType, DictionaryType, InstanceType, NoneType, ClassType
Functions |
getInstanceState jelly setInstanceState setUnjellyableFactoryForClass setUnjellyableForClass setUnjellyableForClassTree unjelly
| getInstanceState
    getInstanceState ( inst,  jellier )
Utility method to default to `normal` state rules in serialization.
| jelly
    jelly (
            object,
            taster=DummySecurityOptions(),
            persistentStore=None,
            invoker=None,
            )
### 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.
| setInstanceState
    setInstanceState (
            inst,
            unjellier,
            jellyList,
            )
Utility method to default to `normal` state rules in unserialization.
| setUnjellyableFactoryForClass
    setUnjellyableFactoryForClass ( classname,  copyFactory )
### Set the factory to construct a remote instance of a type. jellier.setFactoryForClass(`module.package.Class`, MyFactory) Call this at the module level immediately after its class definition. copyFactory should return an instance or subclass of RemoteCopy. Similar to setUnjellyableForClass except it uses a factory instead of creating an instance.
| setUnjellyableForClass
    setUnjellyableForClass ( classname,  unjellyable )
### 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', MyJellier).
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.
| setUnjellyableForClassTree
    setUnjellyableForClassTree (
            module,
            baseClass,
            prefix=None,
            )
### Set all classes in a module derived from baseClass as copiers for a corresponding remote class. When you have a heirarchy of Copyable (or Cacheable) classes on one side, and a mirror structure of Copied (or RemoteCache) classes on the other, use this to setCopierForClass 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 ''. module a module object from which to pull the Copied classes. (passing sys.modules[__name__] might be useful) baseClass the base class from which all your Copied classes derive. prefix the string prefixed to classnames to form the unjellyableRegistry.
| unjelly
    unjelly (
            sexp,
            taster=DummySecurityOptions(),
            persistentLoad=None,
            invoker=None,
            )
### Unserialize from s-expression. Takes an 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.
Classes |
DummySecurityOptions | DummySecurityOptions() -> insecure security options
InsecureJelly | This exception will be raised when a jelly is deemed `insecure'; e.g. it
Jellyable | Inherit from me to Jelly yourself directly.
SecurityOptions | This will by default disallow everything, except for `none`.
Unjellyable | Inherit from me to Unjelly yourself directly.
Unpersistable | This is an instance of a class that comes back when something couldn't be
_Dummy | (Internal)
_Jellier | (Internal) This class manages state for a call to jelly()
_Unjellier |

Table of Contents

This document was automatically generated on Sun Jul 14 19:53:20 2002 by HappyDoc version 2.0