constants

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.

Classes

class constants.Constants(dict_initialiser={})[source]

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.

To retrieve the name or names corresponding to a value, use the name_from_value() or names_from_value() function:

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.

as_string()

Produce a readable version of the data, used by __str__.

constant(value)[source]

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))

Note

No attempt is made to verify that the number passed in represents a combination of the constants in this set.

doc(preamble)[source]
dump(level=0)
dumped(level=None)[source]
classmethod from_dict(d, pattern=None)[source]

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.

classmethod from_list(keys, namespace, pattern=None)[source]

Factory method to return a class instance from a list-like set of values within a namespace. Hands off to the from_dict factory.

classmethod from_pattern(pattern=u'*', excluded=, []namespace=<module 'win32con' from 'C:Python27libsite-packageswin32libwin32con.pyc'>)[source]

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.

init(dict_initialiser)[source]
items()[source]
iterkeys()
keys()[source]
name_from_value(value, default=<Unset>, patterns=[u'*'])[source]

Find the one name in the set of constants (optionally qualified by pattern) which matches value.

names(patterns=[u'*'])[source]

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.

names_from_value(value, patterns=[u'*'])[source]

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.

reset_doc()[source]
update(other)[source]

Act as a dict for updates so that several constant sets may be merged into one.

values()[source]
values_from_value(value, patterns=[u'*'])[source]

Return the list of values which make up the combined value

class constants.Attributes(flags, const)[source]

Simple class wrapper for the list of file attributes (readonly, hidden, &c.) It can be accessed by attribute access, item access and the “in” operator:

from winsys import fs
attributes = fs.file (fs.__file__).parent().attributes
assert(attributes.directory)
assert(attributes[fs.FILE_ATTRIBUTE.DIRECTORY])
assert("directory" in attributes)

Constants

constants.GENERAL = <Constants: {'INFINITE': -1, 'MAXIMUM_ALLOWED': 33554432}>
Name Val Win32
MAXIMUM_ALLOWED 0x02000000 MAXIMUM_ALLOWED
INFINITE 0xFFFFFFFF INFINITE
constants.TOKEN_FLAG = <Constants: {'ALL_ACCESS': 983295, 'ADJUST_DEFAULT': 128, 'EXECUTE': 131072, 'SOURCE_LENGTH': 8, 'READ': 131080, 'ASSIGN_PRIMARY': 1, 'WRITE': 131296, 'ADJUST_PRIVILEGES': 32, 'DUPLICATE': 2, 'IMPERSONATE': 4, 'QUERY_SOURCE': 16, 'QUERY': 8, 'ADJUST_GROUPS': 64}>
Name Val Win32
ASSIGN_PRIMARY 0x000001 TOKEN_ASSIGN_PRIMARY
DUPLICATE 0x000002 TOKEN_DUPLICATE
IMPERSONATE 0x000004 TOKEN_IMPERSONATE
SOURCE_LENGTH 0x000008 TOKEN_SOURCE_LENGTH
QUERY 0x000008 TOKEN_SOURCE_LENGTH
QUERY_SOURCE 0x000010 TOKEN_QUERY_SOURCE
ADJUST_PRIVILEGES 0x000020 TOKEN_ADJUST_PRIVILEGES
ADJUST_GROUPS 0x000040 TOKEN_ADJUST_GROUPS
ADJUST_DEFAULT 0x000080 TOKEN_ADJUST_DEFAULT
EXECUTE 0x020000 TOKEN_EXECUTE
READ 0x020008 TOKEN_READ
WRITE 0x0200E0 TOKEN_WRITE
ALL_ACCESS 0x0F00FF TOKEN_ALL_ACCESS
constants.ACCESS = <Constants: {'ACCESS_SYSTEM_SECURITY': 16777216, u'WRITE_DAC': 262144, u'SYNCHRONIZE': 1048576, u'READ_CONTROL': 131072, u'WRITE_OWNER': 524288, u'DELETE': 65536}>
Name Val Win32
DELETE 0x00010000 DELETE
READ_CONTROL 0x00020000 READ_CONTROL
WRITE_DAC 0x00040000 WRITE_DAC
WRITE_OWNER 0x00080000 WRITE_OWNER
SYNCHRONIZE 0x00100000 SYNCHRONIZE
ACCESS_SYSTEM_SECURITY 0x01000000 ACCESS_SYSTEM_SECURITY
constants.GENERIC_ACCESS = <Constants: {'READ': -2147483648, 'WRITE': 1073741824, 'ALL': 268435456, 'EXECUTE': 536870912}>
Name Val Win32
ALL 0x10000000 GENERIC_ALL
EXECUTE 0x20000000 GENERIC_EXECUTE
WRITE 0x40000000 GENERIC_WRITE
READ 0x80000000 GENERIC_READ
constants.STANDARD_ACCESS = <Constants: {u'SYNCHRONIZE': 1048576, u'STANDARD_RIGHTS_WRITE': 131072, u'STANDARD_RIGHTS_READ': 131072}>
Name Val Win32
STANDARD_RIGHTS_WRITE 0x020000 STANDARD_RIGHTS_WRITE
STANDARD_RIGHTS_READ 0x020000 STANDARD_RIGHTS_WRITE
SYNCHRONIZE 0x100000 SYNCHRONIZE

References

See also

Using the constants module
Cookbook examples of using the constants module

Table Of Contents

Previous topic

core – Core objects

Next topic

exc – Exceptions

This Page