python: Add __future__ imports for python 3 compatibility

Except for src/ext, which we may not want to modify.

Closes ticket 32732.
This commit is contained in:
teor 2019-12-12 15:58:51 +10:00
parent a38014e5c6
commit 1619f14a04
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A
36 changed files with 168 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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" ]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 *

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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