[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] python: Add __future__ imports for python 3 compatibility



commit 1619f14a0420b0a57d65b9adeab8e8a4ef222b3a
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Thu Dec 12 15:58:51 2019 +1000

    python: Add __future__ imports for python 3 compatibility
    
    Except for src/ext, which we may not want to modify.
    
    Closes ticket 32732.
---
 contrib/client-tools/tor-resolve.py            |  5 +++++
 scripts/codegen/fuzzing_include_am.py          |  5 +++++
 scripts/codegen/gen_server_ciphers.py          |  5 +++++
 scripts/codegen/get_mozilla_ciphers.py         |  5 +++++
 scripts/codegen/makedesc.py                    |  5 +++++
 scripts/maint/add_c_file.py                    |  5 +++++
 scripts/maint/annotate_ifdef_directives.py     |  5 +++++
 scripts/maint/checkIncludes.py                 |  5 +++++
 scripts/maint/format_changelog.py              |  4 ++++
 scripts/maint/lintChanges.py                   |  5 ++++-
 scripts/maint/locatemissingdoxygen.py          |  5 +++++
 scripts/maint/practracker/includes.py          |  4 +++-
 scripts/maint/practracker/metrics.py           |  5 +++++
 scripts/maint/practracker/practracker.py       |  3 +++
 scripts/maint/practracker/practracker_tests.py |  5 +++++
 scripts/maint/practracker/problem.py           |  3 +++
 scripts/maint/practracker/util.py              |  5 +++++
 scripts/maint/rectify_include_paths.py         |  5 +++++
 scripts/maint/redox.py                         | 11 ++++++++---
 scripts/maint/rename_c_identifier.py           |  5 +++++
 scripts/maint/sortChanges.py                   |  4 ++++
 scripts/maint/update_versions.py               |  3 +++
 scripts/test/appveyor-irc-notify.py            |  4 +++-
 src/config/mmdb-convert.py                     |  5 +++++
 src/test/bt_test.py                            |  4 ++++
 src/test/ed25519_exts_ref.py                   |  5 +++++
 src/test/hs_build_address.py                   |  5 +++++
 src/test/hs_indexes.py                         |  5 +++++
 src/test/hs_ntor_ref.py                        |  5 +++++
 src/test/ntor_ref.py                           |  5 +++++
 src/test/ope_ref.py                            |  5 +++++
 src/test/slow_ed25519.py                       |  5 +++++
 src/test/slownacl_curve25519.py                |  7 ++++++-
 src/test/sr_commit_calc_ref.py                 |  5 +++++
 src/test/sr_srv_calc_ref.py                    |  5 +++++
 src/test/test_rebind.py                        |  3 +++
 36 files changed, 168 insertions(+), 7 deletions(-)

diff --git a/contrib/client-tools/tor-resolve.py b/contrib/client-tools/tor-resolve.py
index 47ae1a0c3..593efc97d 100755
--- a/contrib/client-tools/tor-resolve.py
+++ b/contrib/client-tools/tor-resolve.py
@@ -1,5 +1,10 @@
 #!/usr/bin/python
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import socket
 import struct
 import sys
