Provide unified access to the different sets of constants used by the winsys module. Some of them are provided by modules within the pywin32 package. Others belong to those sets but are not present in the modules. Still others are not present at all within pywin32 and are added here manually.
The constants are grouped together into Constants classes which combine the effect of being a namespace and also providing functions to list the constant name or names given a value, which is useful when displaying Win32 structures.
For useful documentation, each Constants generates a readable docstring tabulating its names & values.
Provide a dict-like interface for a group of related constants. These can come from a module or other namespace according to a wildcard name, or can be added as a list of (unrelated) names from a namespace or can simply be a raw dictionary of name-value pairs:
import win32con from winsys import constants COMPRESSION_ENGINE = constants.Constants.from_pattern ( "COMPRESSION_ENGINE_*", namespace=win32con ) COMPRESSION_ENGINE.update (dict ( EXTRA_VALUE = 5 )) print COMPRESSION_ENGINE.MAXIMUM COMPRESSION_ENGINE.dump ()
The convention is to name the set of constants after the common prefix of the constant names, as in the example above, but it’s just a convention. The pattern parameter to the various factory functions will be used to rename the constants on the way in, but it can be empty.
The constants can be accessed as attributes or as items. In addition, passing a name or a value to the constant() method will return the value. This is done automatically by most functions which expect a parameter based on one of these constants sets.
import win32con from winsys import constants ACE_TYPES = constants.Constants.from_pattern ( "*_ACE_TYPE", namespace=win32con ) print ACE_TYPES.name_from_value (ACE_TYPES.ACCESS_ALLOWED)
Build an internal structure from a dictionary-like set of initial values.
Produce a readable version of the data, used by __str__.
From a value, which may be a string or an integer, determine the corresponding value in this set of constants. If the value is a number, it is passed straight back out. If not, it is assumed to be a single string or a list of strings, each string corresponding to one of the constants in this set of constants:
from winsys.security import SD_CONTROL print SD_CONTROL.constant (["dacl_protected", "sacl_protected"]) print SD_CONTROL.DACL_PROTECTED | SD_CONTROL.SACL_PROTECTED print SD_CONTROL.constant (12288)
No attempt is made to verify that the number passed in represents a combination of the constants in this set.
Factory method to return a class instance from a dictionary-like set of values. If a pattern is passed in, use the distinguished part of the name (the part which matches the wildcard) as the key name.
Factory method to return a class instance from a list-like set of values within a namespace. Hands off to the from_dict factory.
Factory method to return a class instance from a wildcard name pattern. This is the most common method of constructing a list of constants by passing in, eg, FILE_ATTRIBUTE_* and the win32file module as the namespace.
Find the one name in the set of constants (optionally qualified by pattern) which matches value.
From a list of patterns, return the matching names from the list of constants. A single string is considered as though a list of one.
From a number representing the or-ing of several integer values, work out which of the constants make up the number using the pattern to filter the “classes” or constants present in the dataset.
Act as a dict for updates so that several constant sets may be merged into one.
Return the list of values which make up the combined value