Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
caryoscelus committed Jul 29, 2023
1 parent e79924d commit b358435
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,44 +195,6 @@ def mergeDicts(dicts):
return dict(back)


# Request https url using gevent SSL error workaround
def httpRequest(url, as_file=False):
if url.startswith("http://"):
import urllib.request
response = urllib.request.urlopen(url)
else: # Hack to avoid Python gevent ssl errors
import socket
import http.client
import ssl

host, request = re.match("https://(.*?)(/.*?)$", url).groups()

conn = http.client.HTTPSConnection(host)
sock = socket.create_connection((conn.host, conn.port), conn.timeout, conn.source_address)

context = ssl.create_default_context()
context.minimum_version = ssl.TLSVersion.TLSv1_2

conn.sock = context.wrap_socket(sock, conn.key_file, conn.cert_file)
conn.request("GET", request)
response = conn.getresponse()
if response.status in [301, 302, 303, 307, 308]:
logging.info("Redirect to: %s" % response.getheader('Location'))
response = httpRequest(response.getheader('Location'))

if as_file:
import io
data = io.BytesIO()
while True:
buff = response.read(1024 * 16)
if not buff:
break
data.write(buff)
return data
else:
return response


def timerCaller(secs, func, *args, **kwargs):
gevent.spawn_later(secs, timerCaller, secs, func, *args, **kwargs)
func(*args, **kwargs)
Expand Down

0 comments on commit b358435

Please sign in to comment.