summaryrefslogtreecommitdiff
path: root/pint/util.py
diff options
context:
space:
mode:
authorHernan Grecco <hernan.grecco@gmail.com>2022-10-21 22:51:30 -0300
committerGitHub <noreply@github.com>2022-10-21 22:51:30 -0300
commitc07fc9b218ea39965d8d4492e52168fe8f8a644b (patch)
tree51574304897d2566dc98138d878a7e582767ca5d /pint/util.py
parent64f19ed6a78b1e6c59e07a953febe212818ec4c1 (diff)
parenta943a4f15daf7d6bdd7948dff08b0802f77d7907 (diff)
downloadpint-c07fc9b218ea39965d8d4492e52168fe8f8a644b.tar.gz
Merge pull request #1595 from hgrecco/using_flexparser
Final step to split the registry from the parser
Diffstat (limited to 'pint/util.py')
-rw-r--r--pint/util.py74
1 files changed, 0 insertions, 74 deletions
diff --git a/pint/util.py b/pint/util.py
index 0152e66..eba747e 100644
--- a/pint/util.py
+++ b/pint/util.py
@@ -980,80 +980,6 @@ def getattr_maybe_raise(self, item):
raise AttributeError("%r object has no attribute %r" % (self, item))
-class SourceIterator:
- """Iterator to facilitate reading the definition files.
-
- Accepts any sequence (like a list of lines, a file or another SourceIterator)
-
- The iterator yields the line number and line (skipping comments and empty lines)
- and stripping white spaces.
-
- for lineno, line in SourceIterator(sequence):
- # do something here
-
- """
-
- def __new__(cls, sequence, filename=None, is_resource=False):
- if isinstance(sequence, SourceIterator):
- return sequence
-
- obj = object.__new__(cls)
-
- if sequence is not None:
- obj.internal = enumerate(sequence, 1)
- obj.last = (None, None)
- obj.filename = filename or getattr(sequence, "name", None)
- obj.is_resource = is_resource
-
- return obj
-
- def __iter__(self):
- return self
-
- def __next__(self):
- line = ""
- while not line or line.startswith("#"):
- lineno, line = next(self.internal)
- line = line.split("#", 1)[0].strip()
-
- self.last = lineno, line
- return lineno, line
-
- next = __next__
-
- def block_iter(self):
- """Iterate block including header."""
- return BlockIterator(self)
-
-
-class BlockIterator(SourceIterator):
- """Like SourceIterator but stops when it finds '@end'
- It also raises an error if another '@' directive is found inside.
- """
-
- def __new__(cls, line_iterator):
- obj = SourceIterator.__new__(cls, None)
- obj.internal = line_iterator.internal
- obj.last = line_iterator.last
- obj.done_last = False
- return obj
-
- def __next__(self):
- if not self.done_last:
- self.done_last = True
- return self.last
-
- lineno, line = SourceIterator.__next__(self)
- if line.startswith("@end"):
- raise StopIteration
- elif line.startswith("@"):
- raise DefinitionSyntaxError("cannot nest @ directives", lineno=lineno)
-
- return lineno, line
-
- next = __next__
-
-
def iterable(y) -> bool:
"""Check whether or not an object can be iterated over.