diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-06-13 23:27:03 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-06-13 23:27:03 +0000 |
commit | 03761495bc2ee062701d4b06ceca38d98a253bba (patch) | |
tree | ff1ca8f903adc41872986a08a736f15260f1c221 /tools/dev/create_unimap.py | |
parent | c5f3093e19314502240c440c076ead8c726a19aa (diff) | |
download | docutils-03761495bc2ee062701d4b06ceca38d98a253bba.tar.gz |
Make tools/ compatible with both, Python 2 and 3 without 2to3-conversion.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7442 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'tools/dev/create_unimap.py')
-rwxr-xr-x | tools/dev/create_unimap.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/tools/dev/create_unimap.py b/tools/dev/create_unimap.py index 0f733c69f..9fb75bcc7 100755 --- a/tools/dev/create_unimap.py +++ b/tools/dev/create_unimap.py @@ -13,8 +13,15 @@ from xml.dom import minidom import sys import pprint +if sys.version_info >= (3,0): + unicode = str +else: + bytes = str + chr = unichr + + def w(s): - if isinstance(s, unicode): + if sys.version_info >= (3,0) and isinstance(s, unicode): s = s.encode('utf8') sys.stdout.write(s) @@ -39,9 +46,9 @@ class Visitor: continue latex_code = n.childNodes[0].nodeValue.encode('ascii').strip() if node.attributes['mode'].value == 'math': - math_map[unichr(int(code))] = '$%s$' % latex_code + math_map[chr(int(code))] = '$%s$' % latex_code else: - text_map[unichr(int(code))] = '{%s}' % latex_code + text_map[chr(int(code))] = '{%s}' % latex_code def call_visitor(node, visitor=Visitor()): if isinstance(node, minidom.Text): @@ -63,16 +70,16 @@ unicode_map.update(text_map) # Now unicode_map contains the text entries plus dollar-enclosed math # entries for those chars for which no text entry exists. -print '# $%s$' % 'Id' -print '# Author: Lea Wiemann <LeWiemann@gmail.com>' -print '# Copyright: This file has been placed in the public domain.' -print -print '# This is a mapping of Unicode characters to LaTeX equivalents.' -print '# The information has been extracted from' -print '# <http://www.w3.org/2003/entities/xml/unicode.xml>, written by' -print '# David Carlisle and Sebastian Rahtz.' -print '#' -print '# The extraction has been done by the "create_unimap.py" script' -print '# located at <http://docutils.sf.net/tools/dev/create_unimap.py>.' -print -print 'unicode_map = %s' % pprint.pformat(unicode_map, indent=0) +print('# $%s$' % 'Id') +print('# Author: Lea Wiemann <LeWiemann@gmail.com>') +print('# Copyright: This file has been placed in the public domain.') +print('') +print('# This is a mapping of Unicode characters to LaTeX equivalents.') +print('# The information has been extracted from') +print('# <http://www.w3.org/2003/entities/xml/unicode.xml>, written by') +print('# David Carlisle and Sebastian Rahtz.') +print('#') +print('# The extraction has been done by the "create_unimap.py" script') +print('# located at <http://docutils.sf.net/tools/dev/create_unimap.py>.') +print('') +print('unicode_map = %s' % pprint.pformat(unicode_map, indent=0)) |