The zugbruecke.CtypesSession class

class zugbruecke.CtypesSession(**kwargs)

Represents one “ctypes session”, i.e. one Wine Python process, related infrastructure and its independent configuration. Mutliple sessions can run simultaneously. Mutable.

Parameters

kwargs (Any) – An arbitrary number of keyword arguments matching valid configuration parameters

exception ArgumentError
class Array

XXX to be provided

class BigEndianStructure

Structure with big endian byte order

CDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)

zugbruecke drop-in replacement for ctypes.CDLL

Parameters
  • name (str) – Pathname of the shared library (DLL file)

  • mode (int) – Ignored on Windows, therefore ignored by zugbruecke

  • handle (Optional[Any]) – Ignored by zugbruecke, see issue #54

  • use_errno (bool) – Enables a ctypes mechanism that allows accessing the system errno error number in a safe way.

  • use_last_error (bool) – Enables the same mechanism for the Windows error code which is managed by the GetLastError() and SetLastError() Windows API functions.

  • winmode (Optional[int]) – Ignored by zugbruecke. Used on Windows to specify how the library is loaded (since mode is ignored)

CFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False)

zugbruecke drop-in replacement for ctypes.CFUNCTYPE

Parameters
  • restype (Any) – ctypes type of return value

  • argtypes (Any) – ctypes types of arguments

  • use_errno (bool) – If true, the ctypes private copy of the system errno variable is exchanged with the real errno value before and after the call.

  • use_last_error (bool) – Does the same for the Windows error code.

Return type

Type

static DllCanUnloadNow()

Stub, not implemented. Required for COM.

static DllGetClassObject(rclsid, riid, ppv)

Stub, not implemented. Required for COM.

FormatError(*args, **kwargs)

zugbruecke wrapper for ctypes.FormatError, untested.

Parameters
  • args (Any) – positional arguments

  • kwargs (Any) – keyword arguments

Return type

Any

Returns

A textual description of the error code code. If no error code is specified, the last error code is used by calling the Windows api function GetLastError.

GetLastError(*args, **kwargs)

zugbruecke wrapper for ctypes.GetLastError, untested.

Parameters
  • args (Any) – positional arguments

  • kwargs (Any) – keyword arguments

Return type

Any

Returns

The last error code set by Windows in the calling thread. This function calls the Windows GetLastError() function directly, it does not return the ctypes-private copy of the error code.

class HRESULT(*args, **kwargs)

Stub, not implemented. Required for COM. Special form of ctypes.c_long (32 bit).

Parameters
  • args (Any) – positional arguments

  • kwargs (Any) – keyword arguments

LittleEndianStructure

alias of Structure

OleDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)

zugbruecke drop-in replacement for ctypes.CDLL

Parameters
  • name (str) – Pathname of the shared library (DLL file)

  • mode (int) – Ignored on Windows, therefore ignored by zugbruecke

  • handle (Optional[Any]) – Ignored by zugbruecke, see issue #54

  • use_errno (bool) – Enables a ctypes mechanism that allows accessing the system errno error number in a safe way.

  • use_last_error (bool) – Enables the same mechanism for the Windows error code which is managed by the GetLastError() and SetLastError() Windows API functions.

  • winmode (Optional[int]) – Ignored by zugbruecke. Used on Windows to specify how the library is loaded (since mode is ignored)

PyDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)

Stub, not implemented. zugbruecke drop-in replacement for ctypes.PyDLL

Parameters
  • name (str) – Pathname of the shared library (DLL file)

  • mode (int) – Ignored on Windows, therefore ignored by zugbruecke

  • handle (Optional[Any]) – Ignored by zugbruecke, see issue #54

  • use_errno (bool) – Enables a ctypes mechanism that allows accessing the system errno error number in a safe way.

  • use_last_error (bool) – Enables the same mechanism for the Windows error code which is managed by the GetLastError() and SetLastError() Windows API functions.

  • winmode (Optional[int]) – Ignored by zugbruecke. Used on Windows to specify how the library is loaded (since mode is ignored)

class Structure

Structure base class

class Union

Union base class

WINFUNCTYPE(restype, *argtypes, use_errno=False, use_last_error=False)

zugbruecke drop-in replacement for ctypes.WINFUNCTYPE

Parameters
  • restype (Any) – ctypes type of return value

  • argtypes (Any) – ctypes types of arguments

  • use_errno (bool) – If true, the ctypes private copy of the system errno variable is exchanged with the real errno value before and after the call.

  • use_last_error (bool) – Does the same for the Windows error code.

Return type

Type

WinDLL(name, mode=0, handle=None, use_errno=False, use_last_error=False, winmode=None)

zugbruecke drop-in replacement for ctypes.WinDLL

Parameters
  • name (str) – Pathname of the shared library (DLL file)

  • mode (int) – Ignored on Windows, therefore ignored by zugbruecke

  • handle (Optional[Any]) – Ignored by zugbruecke, see issue #54

  • use_errno (bool) – Enables a ctypes mechanism that allows accessing the system errno error number in a safe way.

  • use_last_error (bool) – Enables the same mechanism for the Windows error code which is managed by the GetLastError() and SetLastError() Windows API functions.

  • winmode (Optional[int]) – Ignored by zugbruecke. Used on Windows to specify how the library is loaded (since mode is ignored)

