diff options
author | Hernan Grecco <hernan.grecco@gmail.com> | 2013-12-13 01:11:48 -0300 |
---|---|---|
committer | Hernan Grecco <hernan.grecco@gmail.com> | 2013-12-13 01:11:48 -0300 |
commit | 9d34765aed601e53e4fed4d41631e9718b14380f (patch) | |
tree | 49402ed650a2ae898372be2c6ecb41d3fbce011b | |
parent | 39d60e9531e19e017314a4f31957dee57936559e (diff) | |
download | pint-9d34765aed601e53e4fed4d41631e9718b14380f.tar.gz |
Changed end of context specification @end
-rw-r--r-- | pint/unit.py | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/pint/unit.py b/pint/unit.py index 92a0d69..71f1335 100644 --- a/pint/unit.py +++ b/pint/unit.py @@ -648,30 +648,21 @@ class UnitRegistry(object): path = os.getcwd() path = os.path.join(path, os.path.normpath(line[7:].strip())) self.load_definitions(path, is_resource) - continue - if line.startswith('@context'): - # Like Python code, contexts block are identified by their indentation + elif line.startswith('@context'): context = [line, ] - no, line = next(ifile) - indent_level = len(line) - len(line.lstrip()) - if not indent_level: - raise ValueError('In line {}, expected an indented block for the context:\n{}'.format(no, line)) for no, line in ifile: - line = line.rstrip() - level = len(line) - len(line.lstrip()) - if level: - if level != indent_level: - raise ValueError('In line {}, the indentation level ({}) does not match ' - 'the context indentation level ({}) in:\n{}'.format(no, level, indent_level, line)) - context.append(line) - else: + line = line.strip() + if line.startswith('@end'): + self.add_context(Context.from_lines(context)) break - self.add_context(Context.from_lines(context)) - continue - try: - self.define(Definition.from_string(line)) - except Exception as ex: - logger.error("Cannot add '{}' {}".format(line, ex)) + elif line.startswith('@'): + raise ValueError('In line {}, cannot nest @ directives:\n{}'.format(no, line)) + context.append(line) + else: + try: + self.define(Definition.from_string(line)) + except Exception as ex: + logger.error("In line {}, cannot add '{}' {}".format(no, line, ex)) def validate(self): """Walk the registry and calculate for each unit definition |