diff --git a/scripts/codegen/fuzzing_include_am.py b/scripts/codegen/fuzzing_include_am.py
index a94458445..aa3ba49a7 100755
--- a/scripts/codegen/fuzzing_include_am.py
+++ b/scripts/codegen/fuzzing_include_am.py
@@ -1,5 +1,10 @@
 #!/usr/bin/python
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 FUZZERS = """
 	consensus
 	descriptor
diff --git a/scripts/codegen/gen_server_ciphers.py b/scripts/codegen/gen_server_ciphers.py
index 5d326f8b9..dd295b7f7 100755
--- a/scripts/codegen/gen_server_ciphers.py
+++ b/scripts/codegen/gen_server_ciphers.py
@@ -8,6 +8,11 @@
 #
 # Run it on all the files in your openssl include directory.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import re
 import sys
 
diff --git a/scripts/codegen/get_mozilla_ciphers.py b/scripts/codegen/get_mozilla_ciphers.py
index f23f2f1e6..d149c71c2 100755
--- a/scripts/codegen/get_mozilla_ciphers.py
+++ b/scripts/codegen/get_mozilla_ciphers.py
@@ -10,6 +10,11 @@
 # It takes two arguments: the location of a firefox source directory, and the
 # location of an openssl source directory.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import os
 import re
 import sys
diff --git a/scripts/codegen/makedesc.py b/scripts/codegen/makedesc.py
index efca4dda9..7d8177f46 100644
--- a/scripts/codegen/makedesc.py
+++ b/scripts/codegen/makedesc.py
@@ -9,6 +9,11 @@
 # I've used this to make inputs for unit tests.  I wouldn't suggest
 # using it for anything else.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import base64
 import binascii
 import ctypes
diff --git a/scripts/maint/add_c_file.py b/scripts/maint/add_c_file.py
index a773fd0ff..a9a6eb25b 100755
--- a/scripts/maint/add_c_file.py
+++ b/scripts/maint/add_c_file.py
@@ -9,6 +9,11 @@
    % add_c_file.py ./src/feature/dirauth/ocelot.c
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import os
 import re
 import time
diff --git a/scripts/maint/annotate_ifdef_directives.py b/scripts/maint/annotate_ifdef_directives.py
index 102128bfa..cd70b55c8 100755
--- a/scripts/maint/annotate_ifdef_directives.py
+++ b/scripts/maint/annotate_ifdef_directives.py
@@ -57,6 +57,11 @@ Note that only #else and #endif lines are annotated.  Existing comments
 on those lines are removed.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import re
 
 # Any block with fewer than this many lines does not need annotations.
diff --git a/scripts/maint/checkIncludes.py b/scripts/maint/checkIncludes.py
index 926b201b3..2ca46347f 100755
--- a/scripts/maint/checkIncludes.py
+++ b/scripts/maint/checkIncludes.py
@@ -5,6 +5,11 @@
 # functionality.  This is a stub file that exists so that older git
 # hooks will know where to look.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import sys, os
 
 dirname = os.path.split(sys.argv[0])[0]
diff --git a/scripts/maint/format_changelog.py b/scripts/maint/format_changelog.py
index 97a6ce938..5f04a44ef 100755
--- a/scripts/maint/format_changelog.py
+++ b/scripts/maint/format_changelog.py
@@ -9,7 +9,11 @@
 # To run it, pipe a section of the changelog (starting with "Changes
 # in Tor 0.x.y.z-alpha" through the script.)
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
+
 import os
 import re
 import sys
diff --git a/scripts/maint/lintChanges.py b/scripts/maint/lintChanges.py
index 82c118f07..88a865a57 100755
--- a/scripts/maint/lintChanges.py
+++ b/scripts/maint/lintChanges.py
@@ -1,7 +1,10 @@
 #!/usr/bin/python
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
-from __future__ import with_statement
+from __future__ import unicode_literals
+
 import sys
 import re
 import os
diff --git a/scripts/maint/locatemissingdoxygen.py b/scripts/maint/locatemissingdoxygen.py
index 797bf8176..9e58bd347 100755
--- a/scripts/maint/locatemissingdoxygen.py
+++ b/scripts/maint/locatemissingdoxygen.py
@@ -7,6 +7,11 @@
   to highlight the undocumented stuff.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import os
 import re
 import shutil
diff --git a/scripts/maint/practracker/includes.py b/scripts/maint/practracker/includes.py
index ed0e11ef2..fe0f32e25 100755
--- a/scripts/maint/practracker/includes.py
+++ b/scripts/maint/practracker/includes.py
@@ -19,8 +19,10 @@
    Advisory .may_include files only result in warnings, rather than errors.
 """
 
-
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
 
 import fnmatch
 import os
diff --git a/scripts/maint/practracker/metrics.py b/scripts/maint/practracker/metrics.py
index 4c62bc242..ae88b84f3 100644
--- a/scripts/maint/practracker/metrics.py
+++ b/scripts/maint/practracker/metrics.py
@@ -4,6 +4,11 @@
 # These are currently ad-hoc string operations and regexps.
 # We might want to use a proper static analysis library in the future, if we want to get more advanced metrics.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import re
 
 def get_file_len(f):
diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py
index 5f26d28ce..e1845c43e 100755
--- a/scripts/maint/practracker/practracker.py
+++ b/scripts/maint/practracker/practracker.py
@@ -19,7 +19,10 @@ problems in the Tor source, use the --regen flag:
   $ python3 --regen ./scripts/maint/practracker/practracker.py .
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
 
 import os, sys
 
diff --git a/scripts/maint/practracker/practracker_tests.py b/scripts/maint/practracker/practracker_tests.py
index 45719d6cb..8d0418880 100755
--- a/scripts/maint/practracker/practracker_tests.py
+++ b/scripts/maint/practracker/practracker_tests.py
@@ -2,6 +2,11 @@
 
 """Some simple tests for practracker metrics"""
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import unittest
 
 try:
