Skip to content

Commit

Permalink
Merge pull request #26 from pkgw/next
Browse files Browse the repository at this point in the history
Specify UTF-8 encoding whenever working with text
  • Loading branch information
pkgw committed Oct 5, 2020
2 parents 939324b + d069b77 commit fe19e1d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions toasty/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def query_candidates(self):
def open_input(self, unique_id, cachedir):
import json

with open(os.path.join(cachedir, 'astropix.json'), 'rt') as f:
with open(os.path.join(cachedir, 'astropix.json'), 'rt', encoding='utf8') as f:
json_data = json.load(f)

return AstroPixInputImage(unique_id, cachedir, json_data)
Expand Down Expand Up @@ -499,7 +499,7 @@ def cache_data(self, cachedir):

# Save the AstroPix metadata as well.

with open(os.path.join(cachedir, 'astropix.json'), 'wt') as f:
with open(os.path.join(cachedir, 'astropix.json'), 'wt', encoding='utf8') as f:
json.dump(self._json, f)


Expand Down Expand Up @@ -843,7 +843,7 @@ def ensure_config(self):
with open(cfg_path, 'wb') as f:
self._pipeio.get_item('toasty-pipeline-config.yaml', dest=f)

with open(cfg_path, 'rt') as f:
with open(cfg_path, 'rt', encoding='utf8') as f:
config = yaml.safe_load(f)

if config is None:
Expand Down Expand Up @@ -926,7 +926,7 @@ def process_todos(self):
# requires us to use some configuration data. The `place` that we
# get out of the processing stage has relative URLs.

with open(self._path('out_todo', uniq_id, 'index_rel.wtml'), 'w') as f:
with open(self._path('out_todo', uniq_id, 'index_rel.wtml'), 'wt', encoding='utf8') as f:
write_xml_doc(folder.to_xml(), dest_stream=f)

if pub_url_prefix:
Expand All @@ -936,7 +936,7 @@ def process_todos(self):
place.foreground_image_set.thumbnail_url = maybe_prefix_url(place.foreground_image_set.thumbnail_url, pfx)
place.thumbnail = maybe_prefix_url(place.thumbnail, pfx)

with open(self._path('out_todo', uniq_id, 'index.wtml'), 'w') as f:
with open(self._path('out_todo', uniq_id, 'index.wtml'), 'wt', encoding='utf8') as f:
write_xml_doc(folder.to_xml(), dest_stream=f)

# All done here.
Expand Down
4 changes: 2 additions & 2 deletions toasty/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def cache_data(self, cachedir):

self._json['toasty_cached_image_name'] = 'image.' + ext

with open(os.path.join(cachedir, 'astropix.json'), 'wt') as f:
with open(os.path.join(cachedir, 'astropix.json'), 'wt', encoding='utf8') as f:
json.dump(self._json, f)


Expand Down Expand Up @@ -65,7 +65,7 @@ def query_candidates(self):
def open_input(self, unique_id, cachedir):
import json

with open(os.path.join(cachedir, 'astropix.json'), 'rt') as f:
with open(os.path.join(cachedir, 'astropix.json'), 'rt', encoding='utf8') as f:
json_data = json.load(f)

return pipeline.AstroPixInputImage(unique_id, cachedir, json_data)
Expand Down
2 changes: 1 addition & 1 deletion toasty/tests/test_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_sample_cli(self):
]
cli.entrypoint(args)

with open(self.work_path('index_rel.wtml')) as f:
with open(self.work_path('index_rel.wtml'), 'rt', encoding='utf8') as f:
observed = etree.fromstring(f.read())

assert_xml_elements_equal(observed, expected)

0 comments on commit fe19e1d

Please sign in to comment.