Beispiel #1
0
 def testStrings(self):
   self.assertEqual(utils.coerceDbusType(dbus.UTF8String("blah")), "blah")
   self.assertEqual(utils.coerceDbusType(dbus.ByteArray(u"blah")), "blah")
   self.assertEqual(utils.coerceDbusType(dbus.String(u"blah")), u"blah")
   self.assertEqual(utils.coerceDbusType(dbus.Signature(u"ssi")), u"ssi")
   self.assertEqual(utils.coerceDbusType(dbus.ObjectPath(
       u"/com/googlecode/debmarshal/Privops")), u"/com/googlecode/debmarshal/Privops")
 def testStrings(self):
     self.assertEqual(utils.coerceDbusType(dbus.UTF8String("blah")), "blah")
     self.assertEqual(utils.coerceDbusType(dbus.ByteArray(u"blah")), "blah")
     self.assertEqual(utils.coerceDbusType(dbus.String(u"blah")), u"blah")
     self.assertEqual(utils.coerceDbusType(dbus.Signature(u"ssi")), u"ssi")
     self.assertEqual(
         utils.coerceDbusType(
             dbus.ObjectPath(u"/com/googlecode/debmarshal/Privops")),
         u"/com/googlecode/debmarshal/Privops")
Beispiel #3
0
  def testCollections(self):
    self.assertEqual(
        utils.coerceDbusType(dbus.Struct((
            dbus.String('x'), dbus.String('y'), dbus.String('z')))),
        ('x', 'y', 'z'))

    self.assertEqual(
        utils.coerceDbusType(dbus.Array([
            dbus.Int16(12), dbus.Int16(13), dbus.Int16(14)])),
        [12, 13, 14])

    self.assertEqual(
        utils.coerceDbusType(dbus.Dictionary({
            dbus.Int16(12): dbus.String('foo'),
            dbus.Int16(13): dbus.String('bar')})),
        {12: 'foo', 13: 'bar'})
Beispiel #4
0
def _coerceDbusArgs(f, *args, **kwargs):
  """Decorator to coerce all positional arguments into normal Python types.

  Arguments to DBus methods usually come in as specialized DBus types,
  but those are annoying to work with, and don't contain any
  information we care about keeping, so let's coerce them into normal
  Python types instead.
  """
  return f(*(utils.coerceDbusType(arg) for arg in args), **kwargs)
Beispiel #5
0
def _coerceDbusArgs(f, *args, **kwargs):
    """Decorator to coerce all positional arguments into normal Python types.

  Arguments to DBus methods usually come in as specialized DBus types,
  but those are annoying to work with, and don't contain any
  information we care about keeping, so let's coerce them into normal
  Python types instead.
  """
    return f(*(utils.coerceDbusType(arg) for arg in args), **kwargs)
Beispiel #6
0
def call(method, *args):
  """Call a privileged operation.

  This function handles calling privileged operations. Currently,
  these calls are simply dispatched over dbus.

  Args:
    method: The name of the method to call.
    *args: The arguments to pass to the method.
  """
  proxy = dbus.SystemBus().get_object(DBUS_BUS_NAME, DBUS_OBJECT_PATH)
  return utils.coerceDbusType(proxy.get_dbus_method(
      method, dbus_interface=DBUS_INTERFACE)(*args))
    def testCollections(self):
        self.assertEqual(
            utils.coerceDbusType(
                dbus.Struct(
                    (dbus.String('x'), dbus.String('y'), dbus.String('z')))),
            ('x', 'y', 'z'))

        self.assertEqual(
            utils.coerceDbusType(
                dbus.Array([dbus.Int16(12),
                            dbus.Int16(13),
                            dbus.Int16(14)])), [12, 13, 14])

        self.assertEqual(
            utils.coerceDbusType(
                dbus.Dictionary({
                    dbus.Int16(12): dbus.String('foo'),
                    dbus.Int16(13): dbus.String('bar')
                })), {
                    12: 'foo',
                    13: 'bar'
                })
Beispiel #8
0
def call(method, *args):
    """Call a privileged operation.

  This function handles calling privileged operations. Currently,
  these calls are simply dispatched over dbus.

  Args:
    method: The name of the method to call.
    *args: The arguments to pass to the method.
  """
    proxy = dbus.SystemBus().get_object(DBUS_BUS_NAME, DBUS_OBJECT_PATH)
    return utils.coerceDbusType(
        proxy.get_dbus_method(method, dbus_interface=DBUS_INTERFACE)(*args))
Beispiel #9
0
 def testPythonType(self):
   obj = object()
   self.assertEqual(utils.coerceDbusType(obj), obj)
Beispiel #10
0
 def testBoolean(self):
   self.assertEqual(utils.coerceDbusType(dbus.Boolean(0)), False)
   self.assertEqual(utils.coerceDbusType(dbus.Boolean(1)), True)
Beispiel #11
0
 def testDouble(self):
   self.assertEqual(utils.coerceDbusType(dbus.Double(12.3)), 12.3)
Beispiel #12
0
 def testInts(self):
   self.assertEqual(utils.coerceDbusType(dbus.Byte(12)), 12)
   self.assertEqual(utils.coerceDbusType(dbus.Int16(12)), 12)
   self.assertEqual(utils.coerceDbusType(dbus.Int32(12)), 12)
   self.assertEqual(utils.coerceDbusType(dbus.UInt16(12)), 12)
   self.assertEqual(utils.coerceDbusType(dbus.UInt32(12)), 12)
Beispiel #13
0
 def testPythonType(self):
     obj = object()
     self.assertEqual(utils.coerceDbusType(obj), obj)
Beispiel #14
0
 def testBoolean(self):
     self.assertEqual(utils.coerceDbusType(dbus.Boolean(0)), False)
     self.assertEqual(utils.coerceDbusType(dbus.Boolean(1)), True)
Beispiel #15
0
 def testDouble(self):
     self.assertEqual(utils.coerceDbusType(dbus.Double(12.3)), 12.3)
Beispiel #16
0
 def testInts(self):
     self.assertEqual(utils.coerceDbusType(dbus.Byte(12)), 12)
     self.assertEqual(utils.coerceDbusType(dbus.Int16(12)), 12)
     self.assertEqual(utils.coerceDbusType(dbus.Int32(12)), 12)
     self.assertEqual(utils.coerceDbusType(dbus.UInt16(12)), 12)
     self.assertEqual(utils.coerceDbusType(dbus.UInt32(12)), 12)