当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.ArgumentError方法代码示例

本文整理汇总了Python中ctypes.ArgumentError方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.ArgumentError方法的具体用法?Python ctypes.ArgumentError怎么用?Python ctypes.ArgumentError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.ArgumentError方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setProperty

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def setProperty(self, name, value):
        if name == 'voice':
            if value is None:
                return
            try:
                utf8Value = toUtf8(value)
                _espeak.SetVoiceByName(utf8Value)
            except ctypes.ArgumentError as e:
                raise ValueError(str(e))
        elif name == 'rate':
            try:
                _espeak.SetParameter(_espeak.RATE, value, 0)
            except ctypes.ArgumentError as e:
                raise ValueError(str(e))
        elif name == 'volume':
            try:
                _espeak.SetParameter(
                    _espeak.VOLUME, int(round(value * 100, 2)), 0)
            except TypeError as e:
                raise ValueError(str(e))
        else:
            raise KeyError('unknown property %s' % name) 
开发者ID:nateshmbhat,项目名称:pyttsx3,代码行数:24,代码来源:espeak.py

示例2: cast_func_to_c_void_p

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def cast_func_to_c_void_p(func, cfunctype):
  """Casts a native function pointer or a Python callable into `c_void_p`.

  Args:
    func: A callable, or a `c_void_p` pointing to a native function, or `None`.
    cfunctype: A `CFUNCTYPE` prototype that is used to wrap `func` if it is
      a Python callable.

  Returns:
    A tuple `(func_ptr, wrapped_pyfunc)`, where `func_ptr` is a `c_void_p`
    object, and `wrapped_pyfunc` is a `CFUNCTYPE` object that wraps `func` if
    it is a Python callable. (If `func` is not a Python callable then
    `wrapped_pyfunc` is `None`.)
  """
  if not (callable(func) or isinstance(func, ctypes.c_void_p) or func is None):
    raise TypeError(_INVALID_CALLBACK_TYPE.format(func))
  try:
    new_func_ptr = ctypes.cast(func, ctypes.c_void_p)
    wrapped_pyfunc = None
  except ctypes.ArgumentError:
    wrapped_pyfunc = cfunctype(func)
    new_func_ptr = ctypes.cast(wrapped_pyfunc, ctypes.c_void_p)
  return new_func_ptr, wrapped_pyfunc 
开发者ID:deepmind,项目名称:dm_control,代码行数:25,代码来源:util.py

示例3: _coord_byval

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def _coord_byval(coord):
    """
    Turns a COORD object into a c_long.
    This will cause it to be passed by value instead of by reference. (That is what I think at least.)

    When runing ``ptipython`` is run (only with IPython), we often got the following error::

         Error in 'SetConsoleCursorPosition'.
         ArgumentError("argument 2: <class 'TypeError'>: wrong type",)
     argument 2: <class 'TypeError'>: wrong type

    It was solved by turning ``COORD`` parameters into a ``c_long`` like this.

    More info: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx
    """
    return c_long(coord.Y * 0x10000 | coord.X & 0xFFFF)


#: If True: write the output of the renderer also to the following file. This
#: is very useful for debugging. (e.g.: to see that we don't write more bytes
#: than required.) 
开发者ID:bkerler,项目名称:android_universal,代码行数:23,代码来源:win32_output.py

示例4: _winapi

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def _winapi(self, func, *a, **kw):
        """
        Flush and call win API function.
        """
        self.flush()

        if _DEBUG_RENDER_OUTPUT:
            self.LOG.write(('%r' % func.__name__).encode('utf-8') + b'\n')
            self.LOG.write(b'     ' + ', '.join(['%r' % i for i in a]).encode('utf-8') + b'\n')
            self.LOG.write(b'     ' + ', '.join(['%r' % type(i) for i in a]).encode('utf-8') + b'\n')
            self.LOG.flush()

        try:
            return func(*a, **kw)
        except ArgumentError as e:
            if _DEBUG_RENDER_OUTPUT:
                self.LOG.write(('    Error in %r %r %s\n' % (func.__name__, e, e)).encode('utf-8')) 
开发者ID:bkerler,项目名称:android_universal,代码行数:19,代码来源:win32_output.py

