parser: remove class elements; strip 0 from ascii strings

This commit is contained in:
Julian Daube 2019-07-02 19:37:32 +02:00
parent 096715320b
commit c1c8bc7a7d
2 changed files with 10 additions and 11 deletions

View File

@ -29,19 +29,16 @@ class ParserError(Exception):
pass pass
class Parser(Reader): class Parser(Reader):
# parser stack
_token = None
progress_callback = None
# parser state
Library = Library()
current_structure = None
def __init__(self, file, progress_callback=None): def __init__(self, file, progress_callback=None):
super(Parser, self).__init__(file) super(Parser, self).__init__(file)
self._token = None
self.progress_callback = progress_callback self.progress_callback = progress_callback
# parser state
self.Library = Library()
self.current_structure = None
@property @property
def token(self): def token(self):
return self._token return self._token

View File

@ -99,7 +99,9 @@ class Reader(ProgressGetter):
return 0 return 0
def read_ascii(self, len): def read_ascii(self, len):
return self.stream.read(len).decode("ASCII").strip() # removes zero terminators
# as well as trailing and beginning whitespaces
return self.stream.read(len).decode("ASCII").replace("\x00", "").strip()
def read_record(self): def read_record(self):
result = Record() result = Record()