From c1c8bc7a7d0d7d8ccaf07d5359ac5ad157491215 Mon Sep 17 00:00:00 2001 From: Julian Daube Date: Tue, 2 Jul 2019 19:37:32 +0200 Subject: [PATCH] parser: remove class elements; strip 0 from ascii strings --- gds/parser.py | 17 +++++++---------- gds/reader.py | 4 +++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/gds/parser.py b/gds/parser.py index 1c50232..44abf53 100644 --- a/gds/parser.py +++ b/gds/parser.py @@ -29,19 +29,16 @@ class ParserError(Exception): pass class Parser(Reader): - # parser stack - _token = None - progress_callback = None - - # parser state - Library = Library() - current_structure = None - def __init__(self, file, progress_callback=None): super(Parser, self).__init__(file) - + + self._token = None self.progress_callback = progress_callback - + + # parser state + self.Library = Library() + self.current_structure = None + @property def token(self): return self._token diff --git a/gds/reader.py b/gds/reader.py index ff7a538..4c37e98 100644 --- a/gds/reader.py +++ b/gds/reader.py @@ -99,7 +99,9 @@ class Reader(ProgressGetter): return 0 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): result = Record()