Module Cerealizer
[hide private]
[frames] | no frames]

Module Cerealizer

source code

Classes [hide private]
  frozenset
Cerealizer -- A secure Pickle-like module The interface of the Cerealizer module is similar to Pickle, and it supports __getstate__, __setstate__, __getinitargs__ and __getnewargs__.
  NotCerealizerFileError
  NonCerealizableObjectError
  Dumper
  Handler
Handler
  RefHandler
  NoneHandler
  StrHandler
  UnicodeHandler
  BoolHandler
  IntHandler
  LongHandler
  FloatHandler
  ComplexHandler
  TupleHandler
  FrozensetHandler
  ListHandler
  SetHandler
  DictHandler
  ObjHandler
ObjHandler
  SlotedObjHandler
SlotedObjHandler
  InitArgsObjHandler
InitArgsObjHandler
  NewArgsObjHandler
NewArgsObjHandler
Functions [hide private]
 
_priority_sorter(a, b) source code
 
register(Class, handler='', classname='')
register(Class, handler = None, classname = "")
source code
 
register_class(Class, handler='', classname='')
register(Class, handler = None, classname = "")
source code
 
register_alias(Class, alias)
Registers ALIAS as an alias classname for CLASS.
source code
 
freeze_configuration()
Ends Cerealizer configuration.
source code
 
dump(obj, file, protocol=0)
dump(obj, file, protocol = 0)
source code
 
load(file)
De-serializes an object from FILE.
source code
 
dumps(obj, protocol=0)
dumps(obj, protocol = 0) -> str
source code
 
loads(file)
De-serializes an object from STRING.
source code
 
dump_class_of_module(*modules)
Utility function; for each classes found in the given module, print the needed call to register.
source code
Variables [hide private]
  set = sets.Set
  __alls__ = ['load', 'dump', 'loads', 'dumps', 'freeze_configur...
  VERSION = '0.5'
  logger = logging.getLogger("cerealizer")
  _configurable = 1
  _HANDLERS = {'dict\n': <Cerealizer.DictHandler object at 0x41c...
  _HANDLERS_ = {<type 'float'>: <Cerealizer.FloatHandler object ...
Function Details [hide private]

register(Class, handler='', classname='')

source code 

register(Class, handler = None, classname = "")

Registers CLASS as a serializable and secure class. By calling register, YOU HAVE TO ASSUME THAT THE FOLLOWING METHODS ARE SECURE:
  • CLASS.__new__
  • CLASS.__del__
  • CLASS.__getstate__
  • CLASS.__setstate__
  • CLASS.__getinitargs__
  • CLASS.__init__ (only if CLASS.__getinitargs__ exists)

HANDLER is the Cerealizer Handler object that handles serialization and deserialization for Class. If not given, Cerealizer create an instance of ObjHandler, which is suitable for old-style and new_style Python class, and also C-defined types (although if it has some C-side data, you may have to write a custom Handler or a __getstate__ and __setstate__ pair).

CLASSNAME is the classname used in Cerealizer files. It defaults to the full classname (module.class) but you may choose something shorter -- as long as there is no risk of name clash.

register_class(Class, handler='', classname='')

source code 

register(Class, handler = None, classname = "")

Registers CLASS as a serializable and secure class. By calling register, YOU HAVE TO ASSUME THAT THE FOLLOWING METHODS ARE SECURE:
  • CLASS.__new__
  • CLASS.__del__
  • CLASS.__getstate__
  • CLASS.__setstate__
  • CLASS.__getinitargs__
  • CLASS.__init__ (only if CLASS.__getinitargs__ exists)

HANDLER is the Cerealizer Handler object that handles serialization and deserialization for Class. If not given, Cerealizer create an instance of ObjHandler, which is suitable for old-style and new_style Python class, and also C-defined types (although if it has some C-side data, you may have to write a custom Handler or a __getstate__ and __setstate__ pair).

CLASSNAME is the classname used in Cerealizer files. It defaults to the full classname (module.class) but you may choose something shorter -- as long as there is no risk of name clash.

register_alias(Class, alias)

source code 
Registers ALIAS as an alias classname for CLASS.
Usefull for keeping backward compatibility in files: e.g. if you have renamed OldClass to
NewClass, just do:

    cerealizer.register_alias(NewClass, "OldClass")

and you'll be able to open old files containing OldClass serialized.

freeze_configuration()

source code 
Ends Cerealizer configuration. When freeze_configuration() is called, it is no longer possible to register classes, using register(). Calling freeze_configuration() is not mandatory, but it may enforce security, by forbidding unexpected calls to register().

dump(obj, file, protocol=0)

source code 

dump(obj, file, protocol = 0)

Serializes object OBJ in FILE. PROTOCOL is unused, it exists only for compatibility with Pickle.

load(file)

source code 
De-serializes an object from FILE.
Returns:
obj

dumps(obj, protocol=0)

source code 

dumps(obj, protocol = 0) -> str

Serializes object OBJ and returns the serialized string. PROTOCOL is unused, it exists only for compatibility with Pickle.

loads(file)

source code 
De-serializes an object from STRING.
Returns:
obj


Variables Details [hide private]

__alls__

Value:
['load', 'dump', 'loads', 'dumps', 'freeze_configuration', 'register']

_HANDLERS

Value:
{}

_HANDLERS_

Value:
{}