diff --git a/scripts/maint/practracker/problem.py b/scripts/maint/practracker/problem.py
index d21840a21..bee5eeb90 100644
--- a/scripts/maint/practracker/problem.py
+++ b/scripts/maint/practracker/problem.py
@@ -7,7 +7,10 @@ problem is worse than a registered exception so that it only warns when things
 get worse.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
 
 import os.path
 import re
diff --git a/scripts/maint/practracker/util.py b/scripts/maint/practracker/util.py
index db02a983f..c52ca2fbb 100644
--- a/scripts/maint/practracker/util.py
+++ b/scripts/maint/practracker/util.py
@@ -1,3 +1,8 @@
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import os
 
 # We don't want to run metrics for unittests, automatically-generated C files,
diff --git a/scripts/maint/rectify_include_paths.py b/scripts/maint/rectify_include_paths.py
index 1140e8cd2..111cf816c 100755
--- a/scripts/maint/rectify_include_paths.py
+++ b/scripts/maint/rectify_include_paths.py
@@ -1,5 +1,10 @@
 #!/usr/bin/python
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import os
 import os.path
 import re
diff --git a/scripts/maint/redox.py b/scripts/maint/redox.py
index 203cce010..171c6d969 100755
--- a/scripts/maint/redox.py
+++ b/scripts/maint/redox.py
@@ -29,6 +29,14 @@
 #     "mv fname.c.newdoc fname.c".  Otherwise, you'll need to merge
 #     the parts you like by hand.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
+import re
+import sys
+
 # Which files should we ignore warning from?  Mostly, these are external
 # files that we've snarfed in from somebody else, whose C we do no intend
 # to document for them.
@@ -52,9 +60,6 @@ ADD_DOCDOCS_TO_TYPES += [ 'variable', ]
 # ====================
 # The rest of this should not need hacking.
 
-import re
-import sys
-
 KINDS = [ "type", "field", "typedef", "define", "function", "variable",
           "enumeration" ]
 
diff --git a/scripts/maint/rename_c_identifier.py b/scripts/maint/rename_c_identifier.py
index 213172d91..6e0c1d8cf 100755
--- a/scripts/maint/rename_c_identifier.py
+++ b/scripts/maint/rename_c_identifier.py
@@ -11,6 +11,11 @@ Helpful script to replace one or more C identifiers, and optionally
 generate a commit message explaining what happened.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import argparse
 import fileinput
 import os
diff --git a/scripts/maint/sortChanges.py b/scripts/maint/sortChanges.py
index 44dd0dc41..2e049b1e5 100755
--- a/scripts/maint/sortChanges.py
+++ b/scripts/maint/sortChanges.py
@@ -7,7 +7,11 @@
    changelog.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
+
 import re
 import sys
 
diff --git a/scripts/maint/update_versions.py b/scripts/maint/update_versions.py
index 706a93b6a..07de1c343 100755
--- a/scripts/maint/update_versions.py
+++ b/scripts/maint/update_versions.py
@@ -1,6 +1,9 @@
 #!/usr/bin/env python
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
 
 import io
 import os
diff --git a/scripts/test/appveyor-irc-notify.py b/scripts/test/appveyor-irc-notify.py
index cfe0afe7a..598a68f47 100644
--- a/scripts/test/appveyor-irc-notify.py
+++ b/scripts/test/appveyor-irc-notify.py
@@ -75,8 +75,10 @@ in Appveyor's YAML:
       - "python scripts/test/appveyor-irc-notify.py irc.oftc.net:6697 tor-ci failure
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
-from __future__ import absolute_import
+from __future__ import unicode_literals
 
 import os
 import random
diff --git a/src/config/mmdb-convert.py b/src/config/mmdb-convert.py
index b861e9433..a58f5d43e 100644
--- a/src/config/mmdb-convert.py
+++ b/src/config/mmdb-convert.py
@@ -28,6 +28,11 @@
    pieces.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import struct
 import bisect
 import socket
diff --git a/src/test/bt_test.py b/src/test/bt_test.py
index f9ca79efd..d728f1359 100755
--- a/src/test/bt_test.py
+++ b/src/test/bt_test.py
@@ -15,7 +15,11 @@ OK
 
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
+
 import sys
 
 
