Import http stuff when needed

This makes startup faster
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2020-09-19 11:36:50 +02:00
parent 9273fc7f50
commit 07e54acc49
No known key found for this signature in database
GPG Key ID: B3A7CF0C801886CF

View File

@ -18,8 +18,6 @@
# #
# Stuff non-related to relational algebra, but used for maintenance. # Stuff non-related to relational algebra, but used for maintenance.
import http.client
import urllib.parse
import os.path import os.path
import pickle import pickle
import base64 import base64
@ -39,6 +37,8 @@ def send_survey(data) -> int:
returns 0 in case of error returns 0 in case of error
returns -1 in case of swearwords''' returns -1 in case of swearwords'''
import urllib.parse
from http.client import HTTPConnection
post = '' post = ''
for i in data.keys(): for i in data.keys():
@ -53,7 +53,7 @@ def send_survey(data) -> int:
params = urllib.parse.urlencode({'survey': post}) params = urllib.parse.urlencode({'survey': post})
headers = {"Content-type": headers = {"Content-type":
"application/x-www-form-urlencoded", "Accept": "text/plain"} "application/x-www-form-urlencoded", "Accept": "text/plain"}
connection = http.client.HTTPConnection('feedback-ltworf.appspot.com') connection = HTTPConnection('feedback-ltworf.appspot.com')
try: try:
connection.request("POST", "/feedback/relational", params, headers) connection.request("POST", "/feedback/relational", params, headers)
return connection.getresponse().status return connection.getresponse().status
@ -65,7 +65,8 @@ def check_latest_version() -> Optional[str]:
'''Returns the latest version available. '''Returns the latest version available.
Heavely dependent on server and server configurations Heavely dependent on server and server configurations
not granted to work forever.''' not granted to work forever.'''
connection = http.client.HTTPConnection('feedback-ltworf.appspot.com') from http.client import HTTPConnection
connection = HTTPConnection('feedback-ltworf.appspot.com')
try: try:
connection.request("GET", "/version/relational") connection.request("GET", "/version/relational")
r = connection.getresponse() r = connection.getresponse()