Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2006-06-18 05:31:18 (GMT)
committer Dan Williams <dcbw@redhat.com>2006-06-18 05:31:18 (GMT)
commit9f1c77a55abfaafdac7912df1ddff07fe7ea3a01 (patch)
tree3ca5700e7d6c67084f9e4d0ea3308ae8df4de672 /sugar
parentafc587212eb908420b8fb186cecc324753a5bbb1 (diff)
Add serialize/deserialize functions for Service objects
Diffstat (limited to 'sugar')
-rw-r--r--sugar/presence/Service.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/sugar/presence/Service.py b/sugar/presence/Service.py
index c97830f..4de43b8 100644
--- a/sugar/presence/Service.py
+++ b/sugar/presence/Service.py
@@ -1,6 +1,7 @@
import avahi
from sugar import util
import string
+import dbus
def _txt_to_dict(txt):
"""Convert an avahi-returned TXT record formatted
@@ -56,6 +57,25 @@ def is_multicast_address(address):
return True
return False
+def deserialize(sdict):
+ try:
+ name = sdict['name']
+ full_stype = sdict['full_stype']
+ activity_stype = sdict['activity_stype']
+ domain = sdict['domain']
+ port = sdict['port']
+ properties = sdict['properties']
+ except KeyError, exc:
+ raise ValueError("Serialized service object was not valid.")
+
+ address = None
+ try:
+ address = sdict['address']
+ except KeyError:
+ pass
+ return Service(name, full_stype, domain, address=address,
+ port=port, properties=properties)
+
_ACTIVITY_UID_TAG = "ActivityUID"
@@ -113,6 +133,18 @@ class Service(object):
if uid and not self._properties.has_key(_ACTIVITY_UID_TAG):
self._properties[_ACTIVITY_UID_TAG] = uid
+ def serialize(self):
+ sdict = {}
+ sdict['name'] = dbus.Variant(self._name)
+ sdict['full_stype'] = dbus.Variant(self._full_stype)
+ sdict['activity_stype'] = dbus.Variant(self._activity_stype)
+ sdict['domain'] = dbus.Variant(self._domain)
+ if self._address:
+ sdict['address'] = dbus.Variant(self._address)
+ sdict['port'] = dbus.Variant(self._port)
+ sdict['properties'] = dbus.Variant(self._properties)
+ return sdict
+
def get_name(self):
"""Return the service's name, usually that of the
buddy who provides it."""