Compare commits

..

No commits in common. "fe582c84b94f1c60fdc3e9d054052e2c1a77bcf9" and "847223cdcee6e2339fa4c9a77296c579a4562fcd" have entirely different histories.

2 changed files with 57 additions and 90 deletions

View File

@ -3,14 +3,6 @@ History
-------
11.0.5 (2022-04-29)
++++++++++++++++++
- Bugfix to not overwrite global urlopener in embedded Python.
`#110 <https://github.com/wakatime/sublime-wakatime/issues/110>`_
- Chmod wakatime-cli to be executable after updating on non-Windows platforms.
11.0.4 (2022-01-06)
++++++++++++++++++

View File

@ -8,7 +8,7 @@ Website: https://wakatime.com/
==========================================================="""
__version__ = '11.0.5'
__version__ = '11.0.4'
import sublime
@ -40,9 +40,9 @@ try:
except ImportError:
from configparser import ConfigParser, Error as ConfigParserError
try:
from urllib2 import Request, urlopen, HTTPError
from urllib2 import urlopen, urlretrieve, ProxyHandler, build_opener, install_opener, HTTPError
except ImportError:
from urllib.request import Request, urlopen
from urllib.request import urlopen, urlretrieve, ProxyHandler, build_opener, install_opener
from urllib.error import HTTPError
@ -847,98 +847,83 @@ def reportMissingPlatformSupport(osname, arch):
def request(url, last_modified=None):
req = Request(url)
req.add_header('User-Agent', 'github.com/wakatime/sublime-wakatime')
proxy = SETTINGS.get('proxy')
if proxy:
req.set_proxy(proxy, 'https')
opener = build_opener(ProxyHandler({
'http': proxy,
'https': proxy,
}))
else:
opener = build_opener()
headers = [('User-Agent', 'github.com/wakatime/sublime-wakatime')]
if last_modified:
req.add_header('If-Modified-Since', last_modified)
headers.append(('If-Modified-Since', last_modified))
opener.addheaders = headers
install_opener(opener)
try:
resp = urlopen(req)
resp = urlopen(url)
headers = dict(resp.getheaders()) if is_py2 else resp.headers
return headers, resp.read(), resp.getcode()
except HTTPError as err:
if err.code == 304:
return None, None, 304
if is_py2:
with SSLCertVerificationDisabled():
try:
resp = urlopen(req)
headers = dict(resp.getheaders()) if is_py2 else resp.headers
return headers, resp.read(), resp.getcode()
except HTTPError as err2:
if err2.code == 304:
return None, None, 304
log(DEBUG, err.read().decode())
log(DEBUG, err2.read().decode())
raise
except IOError:
raise
ssl._create_default_https_context = ssl._create_unverified_context
try:
resp = urlopen(url)
headers = dict(resp.getheaders()) if is_py2 else resp.headers
return headers, resp.read(), resp.getcode()
except HTTPError as err2:
if err2.code == 304:
return None, None, 304
log(DEBUG, err.read().decode())
log(DEBUG, err2.read().decode())
raise
except IOError:
raise
log(DEBUG, err.read().decode())
raise
except IOError:
if is_py2:
with SSLCertVerificationDisabled():
try:
resp = urlopen(url)
headers = dict(resp.getheaders()) if is_py2 else resp.headers
return headers, resp.read(), resp.getcode()
except HTTPError as err:
if err.code == 304:
return None, None, 304
log(DEBUG, err.read().decode())
raise
except IOError:
raise
ssl._create_default_https_context = ssl._create_unverified_context
try:
resp = urlopen(url)
headers = dict(resp.getheaders()) if is_py2 else resp.headers
return headers, resp.read(), resp.getcode()
except HTTPError as err:
if err.code == 304:
return None, None, 304
log(DEBUG, err.read().decode())
raise
except IOError:
raise
raise
def download(url, filePath):
req = Request(url)
req.add_header('User-Agent', 'github.com/wakatime/sublime-wakatime')
proxy = SETTINGS.get('proxy')
if proxy:
req.set_proxy(proxy, 'https')
opener = build_opener(ProxyHandler({
'http': proxy,
'https': proxy,
}))
else:
opener = build_opener()
opener.addheaders = [('User-Agent', 'github.com/wakatime/sublime-wakatime')]
with open(filePath, 'wb') as fh:
try:
resp = urlopen(req)
fh.write(resp.read())
except HTTPError as err:
if err.code == 304:
return None, None, 304
if is_py2:
with SSLCertVerificationDisabled():
try:
resp = urlopen(req)
fh.write(resp.read())
return
except HTTPError as err2:
log(DEBUG, err.read().decode())
log(DEBUG, err2.read().decode())
raise
except IOError:
raise
log(DEBUG, err.read().decode())
raise
except IOError:
if is_py2:
with SSLCertVerificationDisabled():
try:
resp = urlopen(url)
fh.write(resp.read())
return
except HTTPError as err:
log(DEBUG, err.read().decode())
raise
except IOError:
raise
raise
install_opener(opener)
try:
urlretrieve(url, filePath)
except IOError:
if is_py2:
ssl._create_default_https_context = ssl._create_unverified_context
urlretrieve(url, filePath)
raise
def is_symlink(path):
@ -964,13 +949,3 @@ def createSymlink():
os.chmod(link, 509) # 755
except:
log(traceback.format_exc())
class SSLCertVerificationDisabled(object):
def __enter__(self):
self.original_context = ssl._create_default_https_context
ssl._create_default_https_context = ssl._create_unverified_context
def __exit__(self, *args, **kwargs):
ssl._create_default_https_context = self.original_context