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>
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 8fb9488..b34787d 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -24,22 +24,17 @@
import subprocess
import sys
import time
-try:
- # For python3
+
+from pyversion import is_python3
+if is_python3():
import urllib.parse
-except ImportError:
- # For python2
+ import xmlrpc.client
+else:
import imp
import urlparse
+ import xmlrpclib
urllib = imp.new_module('urllib')
urllib.parse = urlparse
-try:
- # For python3
- import xmlrpc.client
-except ImportError:
- # For python2
- import imp
- import xmlrpclib
xmlrpc = imp.new_module('xmlrpc')
xmlrpc.client = xmlrpclib