Module: pysyncml.agents¶
This module defines the abstract interface pysyncml.Agent, the base class for all pysyncml synchronization agents.
- class pysyncml.agents.base.Agent(contentTypes=None, *args, **kw)[source]¶
The Agent interface is how the pysyncml Adapter interacts with the actual objects being synchronized. The data is expected to be stored by the calling framework, and pysyncml manages the protocol for synchronization. This API defines the core required methods that need to be implemented (addItem(), getItem(), replaceItem(), deleteItem(), getAllItems(), loadItem(), dumpItem()), as well as several optional methods that can be implemented for optimization purposes.
- addItem(item)[source]¶
The specified item, which will have been created via a prior loadItem(), is added to the local datastore. This method returns either a new pysyncml.Item instance or the same item that was passed — in either case, the returned item MUST have a valid pysyncml.Item.id attribute.
- deleteAllItems()[source]¶
[OPTIONAL] Deletes all items stored by this Agent. The default implementation simply iterates over getAllItems() and deletes them one at a time.
- dumpItem(item, stream, contentType=None, version=None)[source]¶
Converts the specified item to serialized form (such that it can be transported over the wire) and writes it to the provided file-like stream object. For agents that support multiple content-types, the desired contentType and version will be specified as a parameter. If contentType and version are None, appropriate default values should be used.
- dumpsItem(item, contentType=None, version=None)[source]¶
[OPTIONAL] Identical to dumpItem(), except the serialized form is returned as a string representation. The default implementation just wraps dumpItem().
- getItem(itemID)[source]¶
Returns the pysyncml.Item instance associated with the specified itemID, which may or may not have been converted to a string.
- loadItem(stream, contentType=None, version=None)[source]¶
Reverses the effects of the dumpItem() method, and returns the de-serialized Item from the file-like source stream.
Note: version will typically be None, so it should either be auto-determined, or not used. This is an issue in the SyncML protocol, and is only here for symmetry with dumpItem() and as “future-proofing”.
- loadsItem(data, contentType=None, version=None)[source]¶
[OPTIONAL] Identical to loadItem(), except the serialized form is provided as a string representation in data instead of as a stream. The default implementation just wraps loadItem().
Standard Agent Implementations¶
TODO: documentation on available standard Agent implementations coming soon...