WinError(*args, **kwargs)

zugbruecke wrapper for ctypes.WinError, untested.

This function is probably the worst-named thing in ctypes.

Parameters
  • args (Any) – positional arguments

  • kwargs (Any) – keyword arguments

Return type

Any

Returns

An instance of OSError.

__enter__()

Context manager entry point for zugbruecke session.

Return type

CtypesSessionABC

__exit__(exc_type, exc_value, traceback)

Context manager exit point for zugbruecke session.

Parameters
  • exc_type (Optional[Type]) – Type of exception

  • exc_value (Optional[Exception]) – Actual exception object

  • traceback (Optional[traceback]) – Related traceback object

__repr__()

zugbruecke session string representation for interactive use

Return type

str

static addressof(C instance) integer

Return the address of the C instance internal buffer

static alignment(C type) integer
static alignment(C instance) integer

Return the alignment requirements of a C instance

static byref(C instance[, offset=0]) byref-object

Return a pointer lookalike to a C instance, only usable as function argument

class c_bool
class c_byte
class c_char
class c_char_p
from_param()

Convert a Python object into a function call parameter.

class c_double
class c_float
class c_int
c_int16

alias of c_short

c_int32

alias of c_int

c_int64

alias of c_long

c_int8

alias of c_byte

class c_long
class c_longdouble
c_longlong

alias of c_long

class c_short
c_size_t

alias of c_ulong

c_ssize_t

alias of c_long

class c_ubyte
class c_uint
c_uint16

alias of c_ushort

c_uint32

alias of c_uint

c_uint64

alias of c_ulong

c_uint8

alias of c_ubyte

class c_ulong
c_ulonglong

alias of c_ulong

class c_ushort
class c_void_p
from_param()

Convert a Python object into a function call parameter.

c_voidp

alias of c_void_p

class c_wchar
class c_wchar_p
from_param()

Convert a Python object into a function call parameter.

property cdll: LibraryLoader

zugbruecke drop-in replacement for LibraryLoader(CDLL) aka ctypes.cdll

Return type

LibraryLoader

static create_string_buffer(aBytes) character array
static create_string_buffer(anInteger) character array
static create_string_buffer(aBytes, anInteger) character array
static create_unicode_buffer(aString) character array
static create_unicode_buffer(anInteger) character array
static create_unicode_buffer(aString, anInteger) character array
get_last_error(*args, **kwargs)

zugbruecke wrapper for ctypes.get_last_error, untested.

Parameters
  • args (Any) – positional arguments

  • kwargs (Any) – keyword arguments

Return type

Any

Returns

The current value of the ctypes-private copy of the system LastError variable in the calling thread.

property oledll: LibraryLoader

zugbruecke drop-in replacement for LibraryLoader(OleDLL) aka ctypes.oledll

Return type

LibraryLoader

class py_object
property pydll: LibraryLoader

zugbruecke drop-in replacement for LibraryLoader(PyDLL) aka ctypes.pydll

Return type

LibraryLoader

static resize()

Resize the memory buffer of a ctypes instance

set_last_error(*args, **kwargs)

zugbruecke wrapper for ctypes.set_last_error, untested.

Set the current value of the ctypes-private copy of the system LastError variable in the calling thread to valueself.

Parameters
  • args (Any) – positional arguments

  • kwargs (Any) – keyword arguments

Return type

Any

Returns

The previous value.

static sizeof(C type) integer
static sizeof(C instance) integer

Return the size in bytes of a C instance

static string_at(addr[, size]) string

Return the string at addr.

property util: _util

Regular ctypes has a submodule named ctypes.util. In zugbruecke, this functionality is bound to a session. On a per-session level, it is exposed via this attribute.

Return type

_util

Returns

Drop-in replacement for ctypes.util. Offers zugbruecke wrappers for find_library and find_msvcrt.

property windll: LibraryLoader

zugbruecke drop-in replacement for LibraryLoader(WinDLL) aka ctypes.windll

Return type

LibraryLoader

static wstring_at(addr[, size]) string

Return the string at addr.

property zb_client_up: bool

Client status

Return type

bool

zb_get_parameter(key)

Reads configuration parameter of this session

Parameters

key (str) – Name of configuration parameter

Return type

Any

Returns

Value for configuration parameter

property zb_id: str

Session ID string

Return type

str

zb_path_unix_to_wine(path)

Path conversion, Unix to Windows/Wine. It uses Wine’s internal implementation for path conversions. It does not check, whether the path actually exists or not.

Parameters

path (str) – Unix path. Path can be absolute or relative.

Return type

str

Returns

Windows/Wine path

zb_path_wine_to_unix(path)

Path conversion, Windows/Wine to Unix. It uses Wine’s internal implementation for path conversions. It does not check, whether the path actually exists or not.

Parameters

path (str) – Windows/Wine path. Path can be absolute or relative.

Return type

str

Returns

Unix path

property zb_server_up: bool

Server status

Return type

bool

zb_set_parameter(key, value)

Changes configuration parameter of this session (both on Unix/client and Wine/server side)

Parameters
  • key (str) – Name of configuration parameter

  • value (Any) – New value for configuration parameter

zb_terminate()

This method can be used to manually terminate a session. It will quit the Windows Python interpreter running in the background. Once terminated, a session can not be re-started. Any handles on DLLs and their routines derived from this session will become useless.