Skip to content

Commit 01d6c77

Browse files
committed
Merge pull request JessicaTegner#6 from coldfix/python3-compatibility
Python3 compatibility
2 parents 1b44196 + caf6336 commit 01d6c77

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

‎pypandoc/pypandoc.py‎ renamed to ‎pypandoc.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
# -*- coding: utf-8 -*-
12
from __future__ import with_statement
3+
4+
__author__ = 'Juho Vepsäläinen'
5+
__version__ = '0.6.0'
6+
__license__ = 'MIT'
7+
__all__ = ['convert', 'get_pandoc_formats']
8+
29
import subprocess
310
import os
411

12+
13+
514
def convert(source, to, format=None, extra_args=()):
615
'''Converts given `source` from `format` `to` another. `source` may be either a file path or a string to be converted. It's possible to pass `extra_args` if needed. In case `format` is not provided, it will try to invert the format based on given `source`.
716
@@ -47,17 +56,23 @@ def _process_file(source, to, format, extra_args):
4756
args = ['pandoc', '--from=' + format, '--to=' + to]
4857
args.extend(extra_args)
4958

50-
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
59+
p = subprocess.Popen(
60+
args,
61+
stdin=subprocess.PIPE,
62+
stdout=subprocess.PIPE)
5163

52-
return p.communicate(source)[0]
64+
return p.communicate(source.encode())[0].decode()
5365

5466
def get_pandoc_formats():
5567
'''
5668
Dynamic preprocessor for Pandoc formats.
5769
Return 2 lists. "from_formats" and "to_formats".
5870
'''
59-
p = subprocess.Popen(['pandoc', '-h'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
60-
help_text = p.communicate()[0].splitlines(False)
71+
p = subprocess.Popen(
72+
['pandoc', '-h'],
73+
stdin=subprocess.PIPE,
74+
stdout=subprocess.PIPE)
75+
help_text = p.communicate()[0].decode().splitlines(False)
6176
txt = ' '.join(help_text[1:help_text.index('Options:')])
6277

6378
aux = txt.split('Output formats: ')

‎tests/pypandoc.spec‎ renamed to ‎pypandoc.spec‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pypandoc import pypandoc
1+
import pypandoc
22

33
def test_converter(to, format=None, extra_args=()):
44
def reader(*args):

‎pypandoc/__init__.py‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎setup.py‎

100644100755
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
try:
88
long_description = pypandoc.convert('README.md', 'rst')
99
except (IOError, OSError):
10-
print 'check that you have installed pandoc properly and that README.md exists!'
10+
print('check that you have installed pandoc properly and that README.md exists!')
1111
long_description = description
1212

1313
module = pypandoc
@@ -20,8 +20,7 @@
2020
long_description = long_description,
2121
author = module.__author__,
2222
author_email = 'bebraw@gmail.com',
23-
packages = ['pypandoc', ],
24-
package_dir = {'pypandoc': 'pypandoc', },
23+
py_modules = ['pypandoc', ],
2524
install_requires = ['setuptools', ],
2625
classifiers=[
2726
'Development Status :: 4 - Beta',
@@ -34,5 +33,5 @@
3433
'Topic :: Text Processing',
3534
'Topic :: Text Processing :: Filters',
3635
],
37-
test_suite = 'pypandoc'
36+
test_suite = 'tests'
3837
)

‎pypandoc/test_pypandoc.py‎ renamed to ‎tests.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,29 @@ def test_does_not_convert_from_invalid_format(self):
3737
def test_basic_conversion_from_file(self):
3838
# This will not work on windows:
3939
# http://docs.python.org/2/library/tempfile.html
40-
test_file = tempfile.NamedTemporaryFile(suffix='.md')
40+
test_file = tempfile.NamedTemporaryFile('w+t', suffix='.md')
4141
file_name = test_file.name
4242
test_file.write('#some title\n')
4343
test_file.flush()
4444
expected = 'some title\n==========\n\n'
4545
received = pypandoc.convert(file_name, 'rst')
46-
self.assertAlmostEqual(expected, received)
46+
self.assertEqual(expected, received)
4747

4848
def test_basic_conversion_from_file_with_format(self):
4949
# This will not work on windows:
5050
# http://docs.python.org/2/library/tempfile.html
51-
test_file = tempfile.NamedTemporaryFile(suffix='.rst')
51+
test_file = tempfile.NamedTemporaryFile('w+t', suffix='.rst')
5252
file_name = test_file.name
5353
test_file.write('#some title\n')
5454
test_file.flush()
5555
expected = 'some title\n==========\n\n'
5656
received = pypandoc.convert(file_name, 'rst', format='md')
57-
self.assertAlmostEqual(expected, received)
57+
self.assertEqual(expected, received)
5858

5959
def test_basic_conversion_from_string(self):
6060
expected = 'some title\n==========\n\n'
6161
received = pypandoc.convert('#some title', 'rst', format='md')
62-
self.assertAlmostEqual(expected, received)
62+
self.assertEqual(expected, received)
6363

6464
suite = unittest.TestLoader().loadTestsFromTestCase(TestPypandoc)
6565
unittest.TextTestRunner(verbosity=2).run(suite)

0 commit comments

Comments
 (0)