From b36b8e87f8c3dd8f70abe5a97468f375302c7d7d Mon Sep 17 00:00:00 2001
From: speckhard <dts@stanford.edu>
Date: Thu, 14 Mar 2019 11:54:25 +0100
Subject: [PATCH] static check fixes.

---
 dependencies/parsers/atk    |  2 +-
 dependencies/parsers/gpaw   |  2 +-
 nomad/parsing/__init__.py   | 17 ++++++++---------
 nomad/parsing/artificial.py |  6 +++---
 nomad/parsing/parser.py     | 14 ++++++++------
 5 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/dependencies/parsers/atk b/dependencies/parsers/atk
index bab03a285b..b03240e3d7 160000
--- a/dependencies/parsers/atk
+++ b/dependencies/parsers/atk
@@ -1 +1 @@
-Subproject commit bab03a285bac95ee7c3d01727537065c8ae7f4d6
+Subproject commit b03240e3d78b7e4f58974252e7d845229ec81188
diff --git a/dependencies/parsers/gpaw b/dependencies/parsers/gpaw
index cbd073af08..f5be159e49 160000
--- a/dependencies/parsers/gpaw
+++ b/dependencies/parsers/gpaw
@@ -1 +1 @@
-Subproject commit cbd073af089103951ee5b267ab064b00442b3cfc
+Subproject commit f5be159e49f643d220497726da9801138ed615c3
diff --git a/nomad/parsing/__init__.py b/nomad/parsing/__init__.py
index 5d5a288024..9676395f9e 100644
--- a/nomad/parsing/__init__.py
+++ b/nomad/parsing/__init__.py
@@ -150,7 +150,7 @@ parsers = [
             r'^(.*\n)*'
             r'?\s*Invoking FHI-aims \.\.\.'
             r'?\s*Version'),
-        mainfile_name_re= r'^.(?!.*phonopy-FHI-aims-displacement)'
+        mainfile_name_re=r'^.(?!.*phonopy-FHI-aims-displacement)'
     ),
     LegacyParser(
         name='parsers/cp2k',
@@ -244,14 +244,13 @@ parsers = [
     LegacyParser(
         name='parsers/gaussian',
         parser_class_name='gaussianparser.GaussianParser',
-        mainfile_contents_re=
-            # This previous file matching string was too far down the line.
-            # r'\s*Cite this work as:'
-            # r'\s*Gaussian [0-9]+, Revision [A-Za-z0-9.]*,'
-            # r'\s\*\*\*\*\*\*\*\*\*\*\*\**'
-            # r'\s*Gaussian\s*([0-9]+):\s*([A-Za-z0-9-.]+)\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)'
-            # r'\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)')
-            r'Gaussian, Inc'),
+        # This previous file matching string was too far down the line.
+        # r'\s*Cite this work as:'
+        # r'\s*Gaussian [0-9]+, Revision [A-Za-z0-9.]*,'
+        # r'\s\*\*\*\*\*\*\*\*\*\*\*\**'
+        # r'\s*Gaussian\s*([0-9]+):\s*([A-Za-z0-9-.]+)\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)'
+        # r'\s*([0-9][0-9]?\-[A-Z][a-z][a-z]\-[0-9]+)')
+        mainfile_contents_re=r'Gaussian, Inc'),
     LegacyParser(
         name='parsers/quantumespresso',
         parser_class_name='quantumespressoparser.QuantumEspressoParserPWSCF',
diff --git a/nomad/parsing/artificial.py b/nomad/parsing/artificial.py
index 2fabcea114..9299801760 100644
--- a/nomad/parsing/artificial.py
+++ b/nomad/parsing/artificial.py
@@ -59,7 +59,7 @@ class TemplateParser(ArtificalParser):
     """
     name = 'parsers/template'
 
-    def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
+    def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
         return filename.endswith('template.json')
 
     def transform_value(self, name, value):
@@ -127,7 +127,7 @@ class ChaosParser(ArtificalParser):
     """
     name = 'parsers/chaos'
 
-    def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
+    def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
         return filename.endswith('chaos.json')
 
     def run(self, mainfile: str, logger=None) -> LocalBackend:
@@ -189,7 +189,7 @@ class GenerateRandomParser(TemplateParser):
         self.template = json.load(open(template_file, 'r'))
         self.random = None
 
-    def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
+    def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
         return os.path.basename(filename).startswith('random_')
 
     def transform_section(self, name, section):
diff --git a/nomad/parsing/parser.py b/nomad/parsing/parser.py
index cb7f67deb0..9f296ccb4e 100644
--- a/nomad/parsing/parser.py
+++ b/nomad/parsing/parser.py
@@ -34,7 +34,7 @@ class Parser(metaclass=ABCMeta):
     """
 
     @abstractmethod
-    def is_mainfile(self, filename: str, mime: str, buffer: str, compression: str = None) -> bool:
+    def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
         """
         Checks if a file is a mainfile for the parsers.
 
@@ -88,19 +88,21 @@ class LegacyParser(Parser):
         self.parser_class_name = parser_class_name
         self._mainfile_mime_re = re.compile(mainfile_mime_re)
         self._mainfile_name_re = re.compile(mainfile_name_re)
-        self._mainfile_contents_re = mainfile_contents_re
-        if self._mainfile_contents_re is not None:
-            self._mainfile_contents_re = re.compile(self._mainfile_contents_re)
+        # Assign private variable this way to avoid static check issue.
+        if mainfile_contents_re is not None:
+            self._mainfile_contents_re = re.compile(mainfile_contents_re)
+        else:
+            self._mainfile_contents_re = None
         self._supported_compressions = supported_compressions
 
     def is_mainfile(self, filename: str, mime: str, buffer: bytes, compression: str = None) -> bool:
 
         if self._mainfile_contents_re is not None:
             try:  # Try to open the file as a string for regex matching.
-                buffer = buffer.decode('utf-8')
+                decoded_buffer = buffer.decode('utf-8')
             except UnicodeDecodeError:
                 return False  # We're looking for a string match in a file that can't be converted to string.
-            if self._mainfile_contents_re.search(buffer) is None:
+            if self._mainfile_contents_re.search(decoded_buffer) is None:
                 return False
 
         return self._mainfile_mime_re.match(mime) is not None and \
-- 
GitLab