dict = env.Dictionary()
</programlisting>
-<REMARK>
-In the current source code, I implemented this as a dictionary attribute
-named <literal>Dictionary</literal>. While reasonably Pythonic, this
-is ultimately Not Good. We don't want people using a reference to the
-dictionary to change construction variables out from under an existing
-environment. We should use an internal <literal>_dict</literal>
-attribute and control access to it through a method, as specified above.
-</REMARK>
-
<para>
If any arguments are supplied, then just the corresponding value(s)
"""
def __init__(self, **kw):
- self.Dictionary = {}
+ self._dict = {}
if kw.has_key('BUILDERS'):
builders = kw['BUILDERS']
if not type(builders) is types.ListType:
else:
import SCons.Defaults
kw['BUILDERS'] = SCons.Defaults.Builders[:]
- self.Dictionary.update(copy.deepcopy(kw))
+ self._dict.update(copy.deepcopy(kw))
class BuilderWrapper:
"""Wrapper class that allows an environment to
def __cmp__(self, other):
- return cmp(self.Dictionary, other.Dictionary)
+ return cmp(self._dict, other._dict)
def Builders(self):
pass # XXX
"""Update an existing construction Environment with new
construction variables and/or values.
"""
- self.Dictionary.update(copy.deepcopy(kw))
+ self._dict.update(copy.deepcopy(kw))
def Depends(self, target, dependency):
"""Explicity specify that 'target's depend on 'dependency'."""
tlist = tlist[0]
return tlist
+ def Dictionary(self, *args):
+ if not args:
+ return self._dict
+ dlist = map(lambda x, s=self: s._dict[x], args)
+ if len(dlist) == 1:
+ dlist = dlist[0]
+ return dlist
+
def subst(self, string):
"""Recursively interpolates construction variables from the
Environment into the specified string, returning the expanded
key = m.group(1)
if key[:1] == '{' and key[-1:] == '}':
key = key[1:-1]
- if _self.Dictionary.has_key(key): return _self.Dictionary[key]
+ if _self._dict.has_key(key): return _self._dict[key]
else: return ''
n = 1
while n != 0:
assert env1 == env1copy
env3 = env1.Copy(XXX = 'x3', ZZZ = 'z3')
- assert env3.Dictionary['XXX'] == 'x3'
- assert env3.Dictionary['YYY'] == 'y'
- assert env3.Dictionary['ZZZ'] == 'z3'
+ assert env3.Dictionary('XXX') == 'x3'
+ assert env3.Dictionary('YYY') == 'y'
+ assert env3.Dictionary('ZZZ') == 'z3'
assert env1 == env1copy
def test_Dictionary(self):
Fetch them from the Dictionary and check for well-known
defaults that get inserted.
"""
- env = Environment(XXX = 'x', YYY = 'y')
- assert env.Dictionary['XXX'] == 'x'
- assert env.Dictionary['YYY'] == 'y'
- assert env.Dictionary.has_key('BUILDERS')
+ env = Environment(XXX = 'x', YYY = 'y', ZZZ = 'z')
+ assert env.Dictionary('XXX') == 'x'
+ assert env.Dictionary('YYY') == 'y'
+ assert env.Dictionary('XXX', 'ZZZ') == ['x', 'z']
+ xxx, zzz = env.Dictionary('XXX', 'ZZZ')
+ assert xxx == 'x'
+ assert zzz == 'z'
+ assert env.Dictionary().has_key('BUILDERS')
def test_Environment(self):
"""Test construction Environments creation