627
627
def _get_all_dbus_properties(self):
628
628
"""Returns a generator of (name, attribute) pairs
630
return ((prop.__get__(self)._dbus_name, prop.__get__(self))
631
for cls in self.__class__.__mro__
632
for name, prop in inspect.getmembers(cls, self._is_dbus_property))
630
return ((prop._dbus_name, prop)
632
inspect.getmembers(self, self._is_dbus_property))
634
# def _get_dbus_property(self, interface_name, property_name):
635
# """Returns a bound method if one exists which is a D-Bus
636
# property with the specified name and interface.
638
# print("get_property({0!r}, {1!r}".format(interface_name, property_name),file=sys.stderr)
639
# print(dir(self), sys.stderr)
640
# for name in (property_name,
641
# property_name + "_dbus_property"):
642
# prop = getattr(self, name, None)
644
# or not self._is_dbus_property(prop)
645
# or prop._dbus_name != property_name
646
# or (interface_name and prop._dbus_interface
647
# and interface_name != prop._dbus_interface)):
651
# raise DBusPropertyNotFound(self.dbus_object_path + ":"
652
# + interface_name + "."
634
655
def _get_dbus_property(self, interface_name, property_name):
635
656
"""Returns a bound method if one exists which is a D-Bus
636
657
property with the specified name and interface.
638
for cls in self.__class__.__mro__:
639
for name, value in inspect.getmembers(cls, self._is_dbus_property):
640
if value._dbus_name == property_name and value._dbus_interface == interface_name:
641
return value.__get__(self)
659
for name, value in inspect.getmembers(self, self._is_dbus_property):
660
if value._dbus_name == property_name and value._dbus_interface == interface_name:
643
663
# No such property
644
664
raise DBusPropertyNotFound(self.dbus_object_path + ":"
755
775
return dbus.String(dt.isoformat(),
756
776
variant_level=variant_level)
758
class transitional_dbus_metaclass(DBusObjectWithProperties.__metaclass__):
778
class transitional_clientdbus(DBusObjectWithProperties.__metaclass__):
759
779
def __new__(mcs, name, bases, attr):
760
for attrname, old_dbusobj in inspect.getmembers(bases[0]):
780
for key, old_dbusobj in attr.items():
761
781
new_interface = getattr(old_dbusobj, "_dbus_interface", "").replace("se.bsnet.fukt.", "se.recompile.")
762
if (getattr(old_dbusobj, "_dbus_is_signal", False)
763
and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
782
if getattr(old_dbusobj, "_dbus_is_signal", False):
764
783
unwrappedfunc = dict(zip(old_dbusobj.func_code.co_freevars,
765
784
old_dbusobj.__closure__))["func"].cell_contents
766
785
newfunc = types.FunctionType(unwrappedfunc.func_code,
770
789
unwrappedfunc.func_closure)
771
790
new_dbusfunc = dbus.service.signal(
772
791
new_interface, old_dbusobj._dbus_signature)(newfunc)
773
attr["_transitional_" + attrname] = new_dbusfunc
792
attr["_transitional_{0}_1".format(key)] = new_dbusfunc
793
attr["_transitional_{0}_0".format(key)] = old_dbusobj
775
794
def fixscope(func1, func2):
776
795
def newcall(*args, **kwargs):
777
796
func1(*args, **kwargs)
778
797
func2(*args, **kwargs)
781
attr[attrname] = fixscope(old_dbusobj, new_dbusfunc)
800
attr[key] = fixscope(
801
old_dbusobj, attr["_transitional_{0}_1".format(key)])
783
elif (getattr(old_dbusobj, "_dbus_is_method", False)
784
and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
803
if getattr(old_dbusobj, "_dbus_is_method", False):
785
804
new_dbusfunc = (dbus.service.method
787
806
old_dbusobj._dbus_in_signature,
793
812
old_dbusobj.func_defaults,
794
813
old_dbusobj.func_closure)))
796
attr[attrname] = new_dbusfunc
797
elif (getattr(old_dbusobj, "_dbus_is_property", False)
798
and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
815
attr["_transitional_{0}".format(key)] = new_dbusfunc
816
if getattr(old_dbusobj, "_dbus_is_property", False):
799
817
new_dbusfunc = (dbus_service_property
801
819
old_dbusobj._dbus_signature,
808
826
old_dbusobj.func_defaults,
809
827
old_dbusobj.func_closure)))
811
attr[attrname] = new_dbusfunc
829
attr["_transitional_{0}".format(key)] = new_dbusfunc
812
830
return type.__new__(mcs, name, bases, attr)
814
832
class ClientDBus(Client, DBusObjectWithProperties):
1226
1246
return super(ProxyClient, self).__setattr__(name, value)
1227
1247
self._pipe.send(('setattr', name, value))
1229
class ClientDBusTransitional(ClientDBus):
1230
__metaclass__ = transitional_dbus_metaclass
1232
1250
class ClientHandler(socketserver.BaseRequestHandler, object):
1233
1251
"""A class to handle client connections.
2053
class MandosDBusServiceTransitional(MandosDBusService):
2054
__metaclass__ = transitional_dbus_metaclass
2055
mandos_dbus_service = MandosDBusServiceTransitional()
2071
mandos_dbus_service = MandosDBusService()
2058
2074
"Cleanup function; run on exit"