Skip to content
Permalink
Browse files

Fix #194 -- use io.open for Python 2 support

  • Loading branch information
Kwpolska committed Jan 6, 2017
1 parent f78c97e commit c5b814ae79d901efa1c29e27510544686c5d2002
Showing with 4 additions and 4 deletions.
  1. +4 −4 v6/orgmode/orgmode.py
@@ -31,7 +31,7 @@
"""

from __future__ import unicode_literals
import codecs
import io
import os
from os.path import abspath, dirname, join
import subprocess
@@ -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:
@@ -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:

3 comments on commit c5b814a

@baali

This comment has been minimized.

Copy link

@baali baali replied Jan 9, 2017

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

This comment has been minimized.

Copy link
Contributor

@felixfontein felixfontein replied Jan 9, 2017

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

This comment has been minimized.

Copy link

@baali baali replied Jan 9, 2017

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.
You can’t perform that action at this time.