pysyncml 0.1 documentation

Module: pysyncml.change.merger

«  Module: pysyncml.agents   ::   Contents   ::   Module: pysyncml.change.tracker  »

Module: pysyncml.change.merger

The pysyncml.change.merger is a helper package that provides routines to help with managing change-specs on a slightly higher level than pysyncml.change.tracker by actually detecting changes, reporting them to a tracker and merging them back together. Furthermore, it provides routines to help with the detection and merging of text-based changes, either multi-line or singl-line based.

class pysyncml.change.merger.AttributeMerger(changeSpec, *args, **kw)[source]

A merger that simplifies usage of the pysyncml.AttributeChangeTracker and allows it to be used by a CompositeMerger.

class pysyncml.change.merger.AttributeMergerFactory(*args, **kw)[source]

A merger factory for generating AttributeMerger merger objects.

class pysyncml.change.merger.CompositeMerger(factory, changeSpec)[source]

A composite merger is an attribute-based merger that allows a default merger for attributes to be specified, which can then be overridden for specific attributes.

TODO: is there perhaps a better way to define when a subsidiary merger is a dispatch merger (i.e. takes the attribute name as operational parameter) than to use the factory “sharedDefault” parameter?
class pysyncml.change.merger.CompositeMergerFactory(sharedDefault=True, default=None, mergers=None, **kw)[source]

A merger factory for generating CompositeMerger merger objects, which allows control of what kind of merger to use on a per-attribute basis.

The CompositeMergerFactory constructor accepts the following parameters:

  • default – The default merger factory (if unspecified, defaults to an AttributeMergerFactory). See sharedDefault if the default is not an attribute-based merger factory.
  • mergers – A dictionary of (attribute => MergerFactory) that override the default merger factory for the specified attribute. If unspecified, all attributes will use the default merger factory.
  • sharedDefault – The sharedDefault parameter controls how default attributes get handled. When True (the default), then all default attributes will share a Merger and the Merger will be passed the attribute name during operations. When False, then each attribute will get its own Merger and operations will not get the attribute name. It is important that the default and sharedDefault parameters match - for example, if default is set to a TextMergerFactory, then sharedDefault must be set to False.
class pysyncml.change.merger.Merger[source]

Abstract base class for objects returned by the MergerFactory subclasses.


Returns the current change-spec representing all calls to pushChange() since construction of this merger.

mergeChanges(attribute, localValue, remoteValue)[source]

Returns the value of the specified attribute as determined by the change-spec stored by this, the current localValue of this SyncML peer (i.e. the serve-side) and the client-provided remoteValue (i.e. of the remote client-side). Raises a pysyncml.ConflictError if the local changes conflict with the value provided by the remote peer.

If localValue is None, the field is assumed to not exist locally. Conversely, if remoteValue is None, the field is assumed to not exist on the remote peer. If both are None (or, more generally speaking, equal), the value is returned as-is without further investigation.

pushChange(attribute, currentValue, newValue)[source]

Record the change to the specified attribute from the original value currentValue to newValue. The merger object itself (i.e. self) is returned, allowing multiple changes to be chained. The change-spec returned by getChangeSpec() will be updated according to this merger’s change detection strategy.

If currentValue is None, the field is assumed to be added. Conversely, if newValue is None, the field is assumed to be deleted. If both are None (or, more generally speaking, equal), the request is ignored.

class pysyncml.change.merger.MergerFactory[source]

Abstract base class for factories to help with reporting and merging pysyncml change-specs.


Returns a Merger for the specified changeSpec which can be None if the merger is intended to generate a change-spec.

class pysyncml.change.merger.TextMerger(multiLine, changeSpec, *args, **kw)[source]

A merger that simplifies usage of the pysyncml.ListChangeTracker and allows it to be used by a CompositeMerger.

TODO: currently, the merging algorithm is fairly aggressive (i.e. it may merge changes that should probably be conflicts). This should be made an option to provide either aggressive or conservative merging.

class pysyncml.change.merger.TextMergerFactory(multiLine=True, *args, **kw)[source]

A merger factory for generating TextMerger merger objects.

«  Module: pysyncml.agents   ::   Contents   ::   Module: pysyncml.change.tracker  »