Пример #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")
Пример #2
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")
Пример #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'})
Пример #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)
Пример #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)
Пример #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))
Пример #7
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'
                })
Пример #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))
Пример #9
0
 def testPythonType(self):
   obj = object()
   self.assertEqual(utils.coerceDbusType(obj), obj)
Пример #10
0
 def testBoolean(self):
   self.assertEqual(utils.coerceDbusType(dbus.Boolean(0)), False)
   self.assertEqual(utils.coerceDbusType(dbus.Boolean(1)), True)
Пример #11
0
 def testDouble(self):
   self.assertEqual(utils.coerceDbusType(dbus.Double(12.3)), 12.3)
Пример #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)
Пример #13
0
 def testPythonType(self):
     obj = object()
     self.assertEqual(utils.coerceDbusType(obj), obj)
Пример #14
0
 def testBoolean(self):
     self.assertEqual(utils.coerceDbusType(dbus.Boolean(0)), False)
     self.assertEqual(utils.coerceDbusType(dbus.Boolean(1)), True)
Пример #15
0
 def testDouble(self):
     self.assertEqual(utils.coerceDbusType(dbus.Double(12.3)), 12.3)
Пример #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)