3232 py='python'
3333elif command -v python3 &> /dev/null; then
3434 py='python3'
35- elif command -v python2 &> /dev/null; then
36- py='python2'
3735fi
3836/usr/bin/env $py << EOF
3937
6361import shlex
6462from uuid import uuid1
6563
66- try:
67- # For Python 3.0 and later
68- from urllib.request import urlopen, HTTPError, URLError
69- from urllib.parse import urlencode
70- except ImportError:
71- # Fall back to Python 2's urllib2
72- from urllib2 import urlopen, HTTPError, URLError
73- from urllib import urlencode
64+ from urllib.request import urlopen, HTTPError, URLError
65+ from urllib.parse import urlencode
7466
7567try:
7668 from cStringIO import StringIO
@@ -93,10 +85,7 @@ def formatTime(self, record, datefmt=None):
9385# formatter = logging.Formatter(fmt='%%(asctime)s UTC %%(levelname)-8s %%(message)s', datefmt='%%Y-%%m-%%d %%H:%%M:%%S')
9486formatter = MicrosecondFormatter('%%(asctime)s %%(levelname)-8s [%%(name)s] %%(message)s')
9587logging.Formatter.converter = time.gmtime
96- try:
97- screen_handler = logging.StreamHandler(stream=sys.stdout)
98- except TypeError: # python2.6
99- screen_handler = logging.StreamHandler(strm=sys.stdout)
88+ screen_handler = logging.StreamHandler(stream=sys.stdout)
10089screen_handler.setFormatter(formatter)
10190
10291# add a string buffer handler
@@ -276,28 +265,15 @@ def pilotWrapperScript(
276265 # Getting the json, tar, and checksum file
277266 try:
278267
279- # urllib is different between python 2 and 3
280- if sys.version_info < (3,):
281- from urllib2 import urlopen as url_library_urlopen
282- from urllib2 import URLError as url_library_URLError
283- else:
284- from urllib.request import urlopen as url_library_urlopen
285- from urllib.error import URLError as url_library_URLError
268+ from urllib.request import urlopen
269+ from urllib.error import URLError
286270
287271 for fileName in ['checksums.sha512', 'pilot.json', 'pilot.tar']:
288- # needs to distinguish whether urlopen method contains the 'context' param
289- # in theory, it should be available from python 2.7.9
290- # in practice, some prior versions may be composed of recent urllib version containing the param
291- if 'context' in url_library_urlopen.__code__.co_varnames:
292- import ssl
293- context = ssl._create_unverified_context()
294- remoteFile = url_library_urlopen(os.path.join(loc, fileName),
295- timeout=10,
296- context=context)
297-
298- else:
299- remoteFile = url_library_urlopen(os.path.join(loc, fileName),
300- timeout=10)
272+ import ssl
273+ context = ssl._create_unverified_context()
274+ remoteFile = urlopen(os.path.join(loc, fileName),
275+ timeout=10,
276+ context=context)
301277
302278 localFile = open(fileName, 'wb')
303279 localFile.write(remoteFile.read())
@@ -320,7 +296,7 @@ def pilotWrapperScript(
320296 raise
321297 # if we get here we break out of the loop of locations
322298 break
323- except (url_library_URLError , Exception) as e:
299+ except (URLError , Exception) as e:
324300 print('%%s unreacheable (this is normal!)' %% loc, file=sys.stderr)
325301 logger.error('%%s unreacheable (this is normal!)' %% loc)
326302 logger.exception(e)
0 commit comments