Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly close 'file://' resources #1393

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/zeep/transports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from contextlib import contextmanager
from contextlib import contextmanager, closing
from urllib.parse import urlparse

import requests
Expand Down Expand Up @@ -114,7 +114,6 @@ def load(self, url):

scheme = urlparse(url).scheme
if scheme in ("http", "https", "file"):

if self.cache:
response = self.cache.get(url)
if response:
Expand All @@ -133,8 +132,9 @@ def load(self, url):
def _load_remote_data(self, url):
self.logger.debug("Loading remote data from: %s", url)
response = self.session.get(url, timeout=self.load_timeout)
response.raise_for_status()
return response.content
with closing(response):
response.raise_for_status()
return response.content

@contextmanager
def settings(self, timeout=None):
Expand Down
1 change: 1 addition & 0 deletions tests/test_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_load_file_unix():
result = transport.load("file:///usr/local/bin/example.wsdl")
assert result == b"x"
m_open.assert_called_once_with("/usr/local/bin/example.wsdl", "rb")
m_open.return_value.close.assert_called()


@pytest.mark.skipif(os.name != "nt", reason="test valid for windows platform only")
Expand Down