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(dict_initialiser={})

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)

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)
dump(level=0)
dumped(level=None)
classmethod from_dict(d, pattern=None)

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)

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

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)
items()
iteritems()
iterkeys()
itervalues()
keys()
name_from_value(value, default=<Unset>, patterns=[u'*'])

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

names(patterns=[u'*'])

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'*'])

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()
update(other)

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

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

Return the list of values which make up the combined value

Constants

GENERAL
Name Val Win32
INFINITE -1 INFINITE
MAXIMUM_ALLOWED 33554432 MAXIMUM_ALLOWED
TOKEN_FLAG
Name Val Win32
ASSIGN_PRIMARY 1 TOKEN_ASSIGN_PRIMARY
ADJUST_DEFAULT 128 TOKEN_ADJUST_DEFAULT
EXECUTE 131072 TOKEN_EXECUTE
READ 131080 TOKEN_READ
WRITE 131296 TOKEN_WRITE
QUERY_SOURCE 16 TOKEN_QUERY_SOURCE
DUPLICATE 2 TOKEN_DUPLICATE
ADJUST_PRIVILEGES 32 TOKEN_ADJUST_PRIVILEGES
IMPERSONATE 4 TOKEN_IMPERSONATE
ADJUST_GROUPS 64 TOKEN_ADJUST_GROUPS
SOURCE_LENGTH 8 TOKEN_SOURCE_LENGTH
QUERY 8 TOKEN_SOURCE_LENGTH
ALL_ACCESS 983295 TOKEN_ALL_ACCESS
ACCESS
Name Val Win32
SYNCHRONIZE 1048576 SYNCHRONIZE
READ_CONTROL 131072 READ_CONTROL
ACCESS_SYSTEM_SECURITY 16777216 ACCESS_SYSTEM_SECURITY
WRITE_DAC 262144 WRITE_DAC
WRITE_OWNER 524288 WRITE_OWNER
DELETE 65536 DELETE
GENERIC_ACCESS
Name Val Win32
READ -2147483648 GENERIC_READ
WRITE 1073741824 GENERIC_WRITE
ALL 268435456 GENERIC_ALL
EXECUTE 536870912 GENERIC_EXECUTE
STANDARD_ACCESS
Name Val Win32
SYNCHRONIZE 1048576 SYNCHRONIZE
STANDARD_RIGHTS_WRITE 131072 STANDARD_RIGHTS_WRITE
STANDARD_RIGHTS_READ 131072 STANDARD_RIGHTS_WRITE

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