示例5: test_arguments

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_arguments(self):
        """ Test that arguments are coerced from arrays """
        c_forward_pointer.restype = ctypes.c_void_p
        c_forward_pointer.argtypes = (ndpointer(ndim=2),)

        c_forward_pointer(np.zeros((2, 3)))
        # too many dimensions
        assert_raises(
            ctypes.ArgumentError, c_forward_pointer, np.zeros((2, 3, 4))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_ctypeslib.py

示例6: test_ascii_strict

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_ascii_strict(self):
        wcslen = self.wcslen
        ctypes.set_conversion_mode("ascii", "strict")
        # no conversions take place with unicode arguments
        self.assertEqual(wcslen(u"abc"), 3)
        self.assertEqual(wcslen(u"ab\u2070"), 3)
        # string args are converted
        self.assertEqual(wcslen("abc"), 3)
        self.assertRaises(ctypes.ArgumentError, wcslen, "ab�") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_unicode.py

示例7: test_noctypes_argtype

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_noctypes_argtype(self):
        import _ctypes_test
        from ctypes import CDLL, c_void_p, ArgumentError

        func = CDLL(_ctypes_test.__file__)._testfunc_p_p
        func.restype = c_void_p
        # TypeError: has no from_param method
        self.assertRaises(TypeError, setattr, func, "argtypes", (object,))

        class Adapter(object):
            def from_param(cls, obj):
                return None

        func.argtypes = (Adapter(),)
        self.assertEqual(func(None), None)
        self.assertEqual(func(object()), None)

        class Adapter(object):
            def from_param(cls, obj):
                return obj

        func.argtypes = (Adapter(),)
        # don't know how to convert parameter 1
        self.assertRaises(ArgumentError, func, object())
        self.assertEqual(func(c_void_p(42)), 42)

        class Adapter(object):
            def from_param(cls, obj):
                raise ValueError(obj)

        func.argtypes = (Adapter(),)
        # ArgumentError: argument 1: ValueError: 99
        self.assertRaises(ArgumentError, func, 99) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:test_parameters.py

示例8: test_ascii_strict

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_ascii_strict(self):
            ctypes.set_conversion_mode("ascii", "strict")
            # no conversions take place with unicode arguments
            self.assertEqual(wcslen(u"abc"), 3)
            self.assertEqual(wcslen(u"ab\u2070"), 3)
            # string args are converted
            self.assertEqual(wcslen("abc"), 3)
            self.assertRaises(ctypes.ArgumentError, wcslen, "ab�") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:10,代码来源:test_unicode.py

示例9: test_ascii_replace

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_ascii_replace(self):
            ctypes.set_conversion_mode("ascii", "strict")
            self.assertEqual(func("abc"), "abc")
            self.assertEqual(func(u"abc"), "abc")
            self.assertRaises(ctypes.ArgumentError, func, u"ab�") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:7,代码来源:test_unicode.py

示例10: test_noctypes_argtype

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_noctypes_argtype(self):
        import _ctypes_test
        from ctypes import CDLL, c_void_p, ArgumentError

        func = CDLL(_ctypes_test.__file__)._testfunc_p_p
        func.restype = c_void_p
        # TypeError: has no from_param method
        self.assertRaises(TypeError, setattr, func, "argtypes", (object,))

        class Adapter(object):
            def from_param(cls, obj):
                return None

        func.argtypes = (Adapter(),)
        self.assertEqual(func(None), None)
        self.assertEqual(func(object()), None)

        class Adapter(object):
            def from_param(cls, obj):
                return obj

        func.argtypes = (Adapter(),)
        # don't know how to convert parameter 1
        self.assertRaises(ArgumentError, func, object())
        self.assertEqual(func(c_void_p(42)), 42)

        class Adapter(object):
            def from_param(cls, obj):
                raise ValueError(obj)

        func.argtypes = (Adapter(),)
        # ArgumentError: argument 1: ValueError: 99
        self.assertRaises(ArgumentError, func, 99)


################################################################ 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:38,代码来源:test_parameters.py

示例11: test_ascii_replace

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_ascii_replace(self):
        func = self.func
        ctypes.set_conversion_mode("ascii", "strict")
        self.assertEqual(func("abc"), "abc")
        self.assertEqual(func(u"abc"), "abc")
        self.assertRaises(ctypes.ArgumentError, func, u"ab�") 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:8,代码来源:test_unicode.py

示例12: test_wcslen

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def test_wcslen(self):
        dll = ctypes.CDLL(_ctypes_test.__file__)
        wcslen = dll.my_wcslen
        wcslen.argtypes = [ctypes.c_wchar_p]

        self.assertEqual(wcslen("abc"), 3)
        self.assertEqual(wcslen("ab\u2070"), 3)
        self.assertRaises(ctypes.ArgumentError, wcslen, b"ab\xe4") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_unicode.py

示例13: read

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import ArgumentError [as 别名]
def read(self, full_shape=None):
        file = open(self._file_path, 'r')
        str_in = []
        if self._type == 'csv' or self._type == 'txt':
            for row in csv.reader(file):
                if len(row) != 0:
                    str_in.append(row)
        else:
            raise ArgumentError(self._type + ' file is not supported by TensorReader.')
        file.close()

        order = len(str_in[0]) - 1
        entry_count = len(str_in)
        value = np.zeros(entry_count)
        idx = np.zeros(shape=(entry_count, order), dtype=int)
        for row in range(entry_count):
            entry = str_in[row]
            idx[row] = np.array([int(entry[mode]) for mode in range(order)])
            value[row] = float(entry[-1])

        if full_shape==None:
            max_dim = np.max(idx, axis=0) + np.ones(order).astype(int)
        else:
            max_dim = full_shape

        self._sparse_data = tf.SparseTensor(indices=idx, values=value, dense_shape=max_dim)
        self._full_data = tf.sparse_tensor_to_dense(self._sparse_data, validate_indices=False) 
开发者ID:Large-Scale-Tensor-Decomposition,项目名称:tensorD,代码行数:29,代码来源:reader.py


注:本文中的ctypes.ArgumentError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。