diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-07-27 01:14:43 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-07-27 01:14:43 +0200 |
commit | 8e4a8d8b3971490d60aa5b26ec465a8a4ab50cf8 (patch) | |
tree | 37789bfaec46a421fcd3ccd394f27a2dc1b8f79e /portato | |
parent | 40344af86dbe9c7ad2f38b18f31f0f8a4917bda9 (diff) | |
download | portato-8e4a8d8b3971490d60aa5b26ec465a8a4ab50cf8.tar.gz portato-8e4a8d8b3971490d60aa5b26ec465a8a4ab50cf8.tar.bz2 portato-8e4a8d8b3971490d60aa5b26ec465a8a4ab50cf8.zip |
Implemented vectors and so
Diffstat (limited to 'portato')
-rw-r--r-- | portato/eix.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/portato/eix.py b/portato/eix.py index 927870e..5262bf2 100644 --- a/portato/eix.py +++ b/portato/eix.py @@ -12,6 +12,7 @@ from __future__ import absolute_import, with_statement +import os import struct from functools import wraps @@ -45,7 +46,7 @@ class EixReader (object): self.closed = 0 try: - self.version = self.get_number() + self.version = self.number() if self.version not in self.supported_versions: raise UnsupportedVersionError(self.version) @@ -65,7 +66,7 @@ class EixReader (object): return wrapper @check_closed - def get_number (self): + def number (self): n = self._get_bytes(1) if n < 0xFF: @@ -91,6 +92,38 @@ class EixReader (object): return value + @check_closed + def vector (self, get_type, skip = False): + nelems = self.number() + + if skip: + for i in range(nelems): + get_type(skip = True) + else: + return (get_type() for i in range(nelems)) + + @check_closed + def string (self, skip = False): + nelems = self.number() + + if skip: + self.file.seek(nelems, os.SEEK_CUR) + else: + s = self.file.read(nelems) + + if len(s) != nelems: + raise EndOfFileException, self.filename + + return s + + @check_closed + def overlay (self, skip = False): + if skip: + self.file.seek(self.number(), os.SEEK_CUR) # path + self.file.seek(self.number(), os.SEEK_CUR) # label + else: + return (self.string(), self.string()) + def _get_bytes (self, length, expect_list = False): s = self.file.read(length) |