|
PyAMF provides Action Message Format (AMF) support for Python that is compatible with the Adobe Flash Player.
| Copyright: | Copyright (c) 2007-2010 The PyAMF Project. All Rights Reserved. |
|---|---|
| Contact: | users@pyamf.org |
| See: | http://pyamf.org |
| Since: | October 2007 |
| Status: | Production/Stable |
Registers a class to be used in the data streaming.
| Returns: | The registered ClassAlias. |
|---|
Registers a loader that is called to provide the Class for a specific alias.
The loader is provided with one argument, the Class alias. If the loader succeeds in finding a suitable class then it should return that class, otherwise it should return None.
| Raises TypeError: | |
|---|---|
| The loader is not callable. | |
| Raises ValueError: | |
| The loader is already registered. | |
A helper function to encode an element.
| Parameters: |
|
|---|---|
| Return type: | StringIO |
| Returns: | File-like object. |
A generator function to decode a datastream.
| Parameters: |
|
|---|---|
| Returns: | Each element in the stream. |
Finds the alias registered to the class.
| Returns: | The class alias linked to klass. |
|---|---|
| Return type: | ClassAlias |
| Raises UnknownClassAlias: | |
| Class not found. | |
Deletes a class from the cache.
If alias is a class, the matching alias is found.
| Parameter: | alias (class or str) – Alias for class to delete. |
|---|---|
| Raises UnknownClassAlias: | |
| Unknown alias. | |
This function allows you to map subclasses of ClassAlias to classes listed in args.
When an object is read/written from/to the AMF stream, a paired ClassAlias instance is created (or reused), based on the Python class of that object. ClassAlias provides important metadata for the class and can also control how the equivalent Python object is created, how the attributes are applied etc.
Use this function if you need to do something non-standard.
| See: | pyamf.adapters._google_appengine_ext_db.DataStoreClassAlias for a good example. |
|---|---|
| Since: | 0.4 |
| Raises RuntimeError: | |
| Type is already registered. | |
| Raises TypeError: | |
| klass must be a class. | |
| Raises ValueError: | |
| New aliases must subclass pyamf.ClassAlias. | |
| Raises ValueError: | |
| At least one type must be supplied. | |
Removes the klass from the ALIAS_TYPE register.
| See: | register_alias_type() |
|---|
Unregisters a class loader.
| Parameter: | loader (callable) – The object to be unregistered |
|---|---|
| Raises LookupError: | |
| The loader was not registered. | |
Maps an exception class to a string code. Used to map remoting onStatus objects to an exception class so that an exception can be built to represent that error.
| Raises TypeError: | |
|---|---|
| klass must be a class type. | |
| Raises TypeError: | |
| Error classes must subclass the __builtin__.Exception class. | |
| Raises ValueError: | |
| Code is already registered. | |
An example:
>>> class AuthenticationError(Exception):
... pass
...
>>> pyamf.add_error_class(AuthenticationError, 'Auth.Failed')
>>> print pyamf.ERROR_CLASS_MAP
{'TypeError': <type 'exceptions.TypeError'>, 'IndexError': <type 'exceptions.IndexError'>,
'Auth.Failed': <class '__main__.AuthenticationError'>, 'KeyError': <type 'exceptions.KeyError'>,
'NameError': <type 'exceptions.NameError'>, 'LookupError': <type 'exceptions.LookupError'>}
Removes a class from ERROR_CLASS_MAP.
| Raises ValueError: | |
|---|---|
| Code is not registered. | |
| Raises ValueError: | |
| Class is not registered. | |
| Raises TypeError: | |
| Invalid type, expected class or string. | |
An example:
>>> class AuthenticationError(Exception):
... pass
...
>>> pyamf.add_error_class(AuthenticationError, 'Auth.Failed')
>>> pyamf.remove_error_class(AuthenticationError)
Adds a custom type to TYPE_MAP. A custom type allows fine grain control of what to encode to an AMF data stream.
| Raises TypeError: | |
|---|---|
| Unable to add as a custom type (expected a class or callable). | |
| Raises KeyError: | |
| Type already exists. | |
Removes the custom type declaration.
| Returns: | Custom type declaration. |
|---|
This is a helper function that takes the concept of Actionscript packages and registers all the classes in the supplied Python module under that package. It auto-aliased all classes in module based on package.
| Parameters: |
|
|---|---|
| Raises TypeError: | |
Cannot get list of classes from module |
|
| Returns: | A collection of all the classes that were registered and their respective ClassAlias objects. |
| Since: | 0.5 |
PyAMF version number.
>>> pyamf.__version__ is pyamf.version
True
>>> pyamf.version
(0, 6, 1, 'rc1')
>>> str(pyamf.version)
'0.6.1rc1'
| See: | pyamf.versions |
|---|
Class mapping support.
>>> pyamf.CLASS_CACHE
{<class 'pyamf.ASObject'>: <ClassAlias alias= class=<class 'pyamf.ASObject'> @ 0x100568a50>}
| See: | register_class(), unregister_class() and register_package() |
|---|
Alias mapping support
>>> pyamf.ALIAS_TYPES
{<class 'pyamf.TypedObjectClassAlias'>: (<class 'pyamf.TypedObject'>,),
<class 'pyamf.ErrorAlias'>: (<type 'exceptions.Exception'>,)}
| See: | get_class_alias(), register_alias_type() and unregister_alias_type() |
|---|
Maps error classes to string codes.
>>> pyamf.ERROR_CLASS_MAP
{'LookupError': <type 'exceptions.LookupError'>, 'NameError': <type 'exceptions.NameError'>,
'TypeError': <type 'exceptions.TypeError'>, 'IndexError': <type 'exceptions.IndexError'>,
'KeyError': <type 'exceptions.KeyError'>}
| See: | add_error_class() and remove_error_class() |
|---|
Custom type map.
>>> pyamf.TYPE_MAP
{<type 'array.array'>: <function to_list at 0x101345ed8>,
<type 'collections.deque'>: <function to_list at 0x101345ed8>,
<type 'collections.defaultdict'>: <function to_dict at 0x101349b18>}
| See: | get_type(), add_type() and remove_type() |
|---|
Class loaders.
>>> pyamf.CLASS_LOADERS
[<function flex_loader at 0x100569e60>, <function blaze_loader at 0x100569de8>]
| See: | register_class_loader() and unregister_class_loader() |
|---|
Supported AMF encoding types.
>>> pyamf.ENCODING_TYPES
(0, 3)
| See: | AMF0, AMF3, and DEFAULT_ENCODING |
|---|
Base AMF Error.
All AMF related errors should be subclassed from this class.
Raised if the element could not be encoded to the stream.
| Bug: | See Docuverse blog (external) for more info about the empty key string array bug. |
|---|
Raised if the AMF stream specifies an Actionscript class that does not have a Python class alias.
| See: | register_class() |
|---|