pysyncml 0.1 documentation

Module: pysyncml.items

«  Module: pysyncml.ctype   ::   Contents   ::   Module: pysyncml.model.adapter  »

Module: pysyncml.items

The pysyncml.items.base module defines the abstract interface pysyncml.Item, the base class for all pysyncml synchronized objects.

class pysyncml.items.base.Item(id=None, *args, **kw)[source]

An Item declares the abstract interface of objects that are synchronized by the pysyncml framework. The only required attributes are the id property, and the dump() and load() methods. Note that the latter two are currently never invoked directly, and are called via the pysyncml.Agent interface. They are therefore not technically required, but are highly recommended for forward-compatibility.

dump(stream, contentType=None, version=None)[source]

Converts this 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. For agents that concurrently use multiple content-types, the return value may be a two-element tuple of (contentType, version), thus overriding or enhancing the provided values.

dumps(contentType=None, version=None)[source]

[OPTIONAL] Identical to dump(), except the serialized form is returned as a string representation. As documented in dump(), the return value can optionally be a three-element tuple of (contentType, version, data) if the provided content-type should be overridden or enhanced. The default implementation just wraps dump().

id = None

The local datastore-unique identifier for this object. Although the exact datatype is undefined, it must be convertible to a string via a call to str(item.id).

classmethod load(stream, contentType=None, version=None)[source]

Reverses the effects of the dump() 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 dump() and as “future-proofing”.

classmethod loads(data, contentType=None, version=None)[source]

[OPTIONAL] Identical to load(), except the serialized form is provided as a string representation in data instead of as a stream. The default implementation just wraps load().

Standard Item Implementations

The pysyncml.items.note module defines the abstract interface to a Note object via the pysyncml.NoteItem class.

Warning

Be aware that this is NOT an object type defined by the SyncML specification, but rather is a de-facto standard object type.

class pysyncml.items.note.NoteItem(name=None, body=None, *args, **kw)[source]

The NoteItem is an abstract sub-class of a pysyncml.Item which primarily defines a “Note” as having a name and a body. It also provides implementations of the dump() and load() methods, which support the following content-types:

  • text/plain
  • text/x-s4j-sifn, version 1.1

Warning

The text/plain content-type does NOT support the name attribute, and therefore does not get synchronized when using that content-type.

NoteItem constructor which takes attributes name and body.

dump(stream, contentType=None, version=None)[source]

Serializes this NoteItem to a byte-stream and writes it to the file-like object stream. contentType and version must be one of the supported content-types, and if not specified, will default to text/plain.

classmethod load(stream, contentType=None, version=None)[source]

Reverses the effects of the dump() method, creating a NoteItem from the specified file-like stream object.

«  Module: pysyncml.ctype   ::   Contents   ::   Module: pysyncml.model.adapter  »