diff --git a/src/test/ed25519_exts_ref.py b/src/test/ed25519_exts_ref.py
index 75562184b..658f7cde1 100644
--- a/src/test/ed25519_exts_ref.py
+++ b/src/test/ed25519_exts_ref.py
@@ -8,6 +8,11 @@
    Includes self-tester and test vector generator.
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import slow_ed25519
 from slow_ed25519 import *
 
diff --git a/src/test/hs_build_address.py b/src/test/hs_build_address.py
index 7ff22c3a9..91864eabc 100644
--- a/src/test/hs_build_address.py
+++ b/src/test/hs_build_address.py
@@ -1,3 +1,8 @@
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import sys
 import hashlib
 import struct
diff --git a/src/test/hs_indexes.py b/src/test/hs_indexes.py
index af0b81f8d..5c6d893a6 100644
--- a/src/test/hs_indexes.py
+++ b/src/test/hs_indexes.py
@@ -7,6 +7,11 @@
 # store/fetch the descriptor on the hashring. (hs_build_hs_index()).
 #
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import sys
 import hashlib
 import struct
diff --git a/src/test/hs_ntor_ref.py b/src/test/hs_ntor_ref.py
index 1b9772a5d..f107cc36c 100644
--- a/src/test/hs_ntor_ref.py
+++ b/src/test/hs_ntor_ref.py
@@ -41,6 +41,11 @@ The whole logic and concept for this test suite was taken from ntor_ref.py.
                 *** DO NOT USE THIS IN PRODUCTION. ***
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import struct
 import os, sys
 import binascii
diff --git a/src/test/ntor_ref.py b/src/test/ntor_ref.py
index 3e642eb25..e3307430e 100755
--- a/src/test/ntor_ref.py
+++ b/src/test/ntor_ref.py
@@ -27,6 +27,11 @@ commands:
 
 """
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import binascii
 try:
     import curve25519
diff --git a/src/test/ope_ref.py b/src/test/ope_ref.py
index b2f701256..61a86b57b 100644
--- a/src/test/ope_ref.py
+++ b/src/test/ope_ref.py
@@ -4,6 +4,11 @@
 # Reference implementation for our rudimentary OPE code, used to
 # generate test vectors. See crypto_ope.c for more details.
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
 from cryptography.hazmat.primitives.ciphers.algorithms import AES
 from cryptography.hazmat.backends import default_backend
diff --git a/src/test/slow_ed25519.py b/src/test/slow_ed25519.py
index f44708b20..afad67800 100644
--- a/src/test/slow_ed25519.py
+++ b/src/test/slow_ed25519.py
@@ -8,6 +8,11 @@
 #
 # Don't edit this file.  Mess with ed25519_ref.py
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import hashlib
 
 b = 256
diff --git a/src/test/slownacl_curve25519.py b/src/test/slownacl_curve25519.py
index 4dabab61b..0cafe0e71 100644
--- a/src/test/slownacl_curve25519.py
+++ b/src/test/slownacl_curve25519.py
@@ -6,10 +6,15 @@
 # Nick got the slownacl source from:
 #        https://github.com/mdempsky/dnscurve/tree/master/slownacl
 
-__all__ = ['smult_curve25519_base', 'smult_curve25519']
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
 
 import sys
 
+__all__ = ['smult_curve25519_base', 'smult_curve25519']
+
 P = 2 ** 255 - 19
 A = 486662
 
diff --git a/src/test/sr_commit_calc_ref.py b/src/test/sr_commit_calc_ref.py
index 45e629cfb..c4cb72d87 100644
--- a/src/test/sr_commit_calc_ref.py
+++ b/src/test/sr_commit_calc_ref.py
@@ -12,6 +12,11 @@
 #      COMMIT = base64-encode( TIMESTAMP || H(REVEAL) )
 #
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import sys
 import hashlib
 import struct
diff --git a/src/test/sr_srv_calc_ref.py b/src/test/sr_srv_calc_ref.py
index 492ca62b1..a3752b15c 100644
--- a/src/test/sr_srv_calc_ref.py
+++ b/src/test/sr_srv_calc_ref.py
@@ -10,6 +10,11 @@
 #                     HASHED_REVEALS | previous_SRV)
 #
 
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
 import sys
 import hashlib
 import struct
diff --git a/src/test/test_rebind.py b/src/test/test_rebind.py
index c9b9200b2..3fc3deb68 100644
--- a/src/test/test_rebind.py
+++ b/src/test/test_rebind.py
@@ -1,4 +1,7 @@
+# Future imports for Python 2.7, mandatory in 3.0
+from __future__ import division
 from __future__ import print_function
+from __future__ import unicode_literals
 
 import errno
 import logging



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits