Skip to content

Commit

Permalink
Fix #194 -- use io.open for Python 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska committed Jan 6, 2017
1 parent f78c97e commit c5b814a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions v6/orgmode/orgmode.py
Expand Up @@ -31,7 +31,7 @@
"""

from __future__ import unicode_literals
import codecs
import io
import os
from os.path import abspath, dirname, join
import subprocess
Expand Down Expand Up @@ -75,9 +75,9 @@ def compile_html(self, source, dest, is_two_file=True):
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with open(dest, 'r', encoding='utf-8') as inf:
with io.open(dest, 'r', encoding='utf-8') as inf:
output, shortcode_deps = self.site.apply_shortcodes(inf.read(), with_dependencies=True)
with open(dest, 'w', encoding='utf-8') as outf:
with io.open(dest, 'w', encoding='utf-8') as outf:
outf.write(output)
if post is None:
if shortcode_deps:
Expand Down Expand Up @@ -106,7 +106,7 @@ def create_post(self, path, **kw):
metadata.update(kw)
makedirs(os.path.dirname(path))

with codecs.open(path, "wb+", "utf8") as fd:
with io.open(path, "wb+", encoding="utf-8") as fd:
if onefile:
fd.write("#+BEGIN_COMMENT\n")
if write_metadata:
Expand Down

3 comments on commit c5b814a

@baali
Copy link

@baali baali commented on c5b814a Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3.x doesn't support encoding argument with files opened in "binary" mode. Documentation of io.open says: encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode.

@felixfontein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess removing the b should do the job, then? I don't see why it should have been there in the first place, anyway.

@baali
Copy link

@baali baali commented on c5b814a Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tested the same by doing it and it worked. I am not sure if all the cases would be covered by just removing the 'b'. Later in line: 106, the content could be a unicode string, which might need some more special handling to keep things from breaking.

Please sign in to comment.