2
Different versions of the Python DBus bindings return different types
3
to represent integers, strings, lists, etc. Older versions return
4
builtin Python types: C{int}, C{str}, C{list}, etc. Newer versions
5
return DBus-specific wrappers: C{Int16}, C{String}, C{Array}, etc.
6
Failures occur when DBus types are used because bpickle doesn't know
7
that an C{Int16} is really an C{int} and that an C{Array} is really a
10
L{install} and L{uninstall} can install and remove extensions that
11
make bpickle work with DBus types.
16
from landscape.lib import bpickle
20
"""Install bpickle extensions for DBus types."""
21
for type, function in get_dbus_types():
22
bpickle.dumps_table[type] = function
26
"""Uninstall bpickle extensions for DBus types."""
27
for type, function in get_dbus_types():
28
del bpickle.dumps_table[type]
31
def dumps_utf8string(obj):
33
Convert the specified L{dbus.types.UTF8String} to bpickle's
34
representation for C{unicode} data.
36
return "u%s:%s" % (len(obj), obj)
39
def dumps_double(obj):
41
Convert a dbus.types.Double into a floating point representation.
43
return "f%r;" % float(obj)
48
Generator yields C{(type, bpickle_function)} for available DBus
51
for (type_name, function) in [("Boolean", bpickle.dumps_bool),
52
("Int16", bpickle.dumps_int),
53
("UInt16", bpickle.dumps_int),
54
("Int32", bpickle.dumps_int),
55
("UInt32", bpickle.dumps_int),
56
("Int64", bpickle.dumps_int),
57
("UInt64", bpickle.dumps_int),
58
("Double", dumps_double),
59
("Array", bpickle.dumps_list),
60
("Dictionary", bpickle.dumps_dict),
61
("String", bpickle.dumps_unicode),
62
("UTF8String", dumps_utf8string)]:
63
type = getattr(dbus.types, type_name, None)