commit 67b3ad36de59cd1f831b00a7f0a8c116b0c02b4f Author: Shivaram Lingamneni Date: Mon Nov 9 17:27:24 2020 -0500 remove dependency on python3-requests diff --git a/apport/fileutils.py b/apport/fileutils.py index 98ff9f46..e1b1bea2 100644 --- a/apport/fileutils.py +++ b/apport/fileutils.py @@ -9,7 +9,7 @@ # option) any later version. See http://www.gnu.org/copyleft/gpl.html for # the full text of the license. -import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket +import json, os, glob, subprocess, os.path, time, pwd, sys try: from configparser import ConfigParser, NoOptionError, NoSectionError @@ -22,6 +22,8 @@ from problem_report import ProblemReport from apport.packaging_impl import impl as packaging +from .http_unixdomain import unix_http_request + report_dir = os.environ.get('APPORT_REPORT_DIR', '/var/crash') _config_file = '~/.config/apport/settings' @@ -109,12 +111,10 @@ def find_snap(snap): Return None if the snap is not found to be installed. ''' - session = requests_unixsocket.Session() try: - r = session.get('http+unix://%2Frun%2Fsnapd.socket/v2/snaps/{}'.format(snap)) - if r.status_code == 200: - j = r.json() - return j["result"] + code, response = unix_http_request('GET', 'http+unix://%2Frun%2Fsnapd.socket/v2/snaps/{}'.format(snap)) + if code == 200: + return json.loads(response)['result'] except Exception: return None diff --git a/apport/http_unixdomain.py b/apport/http_unixdomain.py new file mode 100644 index 00000000..767a9f4b --- /dev/null +++ b/apport/http_unixdomain.py @@ -0,0 +1,43 @@ +import socket +import http.client +from urllib.parse import unquote, urlencode, urlparse + +# UnixHTTPConnection is from https://github.com/msabramo/requests-unixsocket +# which is released under the Apache License 2.0 +class UnixHTTPConnection(http.client.HTTPConnection, object): + + def __init__(self, unix_socket_url, timeout=60): + """Create an HTTP connection to a unix domain socket + + :param unix_socket_url: A URL with a scheme of 'http+unix' and the + netloc is a percent-encoded path to a unix domain socket. E.g.: + 'http+unix://%2Ftmp%2Fprofilesvc.sock/status/pid' + """ + super(UnixHTTPConnection, self).__init__('localhost', timeout=timeout) + self.unix_socket_url = unix_socket_url + self.timeout = timeout + self.sock = None + + def __del__(self): # base class does not have d'tor + if self.sock: + self.sock.close() + + def connect(self): + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.settimeout(self.timeout) + socket_path = unquote(urlparse(self.unix_socket_url).netloc) + sock.connect(socket_path) + self.sock = sock + +def unix_http_request(verb, url, params=None): + parsed_url = urlparse(url) + conn = UnixHTTPConnection(url) + try: + path = parsed_url.path + if params is not None: + path = '%s?%s' % (parsed_url.path, urlencode(params)) + conn.request(verb.upper(), path) + response = conn.getresponse() + return response.status, response.read() + finally: + conn.close() diff --git a/debian/control b/debian/control index f9d0162b..ffd9057e 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,6 @@ Build-Depends: debhelper (>= 9), python3-all Build-Depends-Indep: python3-distutils-extra (>= 2.24~), python3-apt (>= 0.7.9), - python3-requests-unixsocket, dh-python, intltool, xvfb, @@ -78,7 +77,6 @@ Depends: ${python3:Depends}, python3-apt (>= 0.7.9), python3-httplib2, python3-problem-report (>= 0.94), - python3-requests-unixsocket, lsb-release, python3-launchpadlib, ${misc:Depends}