From 9d4fc96c2079581fddba0723e32f8f0a0adca1ac Mon Sep 17 00:00:00 2001
From: madsmpedersen <m@madsp.dk>
Date: Tue, 5 Jul 2016 11:52:21 +0200
Subject: [PATCH] add fix for htc files with BOM

---
 wetb/hawc2/htc_file.py            | 4 +++-
 wetb/hawc2/tests/test_htc_file.py | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py
index 92740e80..52caf64a 100644
--- a/wetb/hawc2/htc_file.py
+++ b/wetb/hawc2/htc_file.py
@@ -72,7 +72,9 @@ class HTCFile(HTCContents, HTCDefaults):
         self.htc_inputfiles.append(filename)
         htc_lines = []
         with open(filename, encoding='cp1252') as fid:
-            lines = fid.readlines()
+            lines = list(fid.readlines())
+        if lines[0].encode().startswith(b'\xc3\xaf\xc2\xbb\xc2\xbf'):
+            lines[0] = lines[0][3:]
         for l in lines:
             if l.lower().lstrip().startswith('continue_in_file'):
                 filename = l.lstrip().split(";")[0][len("continue_in_file"):].strip()
diff --git a/wetb/hawc2/tests/test_htc_file.py b/wetb/hawc2/tests/test_htc_file.py
index 71fbb4d2..4c5fd806 100644
--- a/wetb/hawc2/tests/test_htc_file.py
+++ b/wetb/hawc2/tests/test_htc_file.py
@@ -241,6 +241,11 @@ class TestHtcFile(unittest.TestCase):
     def test_ansi(self):
         htcfile = HTCFile(self.testfilepath + "./ansi.htc")
 
+    def test_file_with_BOM(self):
+        htcfile = HTCFile(self.testfilepath + 'DLC15_wsp11_wdir000_s0000_phi000_Free_v2_visual.htc')
+        self.assertEqual(str(htcfile)[0], ";")
+
+
 
 
 
-- 
GitLab