Back to index

python3.2  3.2.2
Namespaces | Classes | Functions | Variables
ctypes Namespace Reference

Namespaces

namespace  _endian
namespace  macholib
namespace  test
namespace  util
namespace  wintypes

Classes

class  py_object
class  c_short
class  c_ushort
class  c_long
class  c_ulong
class  c_int
class  c_uint
class  c_float
class  c_double
class  c_longdouble
class  c_longlong
class  c_ulonglong
class  c_ubyte
 def from_param(cls, val): return ('d', float(val), val) from_param = classmethod(from_param) More...
class  c_byte
 c_uchar = c_ubyte More...
class  c_char
class  c_char_p
class  c_void_p
class  c_bool
class  c_wchar_p
class  c_wchar
class  CDLL
class  PyDLL
class  WinDLL
class  HRESULT
class  OleDLL
class  LibraryLoader

Functions

def create_string_buffer
def c_buffer
def CFUNCTYPE
def WINFUNCTYPE
def _check_size
def create_unicode_buffer
def SetPointerType
def ARRAY
def WinError
def PYFUNCTYPE
def cast
def string_at
def wstring_at
def DllGetClassObject
def DllCanUnloadNow

Variables

string __version__ = "1.1.0"
 DEFAULT_MODE = RTLD_LOCAL
dictionary _c_functype_cache = {}
 "deprecated, use create_string_buffer instead" import warnings warnings.warn("c_buffer is deprecated, use create_string_buffer instead", DeprecationWarning, stacklevel=2)
 _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL
dictionary _win_functype_cache = {}
 c_int = c_long
 c_uint = c_ulong
 c_longdouble = c_double
 c_longlong = c_long
 c_ulonglong = c_ulong
 c_voidp = c_void_p
tuple cdll = LibraryLoader(CDLL)
tuple pydll = LibraryLoader(PyDLL)
tuple pythonapi = PyDLL("python dll", None, _sys.dllhandle)
tuple windll = LibraryLoader(WinDLL)
tuple oledll = LibraryLoader(OleDLL)
 GetLastError = windll.kernel32.GetLastError
 c_size_t = c_uint
 c_ssize_t = c_int
tuple memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)
 void *memmove(void *, const void *, size_t);
tuple memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)
 void *memset(void *, int, size_t)
tuple _cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)
tuple _string_at = PYFUNCTYPE(py_object, c_void_p, c_int)
tuple _wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)
 c_int8 = c_byte
 c_uint8 = c_ubyte

Detailed Description

create and manipulate C data types in Python

Function Documentation

def ctypes._check_size (   typ,
  typecode = None 
) [private]

Definition at line 144 of file __init__.py.

00144 
00145 def _check_size(typ, typecode=None):
00146     # Check if sizeof(ctypes_type) against struct.calcsize.  This
00147     # should protect somewhat against a misconfigured libffi.
00148     from struct import calcsize
00149     if typecode is None:
00150         # Most _type_ codes are the same as used in struct
00151         typecode = typ._type_
00152     actual, required = sizeof(typ), calcsize(typecode)
00153     if actual != required:
00154         raise SystemError("sizeof(%s) wrong: %d instead of %d" % \
00155                           (typ, actual, required))

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.ARRAY (   typ,
  len 
)

Definition at line 301 of file __init__.py.

00301 
00302 def ARRAY(typ, len):
00303     return typ * len

Here is the caller graph for this function:

def ctypes.c_buffer (   init,
  size = None 
)

Definition at line 67 of file __init__.py.

00067 
def c_buffer(init, size=None):

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.cast (   obj,
  typ 
)

Definition at line 478 of file __init__.py.

00478 
00479 def cast(obj, typ):
00480     return _cast(obj, obj, typ)

Here is the caller graph for this function:

def ctypes.CFUNCTYPE (   restype,
  argtypes,
  kw 
)
CFUNCTYPE(restype, *argtypes,
             use_errno=False, use_last_error=False) -> function prototype.

restype: the result type
argtypes: a sequence specifying the argument types

The function prototype can be called in different ways to create a
callable object:

prototype(integer address) -> foreign function
prototype(callable) -> create and return a C callable function from callable
prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method
prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal
prototype((function name, dll object)[, paramflags]) -> foreign function exported by name

Definition at line 75 of file __init__.py.

