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