commit 101a2beb279455a739141586674482b0f2d83594 Author: Shivaram Lingamneni Date: Tue Feb 9 12:07:45 2021 -0500 remove dependency on python3-requests diff --git a/apport/fileutils.py b/apport/fileutils.py index d2831968..534e03d7 100644 --- a/apport/fileutils.py +++ b/apport/fileutils.py @@ -9,8 +9,9 @@ # 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 stat +import os, glob, subprocess, os.path, time, pwd, sys, stat, json, socket +import http.client +from contextlib import closing try: from configparser import (ConfigParser, NoOptionError, NoSectionError, @@ -29,6 +30,22 @@ report_dir = os.environ.get('APPORT_REPORT_DIR', '/var/crash') _config_file = '~/.config/apport/settings' +SNAPD_SOCKET = '/run/snapd.socket' + +# UHTTPConnection is based on code from the UpdateManager package: +# Copyright (c) 2017 Canonical +# Author: Andrea Azzarone +class UHTTPConnection(http.client.HTTPConnection, object): + + def __init__(self, path): + http.client.HTTPConnection.__init__(self, 'localhost') + self.path = path + + def connect(self): + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(self.path) + self.sock = sock + def allowed_to_report(): '''Check whether crash reporting is enabled.''' @@ -112,12 +129,13 @@ 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"] + with closing(UHTTPConnection(SNAPD_SOCKET)) as c: + url = f'/v2/snaps/{snap}' + c.request('GET', url) + response = c.getresponse() + if response.status == 200: + return json.loads(response.read())['result'] except Exception: return None diff --git a/debian/control b/debian/control index d277d6e8..8ccf537c 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}