pywincffi.core package

Submodules

pywincffi.core.checks module

Checks

Provides functions that are responsible for internal type checks.

class pywincffi.core.checks.CheckMapping(kind, cname, nullable)

Bases: tuple

cname

Alias for field number 1

kind

Alias for field number 0

nullable

Alias for field number 2

class pywincffi.core.checks.Enums

Bases: enum.Enum

HANDLE = <Enums.HANDLE: 2>
NON_ZERO = <Enums.NON_ZERO: 1>
OVERLAPPED = <Enums.OVERLAPPED: 4>
PYFILE = <Enums.PYFILE: 5>
SECURITY_ATTRIBUTES = <Enums.SECURITY_ATTRIBUTES: 6>
UTF8 = <Enums.UTF8: 3>
pywincffi.core.checks.error_check(function, code=None, expected=None)[source]

Checks the results of a return code against an expected result. If a code is not provided we’ll use ffi.getwinerror() to retrieve the code.

Parameters:
  • function (str) – The Windows API function being called.
  • code (int) – An explicit code to compare against.
  • expected (int) – The code we expect to have as a result of a successful call. This can also be passed pywincffi.core.checks.Enums.NON_ZERO if code can be anything but zero.
Raises:

pywincffi.exceptions.WindowsAPIError – Raised if we receive an unexpected result from a Windows API call

pywincffi.core.checks.input_check(name, value, allowed_types=None, allowed_values=None)[source]

A small wrapper around isinstance(). This is mainly meant to be used inside of other functions to pre-validate input rater than using assertions. It’s better to fail early with bad input so more reasonable error message can be provided instead of from somewhere deep in cffi or Windows.

Parameters:
  • name (str) – The name of the input being checked. This is provided so error messages make more sense and can be attributed to specific input arguments.
  • value – The value we’re performing the type check on.
  • allowed_types – The allowed type or types for value. This argument also supports a special value, pywincffi.core.checks.Enums.HANDLE, which will check to ensure value is a handle object.
  • allowed_values (tuple) – A tuple of allowed values. When provided value must be in this tuple otherwise InputError will be raised.
Raises:

pywincffi.exceptions.InputError – Raised if value is not an instance of allowed_types

pywincffi.core.config module

Configuration

Simple module for loading pywincffi’s configuration, intended for internal use. A configuration file which is reasonable for every day use ships with pywincffi but can be overridden at runtime by dropping a file named pywincffi.ini in the current working directory or the current users’s home directory.

class pywincffi.core.config.Configuration[source]

Bases: ConfigParser.RawConfigParser

Class responsible for loading and retrieving data from the configuration files. This is used by a few parts of pywincffi to control various aspects of execution.

FILES = ('/home/docs/checkouts/readthedocs.org/user_builds/pywincffi/checkouts/0.2.0/pywincffi/core/pywincffi.ini', '/home/docs/pywincffi.ini', 'pywincffi.ini')
LOGGER_LEVEL_MAPPINGS = {'info': 20, 'warning': 30, 'critical': 50, 'error': 40, 'debug': 10, 'notset': 0}
load()[source]

Loads the configuration from disk

logging_level()[source]

Returns the logging level that the configuration currently dictates.

pywincffi.core.dist module

Distribution

Module responsible for building the pywincffi distribution in setup.py. This module is meant to serve two purposes. The first is to serve as the main means of loading the pywincffi library:

>>> from pywincffi.core import dist
>>> ffi, lib = dist.load()

The second is to facilitate a means of building a static library. This is used by the setup.py during the install process to build and install pywincffi as well as a wheel for distribution.

pywincffi.core.dist.load()[source]

The main function used by pywincffi to load an instance of FFI and the underlying build library.

pywincffi.core.logger module

Logger

This module contains pywincffi’s logger and provides functions to configure the logger at runtime.

pywincffi.core.logger.get_logger(name)[source]

Returns an instance of logging.Logger as a child of pywincffi’s main logger.

Parameters:name (str) – The name of the child logger to return. For example, if you provide foo for the name the resulting name will be pywincffi.foo.
Raises:ValueError – Raised if name starts with a dot.
Return type:logging.Logger

Module contents

Core Sub-Package

An internal package used by pywincffi for loading the underlying _pywincffi module, handling configuration data, logging and other common tasks. This package also contains the C source and header files.