Browse Source

Improve python2 support.

master
poikilos 3 years ago
parent
commit
f136354107
  1. 15
      utilities/enissue.py

15
utilities/enissue.py

@ -4,13 +4,14 @@ import sys
import json import json
import os import os
from datetime import datetime, timedelta from datetime import datetime, timedelta
python_mr = sys.version_info.major
try: try:
import urllib.request import urllib.request
request = urllib.request request = urllib.request
except ImportError: except ImportError:
# python2 # python2
python_mr = 2 # python_mr = 2
print("* detected Python " + str(python_mr))
import urllib2 as urllib import urllib2 as urllib
request = urllib request = urllib
@ -20,15 +21,17 @@ try:
from urllib.parse import urlencode from urllib.parse import urlencode
from urllib.parse import quote from urllib.parse import quote
from urllib.parse import unquote from urllib.parse import unquote
from urllib.error import HTTPError
except ImportError: except ImportError:
# Python 2 # Python 2
# See <https://docs.python.org/2/howto/urllib2.html>
from urlparse import urlparse from urlparse import urlparse
# from urlparse import quote_plus # from urlparse import quote_plus
from urllib import urlencode from urllib import urlencode
from urllib import quote from urllib import quote
from urllib import unquote from urllib import unquote
from urllib2 import HTTPError
import urllib # ^ urllib.error.HTTPError doesn't exist in Python 2
# see <https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python> # see <https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python>
@ -306,7 +309,7 @@ class Repo:
try: try:
debug(p+"Query URL (query_s): {}".format(query_s)) debug(p+"Query URL (query_s): {}".format(query_s))
response = request.urlopen(query_s) response = request.urlopen(query_s)
except urllib.error.HTTPError as e: except HTTPError as e:
print(p+"You may be able to view the issues on GitHub") print(p+"You may be able to view the issues on GitHub")
print(p+"at the 'html_url', and a login may be required.") print(p+"at the 'html_url', and a login may be required.")
print(p+"The URL \"{}\" is not accessible, so you may have" print(p+"The URL \"{}\" is not accessible, so you may have"
@ -345,7 +348,7 @@ class Repo:
try: try:
response = request.urlopen(this_issue_json_url) response = request.urlopen(this_issue_json_url)
issue_data_bytes = response.read() issue_data_bytes = response.read()
except urllib.error.HTTPError as e: except HTTPError as e:
print(str(e)) print(str(e))
print(p+"The URL \"{}\" is not accessible, so you may have" print(p+"The URL \"{}\" is not accessible, so you may have"
" exceeded the rate limit and be blocked" " exceeded the rate limit and be blocked"

Loading…
Cancel
Save