Move Python version checking to a separate module

Add a new module with methods for checking the Python version.

Instead of handling Python3 imports with try...except blocks, first
check the python version and then import the relevant modules.  This
makes the code a bit cleaner and will result in less diff when/if we
remove support for Python < 3 later.

Use the same mechanism to handle `input` vs. `raw_input` and add
suppression of pylint warnings caused by redefinition of the built-in
method `input`.

Change-Id: Ia403e525b88d77640a741ac50382146e7d635924
Also-by: Chirayu Desai <cdesai@cyanogenmod.org>
Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
This commit is contained in:
David Pursehouse
2013-05-17 10:49:33 +09:00
parent da45e5d884
commit 59bbb580e3
10 changed files with 62 additions and 49 deletions

8
repo
View File

@@ -117,15 +117,13 @@ import re
import stat
import subprocess
import sys
try:
import urllib2
except ImportError:
# For python3
if sys.version_info[0] == 3:
import urllib.request
import urllib.error
else:
# For python2
import imp
import urllib2
urllib = imp.new_module('urllib')
urllib.request = urllib2
urllib.error = urllib2