Use six for cross python compatibility
- Fixes linting error related to undefined unicode on python3. - Simplifies code Change-Id: Ib40237e0fb7156b084dfdab47be69ccad09547fe
This commit is contained in:
parent
c243d80af9
commit
d181f04353
@ -24,30 +24,19 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
|
import six
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import requests
|
import requests
|
||||||
|
from six.moves import configparser
|
||||||
|
from six.moves import input as do_input
|
||||||
|
from six.moves.urllib.parse import urlencode
|
||||||
|
from six.moves.urllib.parse import urljoin
|
||||||
|
from six.moves.urllib.parse import urlparse
|
||||||
|
|
||||||
if sys.version < '3':
|
|
||||||
import ConfigParser
|
|
||||||
import urllib
|
|
||||||
import urlparse
|
|
||||||
urlencode = urllib.urlencode
|
|
||||||
urljoin = urlparse.urljoin
|
|
||||||
urlparse = urlparse.urlparse
|
|
||||||
do_input = raw_input
|
|
||||||
else:
|
|
||||||
import configparser as ConfigParser
|
|
||||||
|
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
urlencode = urllib.parse.urlencode
|
|
||||||
urljoin = urllib.parse.urljoin
|
|
||||||
urlparse = urllib.parse.urlparse
|
|
||||||
do_input = input
|
|
||||||
|
|
||||||
VERBOSE = False
|
VERBOSE = False
|
||||||
UPDATE = False
|
UPDATE = False
|
||||||
@ -133,7 +122,7 @@ def run_command_status(*argv, **kwargs):
|
|||||||
print(datetime.datetime.now(), "Running:", " ".join(argv))
|
print(datetime.datetime.now(), "Running:", " ".join(argv))
|
||||||
if len(argv) == 1:
|
if len(argv) == 1:
|
||||||
# for python2 compatibility with shlex
|
# for python2 compatibility with shlex
|
||||||
if sys.version_info < (3,) and isinstance(argv[0], unicode):
|
if sys.version_info < (3,) and isinstance(argv[0], six.text_type):
|
||||||
argv = shlex.split(argv[0].encode('utf-8'))
|
argv = shlex.split(argv[0].encode('utf-8'))
|
||||||
else:
|
else:
|
||||||
argv = shlex.split(str(argv[0]))
|
argv = shlex.split(str(argv[0]))
|
||||||
@ -703,7 +692,7 @@ def check_color_support():
|
|||||||
|
|
||||||
def load_config_file(config_file):
|
def load_config_file(config_file):
|
||||||
"""Load configuration options from a file."""
|
"""Load configuration options from a file."""
|
||||||
configParser = ConfigParser.ConfigParser()
|
configParser = configparser.ConfigParser()
|
||||||
configParser.read(config_file)
|
configParser.read(config_file)
|
||||||
options = {
|
options = {
|
||||||
'scheme': 'scheme',
|
'scheme': 'scheme',
|
||||||
|
@ -1 +1,2 @@
|
|||||||
requests>=1.1
|
requests>=1.1
|
||||||
|
six
|
||||||
|
Loading…
x
Reference in New Issue
Block a user