mirror of
https://github.com/wavetermdev/homebrew-cask.git
synced 2026-08-05 13:43:24 -07:00
Use print() function in both Python 2 and Python 3 (#64852)
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import cgi
|
||||
import urllib2
|
||||
try: # Python 3
|
||||
from urllib.request import Request, urlopen
|
||||
except NameError: # Python 2
|
||||
from urllib2 import Request, urlopen
|
||||
|
||||
|
||||
url = sys.argv[1]
|
||||
@@ -12,8 +16,8 @@ if len(sys.argv) > 2:
|
||||
|
||||
|
||||
try:
|
||||
req = urllib2.Request(url, None, headers)
|
||||
response = urllib2.urlopen(req)
|
||||
req = Request(url, None, headers)
|
||||
response = urlopen(req)
|
||||
_, params = cgi.parse_header(
|
||||
response.headers.get('Content-Disposition', ''))
|
||||
filename = params['filename']
|
||||
@@ -21,4 +25,4 @@ except Exception:
|
||||
import traceback
|
||||
filename = 'generic exception: ' + traceback.format_exc()
|
||||
|
||||
print filename
|
||||
print(filename)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import cgi
|
||||
import urllib2
|
||||
try: # Python 3
|
||||
from urllib.request import Request, urlopen
|
||||
except NameError: # Python 2
|
||||
from urllib2 import Request, urlopen
|
||||
|
||||
|
||||
url = sys.argv[1]
|
||||
@@ -11,11 +15,11 @@ if len(sys.argv) > 2:
|
||||
headers = {'User-Agent': ua}
|
||||
|
||||
try:
|
||||
req = urllib2.Request(url, None, headers)
|
||||
response = urllib2.urlopen(req)
|
||||
req = Request(url, None, headers)
|
||||
response = urlopen(req)
|
||||
redir = response.geturl()
|
||||
except Exception:
|
||||
import traceback
|
||||
redir = 'generic exception: ' + traceback.format_exc()
|
||||
|
||||
print redir
|
||||
print(redir)
|
||||
|
||||
Reference in New Issue
Block a user