diff --git a/nd2reader/parser/base.py b/nd2reader/parser/base.py new file mode 100644 index 0000000..20b40d1 --- /dev/null +++ b/nd2reader/parser/base.py @@ -0,0 +1,11 @@ +from abc import abstractproperty + + +class BaseParser(object): + @abstractproperty + def metadata(self): + raise NotImplementedError + + @abstractproperty + def driver(self): + raise NotImplementedError diff --git a/nd2reader/parser/parser.py b/nd2reader/parser/parser.py index e43ddfb..d3e7488 100644 --- a/nd2reader/parser/parser.py +++ b/nd2reader/parser/parser.py @@ -1,6 +1,5 @@ from nd2reader.parser.v3 import V3Parser from nd2reader.exc import InvalidVersionError -from abc import abstractproperty def get_parser(filename, major_version, minor_version): @@ -9,13 +8,3 @@ def get_parser(filename, major_version, minor_version): if not parser: raise InvalidVersionError("No parser is available for that version.") return parser(filename) - - -class BaseParser(object): - @abstractproperty - def metadata(self): - raise NotImplementedError - - @abstractproperty - def driver(self): - raise NotImplementedError diff --git a/nd2reader/parser/v3.py b/nd2reader/parser/v3.py index 59e1cc2..c1f9a0f 100644 --- a/nd2reader/parser/v3.py +++ b/nd2reader/parser/v3.py @@ -3,7 +3,7 @@ import array from datetime import datetime from nd2reader.model.metadata import Metadata -from nd2reader.parser.parser import BaseParser +from nd2reader.parser.base import BaseParser import re import six import struct @@ -24,7 +24,7 @@ class V3Parser(BaseParser): def metadata(self): if not self._metadata: self._parse_metadata() - return self.metadata + return self._metadata @property def driver(self): @@ -207,6 +207,8 @@ class V3Parser(BaseParser): """ Gets the data for a given chunk pointer + :rtype: bytes + """ self._get_file_handle().seek(chunk_location) # The chunk metadata is always 16 bytes long @@ -217,10 +219,7 @@ class V3Parser(BaseParser): # We start at the location of the chunk metadata, skip over the metadata, and then proceed to the # start of the actual data field, which is at some arbitrary place after the metadata. self._get_file_handle().seek(chunk_location + 16 + relative_offset) - val = self._get_file_handle().read(data_length) - print("**************************") - print(type(val)) - return val + return self._get_file_handle().read(data_length) def _parse_unsigned_char(self, data): return struct.unpack("B", data.read(1))[0]