diff --git a/git_config.py b/git_config.py index fd8e9268..2fa43a1e 100644 --- a/git_config.py +++ b/git_config.py @@ -14,6 +14,7 @@ import contextlib import errno +from http.client import HTTPException import json import os import re @@ -26,25 +27,12 @@ try: except ImportError: import dummy_threading as _threading import time - -from pyversion import is_python3 -if is_python3(): - import urllib.request - import urllib.error -else: - import urllib2 - import imp - urllib = imp.new_module('urllib') - urllib.request = urllib2 - urllib.error = urllib2 +import urllib.error +import urllib.request from error import GitError, UploadError import platform_utils from repo_trace import Trace -if is_python3(): - from http.client import HTTPException -else: - from httplib import HTTPException from git_command import GitCommand from git_command import ssh_sock @@ -341,8 +329,6 @@ class GitConfig(object): d = self._do('--null', '--list') if d is None: return c - if not is_python3(): - d = d.decode('utf-8') for line in d.rstrip('\0').split('\0'): if '\n' in line: key, val = line.split('\n', 1) diff --git a/hooks.py b/hooks.py index f805de6b..67c21a25 100644 --- a/hooks.py +++ b/hooks.py @@ -19,20 +19,11 @@ import re import subprocess import sys import traceback +import urllib.parse from error import HookError from git_refs import HEAD -from pyversion import is_python3 -if is_python3(): - import urllib.parse -else: - import imp - import urlparse - urllib = imp.new_module('urllib') - urllib.parse = urlparse - input = raw_input # noqa: F821 - class RepoHook(object): """A RepoHook contains information about a script to run as a hook. diff --git a/main.py b/main.py index cd0b8620..f638a677 100755 --- a/main.py +++ b/main.py @@ -28,15 +28,7 @@ import shlex import sys import textwrap import time - -from pyversion import is_python3 -if is_python3(): - import urllib.request -else: - import imp - import urllib2 - urllib = imp.new_module('urllib') - urllib.request = urllib2 +import urllib.request try: import kerberos @@ -68,8 +60,6 @@ from wrapper import WrapperPath, Wrapper from subcmds import all_commands -if not is_python3(): - input = raw_input # noqa: F821 # NB: These do not need to be kept in sync with the repo launcher script. # These may be much newer as it allows the repo launcher to roll between diff --git a/manifest_xml.py b/manifest_xml.py index bbecb934..9b7a81b3 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -17,15 +17,7 @@ import os import re import sys import xml.dom.minidom - -from pyversion import is_python3 -if is_python3(): - import urllib.parse -else: - import imp - import urlparse - urllib = imp.new_module('urllib') - urllib.parse = urlparse +import urllib.parse import gitc_utils from git_config import GitConfig, IsId diff --git a/platform_utils.py b/platform_utils.py index 6dd3385d..a280982a 100644 --- a/platform_utils.py +++ b/platform_utils.py @@ -15,16 +15,10 @@ import errno import os import platform +from queue import Queue import select import shutil import stat - -from pyversion import is_python3 -if is_python3(): - from queue import Queue -else: - from Queue import Queue - from threading import Thread diff --git a/platform_utils_win32.py b/platform_utils_win32.py index 26c8ad42..bf916d47 100644 --- a/platform_utils_win32.py +++ b/platform_utils_win32.py @@ -14,18 +14,10 @@ import errno -from pyversion import is_python3 from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof -from ctypes import c_buffer +from ctypes import c_buffer, c_ubyte, Structure, Union, byref from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE -from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG -if is_python3(): - from ctypes import c_ubyte, Structure, Union, byref - from ctypes.wintypes import LPDWORD -else: - # For legacy Python2 different imports are needed. - from ctypes.wintypes import POINTER, c_ubyte, Structure, Union, byref - LPDWORD = POINTER(DWORD) +from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG, LPDWORD kernel32 = WinDLL('kernel32', use_last_error=True) @@ -202,26 +194,15 @@ def readlink(path): 'Error reading symbolic link \"%s\"'.format(path)) rdb = REPARSE_DATA_BUFFER.from_buffer(target_buffer) if rdb.ReparseTag == IO_REPARSE_TAG_SYMLINK: - return _preserve_encoding(path, rdb.SymbolicLinkReparseBuffer.PrintName) + return rdb.SymbolicLinkReparseBuffer.PrintName elif rdb.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT: - return _preserve_encoding(path, rdb.MountPointReparseBuffer.PrintName) + return rdb.MountPointReparseBuffer.PrintName # Unsupported reparse point type _raise_winerror( ERROR_NOT_SUPPORTED, 'Error reading symbolic link \"%s\"'.format(path)) -def _preserve_encoding(source, target): - """Ensures target is the same string type (i.e. unicode or str) as source.""" - - if is_python3(): - return target - - if isinstance(source, unicode): # noqa: F821 - return unicode(target) # noqa: F821 - return str(target) - - def _raise_winerror(code, error_desc): win_error_desc = FormatError(code).strip() error_desc = "%s: %s".format(error_desc, win_error_desc) diff --git a/project.py b/project.py index a9bca6db..6c6534d8 100644 --- a/project.py +++ b/project.py @@ -25,6 +25,7 @@ import sys import tarfile import tempfile import time +import urllib.parse from color import Coloring from git_command import GitCommand, git_require @@ -39,16 +40,6 @@ from repo_trace import IsTrace, Trace from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M -from pyversion import is_python3 -if is_python3(): - import urllib.parse -else: - import imp - import urlparse - urllib = imp.new_module('urllib') - urllib.parse = urlparse - input = raw_input # noqa: F821 - # Maximum sleep time allowed during retries. MAXIMUM_RETRY_SLEEP_SEC = 3600.0 diff --git a/pyversion.py b/pyversion.py deleted file mode 100644 index a0cbf777..00000000 --- a/pyversion.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2013 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import sys - - -def is_python3(): - return sys.version_info[0] == 3 diff --git a/subcmds/gitc_delete.py b/subcmds/gitc_delete.py index c6f02607..56e0eaba 100644 --- a/subcmds/gitc_delete.py +++ b/subcmds/gitc_delete.py @@ -17,10 +17,6 @@ import sys from command import Command, GitcClientCommand import platform_utils -from pyversion import is_python3 -if not is_python3(): - input = raw_input # noqa: F821 - class GitcDelete(Command, GitcClientCommand): common = True diff --git a/subcmds/init.py b/subcmds/init.py index e078fcbe..1bcf5463 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -17,15 +17,7 @@ import os import platform import re import sys - -from pyversion import is_python3 -if is_python3(): - import urllib.parse -else: - import imp - import urlparse - urllib = imp.new_module('urllib') - urllib.parse = urlparse +import urllib.parse from color import Coloring from command import InteractiveCommand, MirrorSafeCommand diff --git a/subcmds/sync.py b/subcmds/sync.py index 1e1f2fc1..3482946d 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import http.cookiejar as cookielib import json import netrc from optparse import SUPPRESS_HELP @@ -22,26 +23,10 @@ import subprocess import sys import tempfile import time - -from pyversion import is_python3 -if is_python3(): - import http.cookiejar as cookielib - import urllib.error - import urllib.parse - import urllib.request - import xmlrpc.client -else: - import cookielib - import imp - import urllib2 - import urlparse - import xmlrpclib - urllib = imp.new_module('urllib') - urllib.error = urllib2 - urllib.parse = urlparse - urllib.request = urllib2 - xmlrpc = imp.new_module('xmlrpc') - xmlrpc.client = xmlrpclib +import urllib.error +import urllib.parse +import urllib.request +import xmlrpc.client try: import threading as _threading diff --git a/subcmds/upload.py b/subcmds/upload.py index c189e65f..50dccc52 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -23,11 +23,6 @@ from git_command import GitCommand from git_refs import R_HEADS from hooks import RepoHook -from pyversion import is_python3 -if not is_python3(): - input = raw_input # noqa: F821 -else: - unicode = str UNUSUAL_COMMIT_THRESHOLD = 5 diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 5e2cfa57..d8713738 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -15,27 +15,20 @@ """Unittests for the wrapper.py module.""" import contextlib +from io import StringIO import os import re import shutil import tempfile import unittest +from unittest import mock import git_command import main import platform_utils -from pyversion import is_python3 import wrapper -if is_python3(): - from unittest import mock - from io import StringIO -else: - import mock - from StringIO import StringIO - - @contextlib.contextmanager def TemporaryDirectory(): """Create a new empty git checkout for testing.""" @@ -62,9 +55,6 @@ class RepoWrapperTestCase(unittest.TestCase): wrapper._wrapper_module = None self.wrapper = wrapper.Wrapper() - if not is_python3(): - self.assertRegex = self.assertRegexpMatches - class RepoWrapperUnitTest(RepoWrapperTestCase): """Tests helper functions in the repo wrapper