00075 
00076 def CFUNCTYPE(restype, *argtypes, **kw):
00077     """CFUNCTYPE(restype, *argtypes,
00078                  use_errno=False, use_last_error=False) -> function prototype.
00079 
00080     restype: the result type
00081     argtypes: a sequence specifying the argument types
00082 
00083     The function prototype can be called in different ways to create a
00084     callable object:
00085 
00086     prototype(integer address) -> foreign function
00087     prototype(callable) -> create and return a C callable function from callable
00088     prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method
00089     prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal
00090     prototype((function name, dll object)[, paramflags]) -> foreign function exported by name
00091     """
00092     flags = _FUNCFLAG_CDECL
00093     if kw.pop("use_errno", False):
00094         flags |= _FUNCFLAG_USE_ERRNO
00095     if kw.pop("use_last_error", False):
00096         flags |= _FUNCFLAG_USE_LASTERROR
00097     if kw:
00098         raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
00099     try:
00100         return _c_functype_cache[(restype, argtypes, flags)]
00101     except KeyError:
00102         class CFunctionType(_CFuncPtr):
00103             _argtypes_ = argtypes
00104             _restype_ = restype
00105             _flags_ = flags
00106         _c_functype_cache[(restype, argtypes, flags)] = CFunctionType
00107         return CFunctionType

Here is the caller graph for this function:

def ctypes.create_string_buffer (   init,
  size = None 
)
create_string_buffer(aBytes) -> character array
create_string_buffer(anInteger) -> character array
create_string_buffer(aString, anInteger) -> character array

Definition at line 49 of file __init__.py.

00049 
00050 def create_string_buffer(init, size=None):
00051     """create_string_buffer(aBytes) -> character array
00052     create_string_buffer(anInteger) -> character array
00053     create_string_buffer(aString, anInteger) -> character array
00054     """
00055     if isinstance(init, (str, bytes)):
00056         if size is None:
00057             size = len(init)+1
00058         buftype = c_char * size
00059         buf = buftype()
00060         buf.value = init
00061         return buf
00062     elif isinstance(init, int):
00063         buftype = c_char * init
00064         buf = buftype()
00065         return buf
00066     raise TypeError(init)

Here is the caller graph for this function:

def ctypes.create_unicode_buffer (   init,
  size = None 
)
create_unicode_buffer(aString) -> character array
create_unicode_buffer(anInteger) -> character array
create_unicode_buffer(aString, anInteger) -> character array

Definition at line 270 of file __init__.py.

00270 
00271 def create_unicode_buffer(init, size=None):
00272     """create_unicode_buffer(aString) -> character array
00273     create_unicode_buffer(anInteger) -> character array
00274     create_unicode_buffer(aString, anInteger) -> character array
00275     """
00276     if isinstance(init, (str, bytes)):
00277         if size is None:
00278             size = len(init)+1
00279         buftype = c_wchar * size
00280         buf = buftype()
00281         buf.value = init
00282         return buf
00283     elif isinstance(init, int):
00284         buftype = c_wchar * init
00285         buf = buftype()
00286         return buf
00287     raise TypeError(init)
00288 
00289 POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param
00290 
# XXX Deprecated

Here is the caller graph for this function:

Definition at line 510 of file __init__.py.

00510 
00511     def DllCanUnloadNow():
00512         try:
00513             ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*'])
00514         except ImportError:
00515             return 0 # S_OK
00516         return ccom.DllCanUnloadNow()

Here is the call graph for this function:

def ctypes.DllGetClassObject (   rclsid,
  riid,
  ppv 
)

Definition at line 502 of file __init__.py.

00502 
00503     def DllGetClassObject(rclsid, riid, ppv):
00504         try:
00505             ccom = __import__("comtypes.server.inprocserver", globals(), locals(), ['*'])
00506         except ImportError:
00507             return -2147221231 # CLASS_E_CLASSNOTAVAILABLE
00508         else:
00509             return ccom.DllGetClassObject(rclsid, riid, ppv)

Here is the call graph for this function:

def ctypes.PYFUNCTYPE (   restype,
  argtypes 
)

Definition at line 470 of file __init__.py.

00470 
00471 def PYFUNCTYPE(restype, *argtypes):
00472     class CFunctionType(_CFuncPtr):
00473         _argtypes_ = argtypes
00474         _restype_ = restype
00475         _flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
00476     return CFunctionType

def ctypes.SetPointerType (   pointer,
  cls 
)

Definition at line 291 of file __init__.py.

