item = item.evaluate(self)
return item
- def writeToStream(self, stream, indent, container):
+ def writeToStream(self, stream, indent, container, evaluated=False):
"""
Write this instance to a stream at the specified indentation level.
"""
raise NotImplementedError
- def writeValue(self, value, stream, indent):
+ def writeValue(self, value, stream, indent, evaluated=False):
if isinstance(self, Mapping):
indstr = ' '
else:
indstr = indent * ' '
if isinstance(value, Reference) or isinstance(value, Expression):
- stream.write('%s%r%s' % (indstr, value, NEWLINE))
+ if not evaluated:
+ stream.write('%s%r%s' % (indstr, value, NEWLINE))
+ else:
+ stream.write('%s%r%s' % (indstr, self.evaluate(value), NEWLINE))
else:
if isinstance(value, str): # and not isWord(value):
value = repr(value)
def __getitem__(self, key):
data = object.__getattribute__(self, 'data')
if key not in data:
- raise AttributeError(key)
+ raise AttributeError("Unknown pyconf key: '%s'" % key)
rv = data[key]
return self.evaluate(rv)
#if name == "__class__":
# return ''
data = object.__getattribute__(self, "data")
- useData = data.has_key(name)
+ useData = name in data
if useData:
rv = getattr(data, name)
else:
order = object.__getattribute__(self, 'order')
return order.__iter__()
- def writeToStream(self, stream, indent, container):
+ def writeToStream(self, stream, indent, container, evaluated=False):
"""
Write this instance to a stream at the specified indentation level.
if isinstance(container, Mapping):
stream.write(NEWLINE)
stream.write('%s{%s' % (indstr, NEWLINE))
- self.__save__(stream, indent + 1)
+ self.__save__(stream, indent + 1, evaluated=evaluated)
stream.write('%s}%s' % (indstr, NEWLINE))
- def __save__(self, stream, indent=0):
+ def __save__(self, stream, indent=0, evaluated=False):
"""
Save this configuration to the specified stream.
@param stream: A stream to which the configuration is written.
stream.write('%s%-*s :' % (indstr, maxlen, skey))
value = data[key]
if isinstance(value, Container):
- value.writeToStream(stream, indent, self)
+ value.writeToStream(stream, indent, self, evaluated=evaluated)
else:
- self.writeValue(value, stream, indent)
+ self.writeValue(value, stream, indent, evaluated=evaluated)
class Config(Mapping):
"""
else:
delattr(namespaces[0], name)
- def __save__(self, stream, indent=0, no_close=False):
+ def __save__(self, stream, indent=0, no_close=False, evaluated=False):
"""
Save this configuration to the specified stream. The stream is
closed if this is the top-level configuration in the hierarchy.
@param indent: The indentation level for the output.
@type indent: int
"""
- Mapping.__save__(self, stream, indent)
+ Mapping.__save__(self, stream, indent, evaluated=evaluated)
if indent == 0 and not no_close:
stream.close()
try:
rv = data[index]
except (IndexError, KeyError, TypeError):
- raise ConfigResolutionError('%r is not a valid index for %r' % (index, object.__getattribute__(self, 'path')))
+ raise ConfigResolutionError('Invalid pyconf index %r for %r' % (index, object.__getattribute__(self, 'path')))
if not isinstance(rv, list):
rv = self.evaluate(rv)
else:
def __len__(self):
return len(object.__getattribute__(self, 'data'))
- def writeToStream(self, stream, indent, container):
+ def writeToStream(self, stream, indent, container, evaluated=False):
"""
Write this instance to a stream at the specified indentation level.
if isinstance(container, Mapping):
stream.write(NEWLINE)
stream.write('%s[%s' % (indstr, NEWLINE))
- self.__save__(stream, indent + 1)
+ self.__save__(stream, indent + 1, evaluated=evaluated)
stream.write('%s]%s' % (indstr, NEWLINE))
- def __save__(self, stream, indent):
+ def __save__(self, stream, indent, evaluated=False):
"""
Save this instance to the specified stream.
@param stream: A stream to which the configuration is written.
if comment:
stream.write('%s#%s' % (indstr, comment))
if isinstance(value, Container):
- value.writeToStream(stream, indent, self)
+ value.writeToStream(stream, indent, self, evaluated=evaluated)
else:
- self.writeValue(value, stream, indent)
+ self.writeValue(value, stream, indent, evaluated=evaluated)
class Reference(object):
"""