Ñò
Ã#xPc
@ sÐ d Z d d k l Z l Z d d k l Z d d k Z d d k l Z d d k Z d d k l
Z
d d k l Z d d k
l Z d d k l Z d d
k l Z l Z l Z l Z d e f d „ ƒ YZ d S(
sp
Process-wide static configuration and environment.
The standard run-time instance of the `Env` class is initialized early in the
`ipalib` process and is then locked into a read-only state, after which no
further changes can be made to the environment throughout the remaining life
of the process.
For the per-request thread-local information, see `ipalib.request`.
iÿÿÿÿ( t RawConfigParsert ParsingError( t NoneTypeN( t path( t getfqdn( t DN( t
check_name( t CONFIG_SECTION( t
TYPE_ERRORt OVERRIDE_ERRORt SET_ERRORt DEL_ERRORt Envc B s¿ e Z d Z e Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z
d „ Z d „ Z d „ Z
d
„ Z d „ Z d „ Z d
„ Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z RS( s•
Store and retrieve environment variables.
First an foremost, the `Env` class provides a handy container for
environment variables. These variables can be both set *and* retrieved
either as attributes *or* as dictionary items.
For example, you can set a variable as an attribute:
>>> env = Env()
>>> env.attr = 'I was set as an attribute.'
>>> env.attr
u'I was set as an attribute.'
>>> env['attr'] # Also retrieve as a dictionary item
u'I was set as an attribute.'
Or you can set a variable as a dictionary item:
>>> env['item'] = 'I was set as a dictionary item.'
>>> env['item']
u'I was set as a dictionary item.'
>>> env.item # Also retrieve as an attribute
u'I was set as a dictionary item.'
The variable names must be valid lower-case Python identifiers that neither
start nor end with an underscore. If your variable name doesn't meet these
criteria, a ``ValueError`` will be raised when you try to set the variable
(compliments of the `base.check_name()` function). For example:
>>> env.BadName = 'Wont work as an attribute'
Traceback (most recent call last):
...
ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'BadName'
>>> env['BadName'] = 'Also wont work as a dictionary item'
Traceback (most recent call last):
...
ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'BadName'
The variable values can be ``str``, ``int``, or ``float`` instances, or the
``True``, ``False``, or ``None`` constants. When the value provided is an
``str`` instance, some limited automatic type conversion is performed, which
allows values of specific types to be set easily from configuration files or
command-line options.
So in addition to their actual values, the ``True``, ``False``, and ``None``
constants can be specified with an ``str`` equal to what ``repr()`` would
return. For example:
>>> env.true = True
>>> env.also_true = 'True' # Equal to repr(True)
>>> env.true
True
>>> env.also_true
True
Note that the automatic type conversion is case sensitive. For example:
>>> env.not_false = 'false' # Not equal to repr(False)!
>>> env.not_false
u'false'
If an ``str`` value looks like an integer, it's automatically converted to
the ``int`` type. Likewise, if an ``str`` value looks like a floating-point
number, it's automatically converted to the ``float`` type. For example:
>>> env.lucky = '7'
>>> env.lucky
7
>>> env.three_halves = '1.5'
>>> env.three_halves
1.5
Leading and trailing white-space is automatically stripped from ``str``
values. For example:
>>> env.message = ' Hello! ' # Surrounded by double spaces
>>> env.message
u'Hello!'
>>> env.number = ' 42 ' # Still converted to an int
>>> env.number
42
>>> env.false = ' False ' # Still equal to repr(False)
>>> env.false
False
Also, empty ``str`` instances are converted to ``None``. For example:
>>> env.empty = ''
>>> env.empty is None
True
`Env` variables are all set-once (first-one-wins). Once a variable has been
set, trying to override it will raise an ``AttributeError``. For example:
>>> env.date = 'First'
>>> env.date = 'Second'
Traceback (most recent call last):
...
AttributeError: cannot override Env.date value u'First' with 'Second'
An `Env` instance can be *locked*, after which no further variables can be
set. Trying to set variables on a locked `Env` instance will also raise
an ``AttributeError``. For example:
>>> env = Env()
>>> env.okay = 'This will work.'
>>> env.__lock__()
>>> env.nope = 'This wont work!'
Traceback (most recent call last):
...
AttributeError: locked: cannot set Env.nope to 'This wont work!'
`Env` instances also provide standard container emulation for membership
testing, counting, and iteration. For example:
>>> env = Env()
>>> 'key1' in env # Has key1 been set?
False
>>> env.key1 = 'value 1'
>>> 'key1' in env
True
>>> env.key2 = 'value 2'
>>> len(env) # How many variables have been set?
2
>>> list(env) # What variables have been set?
['key1', 'key2']
Lastly, in addition to all the handy container functionality, the `Env`
class provides high-level methods for bootstraping a fresh `Env` instance
into one containing all the run-time and configuration information needed
by the built-in freeIPA plugins.
These are the `Env` bootstraping methods, in the order they must be called:
1. `Env._bootstrap()` - initialize the run-time variables and then
merge-in variables specified on the command-line.
2. `Env._finalize_core()` - merge-in variables from the configuration
files and then merge-in variables from the internal defaults, after
which at least all the standard variables will be set. After this
method is called, the plugins will be loaded, during which
third-party plugins can merge-in defaults for additional variables
they use (likely using the `Env._merge()` method).
3. `Env._finalize()` - one last chance to merge-in variables and then
the instance is locked. After this method is called, no more
environment variables can be set during the remaining life of the
process.
However, normally none of these three bootstraping methods are called
directly and instead only `plugable.API.bootstrap()` is called, which itself
takes care of correctly calling the `Env` bootstrapping methods.
c K sE t i | d h ƒ t i | d t ƒ ƒ | o | i | n d S( Nt _Env__dt
_Env__done( t objectt __setattr__t sett _merge( t selft
initialize( ( s1 /usr/lib/python2.6/site-packages/ipalib/config.pyt __init__Ê s c C sA | i t j o t d | i i ƒ ‚ n t i | d t ƒ d S( s9
Prevent further changes to environment.
s %s.__lock__() already calledt _Env__lockedN( R t Truet
StandardErrort __class__t __name__R R ( R ( ( s1 /usr/lib/python2.6/site-packages/ipalib/config.pyt __lock__Ð s c C s | i S( s,
Return ``True`` if locked.
( R ( R ( ( s1 /usr/lib/python2.6/site-packages/ipalib/config.pyt __islocked__Ú s c C s | | |