summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/pythontex/pythontex_2to3.py
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-07-21 22:00:53 +0000
committerKarl Berry <karl@freefriends.org>2017-07-21 22:00:53 +0000
commit26f8c60d721bcd3fe6a0183b9f5ea076f9018293 (patch)
treefbfd09188328236e0c4b2a6e91210b4a690fde90 /Master/texmf-dist/scripts/pythontex/pythontex_2to3.py
parent2a74b4e85b56e76205237f78b9b87db928cb1143 (diff)
pythontex (21jul17)
git-svn-id: svn://tug.org/texlive/trunk@44860 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/pythontex/pythontex_2to3.py')
-rwxr-xr-xMaster/texmf-dist/scripts/pythontex/pythontex_2to3.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/Master/texmf-dist/scripts/pythontex/pythontex_2to3.py b/Master/texmf-dist/scripts/pythontex/pythontex_2to3.py
index 166e6784676..442309c86b1 100755
--- a/Master/texmf-dist/scripts/pythontex/pythontex_2to3.py
+++ b/Master/texmf-dist/scripts/pythontex/pythontex_2to3.py
@@ -4,30 +4,30 @@
'''
Convert PythonTeX scripts from Python 2 to Python 3
-It isn't possible to have a single PythonTeX code base, since unicode text
-needs to be supported. Under Python 2, this means importing unicode_literals
+It isn't possible to have a single PythonTeX code base, since unicode text
+needs to be supported. Under Python 2, this means importing unicode_literals
from __future__, or using the unicode function or "u" prefix. Under Python 3,
all strings are automatically unicode.
-At the same time, the differences between the Python 2 and 3 versions are
+At the same time, the differences between the Python 2 and 3 versions are
usually very small, involving only a few lines of code. To keep the code base
-unified, while simultaneously fully supporting both Python 2 and 3, the
-following scheme was devised. The code is written for Python 2. Whenever
-code is not compatible with Python 3, it is enclosed with the tags
-"#// Python 2" and "#\\ End Python 2" (each on its own line, by itself). If
-a Python 3 version of the code is needed, it is included between analogous
-tags "#// Python 3" and "#\\ End Python 2". The Python 3 code is commented
+unified, while simultaneously fully supporting both Python 2 and 3, the
+following scheme was devised. The code is written for Python 2. Whenever
+code is not compatible with Python 3, it is enclosed with the tags
+"#// Python 2" and "#\\ End Python 2" (each on its own line, by itself). If
+a Python 3 version of the code is needed, it is included between analogous
+tags "#// Python 3" and "#\\ End Python 2". The Python 3 code is commented
out with "#", at the same indentation level as the Python 3 tags.
-This script creates Python 3 scripts from the original Python 2 scripts
-by commenting out everything between the Python 2 tags, and uncommenting
-everything between the Python 3 tags. In this way, full compatibility is
-maintained with both Python 2 and 3 while keeping the code base essentially
-unified. This approach also allows greater customization of version-specific
-code than would be possible if automatic translation with a tool like 2to3
+This script creates Python 3 scripts from the original Python 2 scripts
+by commenting out everything between the Python 2 tags, and uncommenting
+everything between the Python 3 tags. In this way, full compatibility is
+maintained with both Python 2 and 3 while keeping the code base essentially
+unified. This approach also allows greater customization of version-specific
+code than would be possible if automatic translation with a tool like 2to3
was required.
-Copyright (c) 2012-2014, Geoffrey M. Poore
+Copyright (c) 2012-2017, Geoffrey M. Poore
All rights reserved.
Licensed under the BSD 3-Clause License:
http://www.opensource.org/licenses/BSD-3-Clause
@@ -50,7 +50,7 @@ def from2to3(list_of_code):
in_2 = False
in_3 = False
indent = ''
-
+
for line in list_of_code:
if r'#// Python 2' in line:
in_2 = True
@@ -70,8 +70,8 @@ def from2to3(list_of_code):
if fixed[0].startswith('#!/usr/bin/env python2'):
fixed[0] = fixed[0].replace('python2', 'python3')
return fixed
-
-
+
+
for file in files_to_process:
f = open(file, 'r', encoding=encoding)
converted_code = from2to3(f.readlines())