Skip to content

Commit d593d2c

Browse files
committed
Use Unicode everywhere for autogenerating code
1 parent 6e443c8 commit d593d2c

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

autogen/args.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# http://www.gnu.org/licenses/
1313
#*****************************************************************************
1414

15+
from __future__ import unicode_literals
16+
1517
# Some replacements for reserved words
1618
replacements = {'char': 'character'}
1719

autogen/generator.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# http://www.gnu.org/licenses/
1414
#*****************************************************************************
1515

16-
from __future__ import absolute_import, print_function
17-
import os, re, sys
16+
from __future__ import absolute_import, print_function, unicode_literals
17+
import os, re, sys, io
1818

1919
from .args import PariArgumentGEN, PariInstanceArgument
2020
from .parser import read_pari_desc, parse_prototype
@@ -284,9 +284,6 @@ def write_method(self, function, cname, args, ret, cargs, file, doc, obsolete):
284284
given whenever this method is called
285285
"""
286286
doc = doc.replace("\n", "\n ") # Indent doc
287-
# doc is unicode, we want str => need to convert on Python 2
288-
if not isinstance(doc, str):
289-
doc = doc.encode("utf-8")
290287

291288
protoargs = ", ".join(a.prototype_code() for a in args)
292289
callargs = ", ".join(a.call_code() for a in cargs)
@@ -320,16 +317,11 @@ def __call__(self):
320317
D = sorted(D.values(), key=lambda d: d['function'])
321318
sys.stdout.write("Generating PARI functions:")
322319

323-
# Stupid Python 3 forces us to specify an encoding
324-
if "encoding" in open.__doc__:
325-
kwds = dict(mode="wt", encoding="utf-8")
326-
else:
327-
kwds = dict(mode="wt")
328-
self.gen_file = open(self.gen_filename + '.tmp', **kwds)
320+
self.gen_file = io.open(self.gen_filename + '.tmp', 'w', encoding='utf-8')
329321
self.gen_file.write(gen_banner)
330-
self.instance_file = open(self.instance_filename + '.tmp', **kwds)
322+
self.instance_file = io.open(self.instance_filename + '.tmp', 'w', encoding='utf-8')
331323
self.instance_file.write(instance_banner)
332-
self.decl_file = open(self.decl_filename + '.tmp', **kwds)
324+
self.decl_file = io.open(self.decl_filename + '.tmp', 'w', encoding='utf-8')
333325
self.decl_file.write(decl_banner)
334326

335327
for v in D:

autogen/parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
# http://www.gnu.org/licenses/
1313
#*****************************************************************************
1414

15-
from __future__ import absolute_import
15+
from __future__ import absolute_import, unicode_literals
1616

17-
import os, re
17+
import os, re, io
1818

1919
from .args import pari_arg_types
2020
from .ret import pari_ret_types
@@ -44,7 +44,8 @@ def read_pari_desc():
4444
... 'section': 'transcendental'}
4545
True
4646
"""
47-
with open(os.path.join(pari_share(), b'pari.desc')) as f:
47+
pari_desc = os.path.join(pari_share(), b'pari.desc')
48+
with io.open(pari_desc, encoding="utf-8") as f:
4849
lines = f.readlines()
4950

5051
n = 0
@@ -100,7 +101,7 @@ def parse_prototype(proto, help, initial_args=[]):
100101
>>> help = 'qfbred(x,{flag=0},{d},{isd},{sd})'
101102
>>> parse_prototype(proto, help)
102103
([GEN x, long flag=0, GEN d=NULL, GEN isd=NULL, GEN sd=NULL], GEN)
103-
>>> parse_prototype("lp", "foo()", ["TEST"])
104+
>>> parse_prototype("lp", "foo()", [str("TEST")])
104105
(['TEST', prec precision=0], long)
105106
"""
106107
# Use the help string just for the argument names.

autogen/paths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# http://www.gnu.org/licenses/
1313
#*****************************************************************************
1414

15-
from __future__ import absolute_import
15+
from __future__ import absolute_import, unicode_literals
1616

1717
import os
1818
from glob import glob

autogen/ret.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# http://www.gnu.org/licenses/
1313
#*****************************************************************************
1414

15+
from __future__ import unicode_literals
16+
1517
class PariReturn(object):
1618
"""
1719
This class represents the return value of a PARI call.

0 commit comments

Comments
 (0)