コード例 #1
0
ファイル: test_utils.py プロジェクト: ebroder/debmarshal
 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
ファイル: test_utils.py プロジェクト: ebroder/debmarshal
  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
ファイル: privops.py プロジェクト: ytrstu/debmarshal
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
ファイル: privops.py プロジェクト: danieldittmann/debmarshal
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
ファイル: privops.py プロジェクト: ytrstu/debmarshal
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
ファイル: privops.py プロジェクト: danieldittmann/debmarshal
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
ファイル: test_utils.py プロジェクト: ebroder/debmarshal
 def testPythonType(self):
   obj = object()
   self.assertEqual(utils.coerceDbusType(obj), obj)
コード例 #10
0
ファイル: test_utils.py プロジェクト: ebroder/debmarshal
 def testBoolean(self):
   self.assertEqual(utils.coerceDbusType(dbus.Boolean(0)), False)
   self.assertEqual(utils.coerceDbusType(dbus.Boolean(1)), True)
コード例 #11
0
ファイル: test_utils.py プロジェクト: ebroder/debmarshal
 def testDouble(self):
   self.assertEqual(utils.coerceDbusType(dbus.Double(12.3)), 12.3)
コード例 #12
0
ファイル: test_utils.py プロジェクト: ebroder/debmarshal
 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)