pysyncml 0.1 documentation

Module: pysyncml.context

«  Module: pysyncml.cli   ::   Contents   ::   Module: pysyncml.ctype  »

Module: pysyncml.context

The pysyncml.context package provides the entry point into most pysyncml operations via the pysyncml.Context class.

class pysyncml.context.Context(engine=None, storage=None, prefix='pysyncml', owner=None, autoCommit=None, router=None, protocol=None, synchronizer=None, codec=None)[source]

The pysyncml Context object creates an environment for an Adapter to be created and evaluated in. The primary object is to provide access to a storage location so that SyncML state information can be stored across multiple synchronization messages, sessions and peers. However, it can also be used to specify operational parameters, such as whether or not to support specific codecs and which to use as the default.

The Context constructor accepts the following parameters, of which all are optional:

  • owner – an integer owner ID. Necessary primarily when the adapter storage is shared between multiple users/adapter agents (i.e. in server contexts). If it is not shared, owner can be left as None (the default).
  • storage

    the sqlalchemy storage specification where all the SyncML- related data should be stored.

    NOTE: can be overridden by parameter engine.

    NOTE: the storage driver MUST support cascading deletes; this is done automatically for connections created directly by pysyncml for mySQL and sqlite, but it is up to the calling program to ensure this for other databases or if the database engine is passed in via parameter engine. Specifically, when pysyncml creates the sqlalchemy engine (i.e. by calling sqlalchemy.create_engine(storage)), then InnoDB is requested for mySQL tables and PRAGMA foreign_keys=ON is issued for sqlite databases. pysyncml provides a helper function to ensure that sqlite databases have cascading deletes enabled:

    import sqlalchemy, pysyncml
    db = sqlalchemy.create_engine(...)
  • engine

    the sqlalchemy storage engine where all the SyncML-related data should be stored.

    NOTE: overrides parameter storage.

    NOTE: see notes under parameter storage for details on cascading delete support.

    TODO: it would be great to add a check to ensure that provided storage engines have cascading deletes enabled.

  • prefix – sets a database table name prefix. This is primarily useful when using the engine parameter, as multiple pysyncml contexts can then be defined within the same database namespace. Defaults to pysyncml.
  • autoCommit – whether or not to execute a storage engine “commit” when syncing is complete. The default behavior is dependent on if engine is provided: if not None, then autoCommit defaults to False, otherwise, defaults to True.
  • router – overrides the default router with an object that must implement the interface specified by pysyncml.router.Router.
  • protocol – sets the semantic objective to/from protocol evaluation and resolution object, which must implement the pysyncml.protocol.Protocol interface.
  • synchronizer – this is the engine for handling sync requests and dispatching them to the various agents. If specified, the object must implement the pysyncml.synchronizer.Synchronizer interface.
  • codec – specify the codec used to encode the SyncML commands - typically either 'xml' (the default) or 'wbxml'. It can also be an object that implements the pysyncml.codec.Codec interface.

The Adapter constructor supports the following parameters:

  • devID – sets the local adapter’s device identifier. For servers, this should be the externally accessible URL that launches the SyncML transaction, and for clients this should be a unique ID, such as the IMEI number (for mobile phones). If not specified, it will be defaulted to the devID of the devinfo object. If it cannot be loaded from the database or from the devinfo, then it must be provided before any synchronization can begin.
  • name – sets the local adapter’s device name - usually a human-friendly description of this SyncML’s function.
  • devinfo – sets the local adapter pysyncml.devinfo.DeviceInfo. If not specified, it will be auto-loaded from the database. If it cannot be loaded from the database, then it must be provided before any synchronization can begin.
  • peer – TODO: document...
  • maxGuidSize – TODO: document...
  • maxMsgSize – TODO: document...
  • maxObjSize – TODO: document...
  • conflictPolicy – sets the default conflict handling policy for this adapter, and can be overriden on a per-store basis (applies only when operating as the server role).

The RemoteAdapter constructor supports the following parameters:

  • url – specifies the URL that this remote SyncML server can be reached at. The URL must be a fully-qualified URL.
  • auth

    set what kind of authentication scheme to use, which generally is one of the following values:

    indicates no authentication is required.


    specifies to use “Basic-Auth” authentication scheme.


    specifies to use MD5 “Digest-Auth” authentication scheme. NOTE: this may not be implemented yet...
  • username – if the auth is not None, then the username to authenticate as must be provided via this parameter.
  • password – if the auth is not None, then the password to authenticate with must be provided via this parameter.

«  Module: pysyncml.cli   ::   Contents   ::   Module: pysyncml.ctype  »