00291 
00292 def SetPointerType(pointer, cls):
00293     if _pointer_type_cache.get(cls, None) is not None:
00294         raise RuntimeError("This type already exists in the cache")
00295     if id(pointer) not in _pointer_type_cache:
00296         raise RuntimeError("What's this???")
00297     pointer.set_type(cls)
00298     _pointer_type_cache[cls] = pointer
00299     del _pointer_type_cache[id(pointer)]
00300 
# XXX Deprecated

Here is the caller graph for this function:

def ctypes.string_at (   ptr,
  size = -1 
)
string_at(addr[, size]) -> string

Return the string at addr.

Definition at line 482 of file __init__.py.

00482 
00483 def string_at(ptr, size=-1):
00484     """string_at(addr[, size]) -> string
00485 
00486     Return the string at addr."""
00487     return _string_at(ptr, size)
00488 
00489 try:
    from _ctypes import _wstring_at_addr

Here is the caller graph for this function:

def ctypes.WinError (   code = None,
  descr = None 
)

Definition at line 441 of file __init__.py.

00441 
00442     def WinError(code=None, descr=None):
00443         if code is None:
00444             code = GetLastError()
00445         if descr is None:
00446             descr = FormatError(code).strip()
00447         return WindowsError(code, descr)
00448 
00449 _pointer_type_cache[None] = c_void_p

Here is the caller graph for this function:

def ctypes.WINFUNCTYPE (   restype,
  argtypes,
  kw 
)

Definition at line 116 of file __init__.py.

00116 
00117     def WINFUNCTYPE(restype, *argtypes, **kw):
00118         # docstring set later (very similar to CFUNCTYPE.__doc__)
00119         flags = _FUNCFLAG_STDCALL
00120         if kw.pop("use_errno", False):
00121             flags |= _FUNCFLAG_USE_ERRNO
00122         if kw.pop("use_last_error", False):
00123             flags |= _FUNCFLAG_USE_LASTERROR
00124         if kw:
00125             raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
00126         try:
00127             return _win_functype_cache[(restype, argtypes, flags)]
00128         except KeyError:
00129             class WinFunctionType(_CFuncPtr):
00130                 _argtypes_ = argtypes
00131                 _restype_ = restype
00132                 _flags_ = flags
00133             _win_functype_cache[(restype, argtypes, flags)] = WinFunctionType
            return WinFunctionType

Here is the caller graph for this function:

def ctypes.wstring_at (   ptr,
  size = -1 
)
wstring_at(addr[, size]) -> string

Return the string at addr.

Definition at line 494 of file __init__.py.

00494 
00495     def wstring_at(ptr, size=-1):
00496         """wstring_at(addr[, size]) -> string
00497 
00498         Return the string at addr."""
00499         return _wstring_at(ptr, size)
00500 

Here is the caller graph for this function:


Variable Documentation

Definition at line 5 of file __init__.py.

"deprecated, use create_string_buffer instead" import warnings warnings.warn("c_buffer is deprecated, use create_string_buffer instead", DeprecationWarning, stacklevel=2)

Definition at line 74 of file __init__.py.

Definition at line 477 of file __init__.py.

ctypes._FUNCFLAG_STDCALL = _FUNCFLAG_CDECL

Definition at line 113 of file __init__.py.

Definition at line 481 of file __init__.py.

Definition at line 115 of file __init__.py.

Definition at line 493 of file __init__.py.

Definition at line 183 of file __init__.py.

Definition at line 520 of file __init__.py.

Definition at line 205 of file __init__.py.

Definition at line 209 of file __init__.py.

Definition at line 451 of file __init__.py.

Definition at line 452 of file __init__.py.

Definition at line 184 of file __init__.py.

Definition at line 521 of file __init__.py.

Definition at line 210 of file __init__.py.

Definition at line 254 of file __init__.py.

Definition at line 420 of file __init__.py.

Definition at line 22 of file __init__.py.

ctypes.GetLastError = windll.kernel32.GetLastError

Definition at line 436 of file __init__.py.

void *memmove(void *, const void *, size_t);

Definition at line 465 of file __init__.py.

void *memset(void *, int, size_t)

Definition at line 468 of file __init__.py.

Definition at line 433 of file __init__.py.

Definition at line 421 of file __init__.py.

tuple ctypes.pythonapi = PyDLL("python dll", None, _sys.dllhandle)

Definition at line 424 of file __init__.py.

Definition at line 432 of file __init__.py.