summaryrefslogtreecommitdiff
path: root/portato/eix/parser.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-08-14 15:27:49 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-08-14 15:27:49 +0200
commit1e88fe3bee51cd04928499f8ec29e00cf129ad33 (patch)
treefa265ce34930d4ca36549fb8654b70579feb7876 /portato/eix/parser.py
parentd44ce453d88624c8444f0733a56197d5291f52f6 (diff)
downloadportato-1e88fe3bee51cd04928499f8ec29e00cf129ad33.tar.gz
portato-1e88fe3bee51cd04928499f8ec29e00cf129ad33.tar.bz2
portato-1e88fe3bee51cd04928499f8ec29e00cf129ad33.zip
Add LazyElement
Diffstat (limited to 'portato/eix/parser.py')
-rw-r--r--portato/eix/parser.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/portato/eix/parser.py b/portato/eix/parser.py
index e89bffe..676cdd5 100644
--- a/portato/eix/parser.py
+++ b/portato/eix/parser.py
@@ -63,7 +63,7 @@ def vector (file, get_type, skip = False):
for i in range(nelems):
get_type(file, skip = True)
else:
- return (get_type(file) for i in range(nelems))
+ return [get_type(file) for i in range(nelems)]
def string (file, skip = False):
nelems = number(file)
@@ -84,3 +84,25 @@ def overlay (file, skip = False):
string(file, skip = True) # label
else:
return (string(file), string(file))
+
+class LazyElement (object):
+ def __init__ (self, get_type, file):
+ self.file = file
+ self.get_type = get_type
+ self._value = None
+
+ self.pos = file.tell()
+ get_type(skip=True) # skip it for the moment
+
+ @property
+ def value (self):
+ if self._value is None:
+ old_pos = self.file.tell()
+ self.file.seek(self.pos)
+ self._value = self.get_type(skip = False)
+ self.file.seek(old_pos)
+
+ return self._value
+
+ def __call__ (self):
+ return self.value