Ensure that deserialized Service arguments are not in Unicode (for the moment), since dbus passes strings as such

This commit is contained in:
Dan Williams 2006-06-19 09:47:04 -04:00
parent ea27f1ad8f
commit 44752264e0

View File

@ -60,9 +60,17 @@ def is_multicast_address(address):
def deserialize(sdict): def deserialize(sdict):
try: try:
name = sdict['name'] name = sdict['name']
if type(name) == type(u""):
name = name.encode()
full_stype = sdict['full_stype'] full_stype = sdict['full_stype']
if type(full_stype) == type(u""):
full_stype = full_stype.encode()
activity_stype = sdict['activity_stype'] activity_stype = sdict['activity_stype']
if type(activity_stype) == type(u""):
activity_stype = activity_stype.encode()
domain = sdict['domain'] domain = sdict['domain']
if type(domain) == type(u""):
domain = domain.encode()
port = sdict['port'] port = sdict['port']
properties = sdict['properties'] properties = sdict['properties']
except KeyError, exc: except KeyError, exc:
@ -71,6 +79,8 @@ def deserialize(sdict):
address = None address = None
try: try:
address = sdict['address'] address = sdict['address']
if type(address) == type(u""):
address = address.encode()
except KeyError: except KeyError:
pass pass
return Service(name, full_stype, domain, address=address, return Service(name, full_stype, domain, address=address,
@ -198,8 +208,8 @@ class Service(object):
return self._port return self._port
def set_port(self, port): def set_port(self, port):
if type(port) != type(1): if type(port) != type(1) or (port <= 1024 and port > 65536):
raise ValueError("must specify a valid port number.") raise ValueError("must specify a valid port number between 1024 and 65536.")
self._port = port self._port = port
def get_publisher_address(self): def get_publisher_address(self):