Philipp Hörist pushed to branch soup3 at gajim / python-nbxmpp
Commits: 5c75d08a by Philipp Hörist at 2022-12-13T16:07:25+01:00 fix: Create Temp File
- - - - -
2 changed files:
- nbxmpp/http.py - test/unit/test_http.py
Changes:
===================================== nbxmpp/http.py ===================================== @@ -40,8 +40,6 @@ log = logging.getLogger('nbxmpp.http') HTTP_METHODS_T = Literal['GET', 'POST'] CHUNK_SIZE = 32768 DEFAULT_USER_AGENT = f'nbxmpp/{nbxmpp.__version__}' - - SIGNAL_ACTIONS = GObject.SignalFlags.RUN_LAST | GObject.SignalFlags.ACTION
@@ -51,10 +49,17 @@ class HTTPLogAdapter(logging.LoggerAdapter):
class HTTPSession: - def __init__(self, user_agent: str = DEFAULT_USER_AGENT) -> None: + def __init__(self, + user_agent: str = DEFAULT_USER_AGENT, + sniffer: bool = False + ) -> None: + self._session = Soup.Session() self._session.set_user_agent(user_agent)
+ if sniffer: + self._session.add_feature_by_type(Soup.ContentSniffer) + self._requests: list[HTTPRequest] = []
def get_soup_session(self) -> Soup.Session: @@ -189,7 +194,7 @@ class HTTPRequest(GObject.GObject): self._request_content_type = content_type self._request_content_length = len(data)
- def set_response_body_path(self, path: Path) -> None: + def set_response_body_from_path(self, path: Path) -> None: self._response_body_file = Gio.File.new_for_path(str(path))
def connect(self, @@ -233,6 +238,7 @@ class HTTPRequest(GObject.GObject): uri_string: str, timeout: Optional[int] = None, callback: Optional[Callable[[HTTPRequest], Any]] = None, + user_data: Optional[Any] = None ) -> None:
if callback is not None:
===================================== test/unit/test_http.py ===================================== @@ -1,4 +1,5 @@ from time import time +import tempfile import unittest from unittest.mock import call from unittest.mock import Mock @@ -37,7 +38,7 @@ class HTTP(unittest.TestCase): def tearDownClass(cls): pass
- def test_in_memory_download_to_file(self): + def test_download_to_file(self):
mainloop = GLib.MainLoop()
@@ -46,8 +47,8 @@ class HTTP(unittest.TestCase):
callback_mock = Mock()
- request.set_response_body_path( - Path('/home/lovetox/Downloads/test123')) + temp_dir = tempfile.gettempdir() + request.set_response_body_from_path(Path(temp_dir) / 'file') request.connect('response-progress', callback_mock.progress) request.connect('starting-response-body', callback_mock.starting) request.connect('finished', callback_mock.finished)
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/commit/5c75d08a2334a9b6dc1796359...