Skip to content

Commit

Permalink
Added explicit utf8 encoding to file opens, reported in #11
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoffmann committed Jul 15, 2022
1 parent 01c580c commit 1cd48b3
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pygoslin/domain/FunctionalGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def to_string(self, level):
_known_functional_groups, s = {}, SumFormulaParser()
fg_dir_name = path.dirname(pygoslin.__file__)
fg_file_name = path.join(fg_dir_name, "data", "goslin", "functional-groups.csv")
with open(fg_file_name, "rt") as fg_infile:
with open(fg_file_name, mode = "rt", encoding= "utf-8") as fg_infile:
fg_infile.readline()
for line in fg_infile:
line = line.strip()
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/domain/LipidClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_class(name):

all_lipids_dir_name = path.dirname(pygoslin.__file__)
file_name = path.join(all_lipids_dir_name, "data", "goslin", "lipid-list.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
line = infile.readline() # skip title row
lipid_reader = csv.reader(infile, delimiter=',', quotechar='"')
sum_formula_parser = SumFormulaParser()
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/parser/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self):
dir_name = path.dirname(pygoslin.__file__)
file_name = path.join(dir_name, "data", "goslin", "trivial-names.csv")
with open(file_name, "rt") as trivial_infile:
with open(file_name, "rt", encoding= "utf-8") as trivial_infile:
trivial_infile.readline()
for line in trivial_infile:
line = line.strip()
Expand Down
4 changes: 2 additions & 2 deletions pygoslin/parser/ParserCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def top_nodes( rule_index):
def extract_text_based_rules(grammar_filename, quote = DEFAULT_QUOTE):
grammar, sb,current_position = "", [], 0

with open(grammar_filename, mode = "rt") as infile:
with open(grammar_filename, mode = "rt", encoding= "utf-8") as infile:
grammar = infile.read() + "\n";
grammar_length = len(grammar)

Expand Down Expand Up @@ -377,7 +377,7 @@ def extract_text_based_rules(grammar_filename, quote = DEFAULT_QUOTE):


def dump_child(self, class_name, parser_event_handler_name):
with open("%s.py" % class_name, mode = "wt") as dumpfile:
with open("%s.py" % class_name, mode = "wt", encoding= "utf-8") as dumpfile:
dumpfile.write("from pygoslin.parser.Parser import Parser\n")
dumpfile.write("from pygoslin.parser.%s import %s\n\n" % (parser_event_handler_name, parser_event_handler_name))
dumpfile.write("class %s(Parser):\n" % class_name)
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/FattyAcidsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LipidMapsTest(unittest.TestCase):
def test_parser(self):
lipid_data = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "fatty-acids-test.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
lipidreader = csv.reader(infile, delimiter=',', quotechar='"')
for row in lipidreader:
lipid_data.append(row)
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/GoslinTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_sphingolipids(self):
def test_parser(self):
lipidnames = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "goslin-test.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
for line in infile:
line = line.strip().strip(" ")
if len(line) > 0: lipidnames.append(line)
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/HmdbTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_sphingolipids(self):
def test_parser(self):
lipidnames = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "hmdb-test.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
for line in infile:
line = line.strip().strip(" ")
if len(line) > 0: lipidnames.append(line)
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/LipidMapsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_sphingolipids(self):
def test_parser(self):
lipidnames = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "lipid-maps-test.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
lipidreader = csv.reader(infile, delimiter=',', quotechar='"')
for row in lipidreader:
lipidnames.append(row)
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/MassesTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TestFormulas(unittest.TestCase):
def test_masses(self):
global parser
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", 'lipid-masses.csv')
with open(file_name, newline='') as csvfile:
with open(file_name, newline='', encoding= "utf-8") as csvfile:
lipidreader = csv.reader(csvfile, delimiter=',', quotechar='\"')
for i, row in enumerate(lipidreader):
if i == 0: continue
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/ParserTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def test_parser_read(self):
global lipid_parser
lipidnames = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "lipidnames.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
for line in infile:
line = line.strip().strip(" ")
if len(line) < 2: continue
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/ShorthandTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_sphingolipids(self):
def test_nomenclature(self):
data = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "shorthand-test.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
lipidreader = csv.reader(infile, delimiter=',', quotechar='"')
for row in lipidreader:
row[-1] = row[-1].strip(" ")
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/tests/SwissLipidsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_sphingolipids(self):
def teset_swiss_lipids_parser(self):
lipidnames = []
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", "swiss-lipids-test.csv")
with open(file_name, mode = "rt") as infile:
with open(file_name, mode = "rt", encoding= "utf-8") as infile:
for line in infile:
line = line.strip().strip(" ")
if len(line) > 0: lipidnames.append(line)
Expand Down
4 changes: 2 additions & 2 deletions pygoslin/tests/TestFormulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TestFormulas(unittest.TestCase):
def test_formulas_swiss_lipids(self):
global swiss_lipids_parser
file_names = os.path.join("pygoslin", "data", "goslin", "testfiles", 'formulas-swiss-lipids.csv')
with open(file_names, newline='') as csvfile:
with open(file_names, newline='', encoding= "utf-8") as csvfile:
lipidreader = csv.reader(csvfile, delimiter=',', quotechar='\"')

for row in lipidreader:
Expand All @@ -70,7 +70,7 @@ def test_formulas_swiss_lipids(self):
def test_formulas_lipid_maps(self):
global lipids_maps_parser
file_name = os.path.join("pygoslin", "data", "goslin", "testfiles", 'formulas-lipid-maps.csv')
with open(file_name, newline='') as csvfile:
with open(file_name, newline='', encoding= "utf-8") as csvfile:
lipidreader = csv.reader(csvfile, delimiter=',', quotechar='\"')

for row in lipidreader:
Expand Down

0 comments on commit 1cd48b3

Please sign in to comment.