當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。