diff -Nru requests-file-1.4.3/CHANGES.rst requests-file-1.5.1/CHANGES.rst --- requests-file-1.4.3/CHANGES.rst 2018-01-02 21:14:12.000000000 +0000 +++ requests-file-1.5.1/CHANGES.rst 2020-04-25 13:52:35.000000000 +0000 @@ -1,3 +1,14 @@ +1.5.1 (25 Apr 2020) +=================== +- Fix python 2.7 compatibility +- Rename test file for pytest +- Add tests via github actions +- Format code with black + +1.5.0 (23 Apr 2020) +================== +- Add set_content_length flag to disable on demand setting Content-Length + 1.4.3 (2 Jan 2018) ================== - Skip the permissions test when running as root diff -Nru requests-file-1.4.3/debian/changelog requests-file-1.5.1/debian/changelog --- requests-file-1.4.3/debian/changelog 2019-09-03 15:33:44.000000000 +0000 +++ requests-file-1.5.1/debian/changelog 2020-04-27 16:18:08.000000000 +0000 @@ -1,3 +1,16 @@ +requests-file (1.5.1-1) unstable; urgency=medium + + [ Ondřej Nový ] + * d/control: Remove ancient X-Python-Version field + * d/control: Remove ancient X-Python3-Version field + * d/copyright: Use https protocol in Format field + * d/control: Set Vcs-* to salsa.debian.org + + [ Antoine Beaupré ] + * new upstream release + + -- Antoine Beaupré Mon, 27 Apr 2020 12:18:08 -0400 + requests-file (1.4.3-2) unstable; urgency=medium * drop Python 2 support (Closes: #938356) diff -Nru requests-file-1.4.3/debian/control requests-file-1.5.1/debian/control --- requests-file-1.4.3/debian/control 2019-09-03 15:33:44.000000000 +0000 +++ requests-file-1.5.1/debian/control 2020-04-27 16:18:08.000000000 +0000 @@ -2,17 +2,17 @@ Section: python Priority: optional Maintainer: Antoine Beaupré -Build-Depends: debhelper (>= 10), dh-python, +Build-Depends: debhelper (>= 10), + dh-python, python3-all, + python3-pytest, python3-setuptools, python3-requests, - python3-six + python3-six, Standards-Version: 4.1.1 -X-Python-Version: >= 2.7 -X-Python3-Version: >= 3.4 Homepage: http://github.com/dashea/requests-file -Vcs-Git: https://anonscm.debian.org/git/collab-maint/requests-file.git -Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/requests-file.git +Vcs-Git: https://salsa.debian.org/debian/requests-file.git +Vcs-Browser: https://salsa.debian.org/debian/requests-file Package: python3-requests-file Architecture: all diff -Nru requests-file-1.4.3/debian/copyright requests-file-1.5.1/debian/copyright --- requests-file-1.4.3/debian/copyright 2019-09-03 15:33:44.000000000 +0000 +++ requests-file-1.5.1/debian/copyright 2020-04-27 16:18:08.000000000 +0000 @@ -1,4 +1,4 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: requests-file Upstream-Contact: David Shea Source: http://github.com/dashea/requests-file diff -Nru requests-file-1.4.3/debian/rules requests-file-1.5.1/debian/rules --- requests-file-1.4.3/debian/rules 2019-09-03 15:33:44.000000000 +0000 +++ requests-file-1.5.1/debian/rules 2020-04-27 16:18:08.000000000 +0000 @@ -3,3 +3,6 @@ export PYBUILD_NAME=requests-file %: dh $@ --with python3 --buildsystem=pybuild + +override_dh_auto_test: + PYTHONPATH=$(CURDIR) pytest-3 diff -Nru requests-file-1.4.3/.github/workflows/test.yml requests-file-1.5.1/.github/workflows/test.yml --- requests-file-1.4.3/.github/workflows/test.yml 1970-01-01 00:00:00.000000000 +0000 +++ requests-file-1.5.1/.github/workflows/test.yml 2020-04-25 13:52:35.000000000 +0000 @@ -0,0 +1,43 @@ +name: CI +on: [push, pull_request] + +jobs: + pytest: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["2.x", "3.x"] + name: "pytest: Python ${{ matrix.python-version }}" + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install package + run: pip install . + - name: Install test dependencies + run: pip install pytest pytest-cov + + - name: Test with pytest + run: pytest --cov=. --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml + fail_ci_if_error: false + + black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v1 + with: + python-version: "3.x" + - name: Install black + run: pip install black + + - name: Run black + run: black --check . diff -Nru requests-file-1.4.3/.gitignore requests-file-1.5.1/.gitignore --- requests-file-1.4.3/.gitignore 2018-01-02 21:14:12.000000000 +0000 +++ requests-file-1.5.1/.gitignore 2020-04-25 13:52:35.000000000 +0000 @@ -1,5 +1,8 @@ *.pyc __pycache__ build +dist +.eggs *.egg-info .*.swp +.DS_Store diff -Nru requests-file-1.4.3/python-requests-file.spec requests-file-1.5.1/python-requests-file.spec --- requests-file-1.4.3/python-requests-file.spec 2018-01-02 21:14:12.000000000 +0000 +++ requests-file-1.5.1/python-requests-file.spec 1970-01-01 00:00:00.000000000 +0000 @@ -1,106 +0,0 @@ -%global srcname requests-file - -Name: python-%{srcname} -Version: 1.4 -Release: 1%{?dist} -Summary: Transport adapter for using file:// URLs with python-requests - -License: ASL 2.0 -URL: https://github.com/dashea/requests-file -Source0: https://pypi.python.org/packages/source/r/%{srcname}/%{srcname}-%{version}.tar.gz - -BuildArch: noarch - -%description -Requests-File is a transport adapter for use with the Requests Python -library to allow local file system access via file:// URLs. - -This is the Python 2 version of the requests_file module - -%package -n python2-%{srcname} -Summary: Transport adapter for using file:// URLs with python-requests -%{?python_provide:%python_provide python2-%{srcname}} - -BuildRequires: python2-devel -BuildRequires: python-setuptools -BuildRequires: python-requests -BuildRequires: python-six - -Requires: python-requests -Requires: python-six - -%description -n python2-%{srcname} -Requests-File is a transport adapter for use with the Requests Python -library to allow local file system access via file:// URLs. - -This is the Python 2 version of the requests_file module - -%package -n python3-requests-file -Summary: Transport adapter for using file:// URLs with python3-requests -%{?python_provide:%python_provide python3-%{srcname}} - -BuildRequires: python3-devel -BuildRequires: python3-setuptools -BuildRequires: python3-requests -BuildRequires: python3-six - -Requires: python3-requests -Requires: python3-six - -%description -n python3-requests-file -Requests-File is a transport adapter for use with the Requests Python -library to allow local file system access via file:// URLs. - -This is the Python 3 version of the requests_file module - -%prep -%autosetup -n %{srcname}-%{version} -rm -rf requests_file.egg-info - -%build -%py2_build -%py3_build - -%install -%py2_install -%py3_install - -%check -%{__python2} setup.py test -%{__python3} setup.py test - -%files -n python2-%{srcname} -%license LICENSE -%doc README.rst -%{python2_sitelib}/requests_file.py* -%{python2_sitelib}/requests_file*.egg-info* - -%files -n python3-requests-file -%license LICENSE -%doc README.rst -%{python3_sitelib}/requests_file.py* -%{python3_sitelib}/__pycache__/requests_file.* -%{python3_sitelib}/requests_file*.egg-info* - -%changelog -* Mon Sep 14 2015 David Shea - 1.4-1 -- Use getprerredencoding instead of nl_langinfo -- Handle files with a drive component -- Switch to the new Fedora packaging guidelines, which renames python-requests-file to python2-requests-file - -* Mon May 18 2015 David Shea - 1.3.1-1 -- Add python version classifiers to the package info - -* Mon May 18 2015 David Shea - 1.3-1 -- Fix a crash when closing a file response. -- Use named aliases instead of integers for status codes. - -* Fri May 8 2015 David Shea - 1.2-1 -- Added support for HEAD requests - -* Thu Mar 12 2015 David Shea - 1.1-1 -- Added handing for %% escapes in URLs -- Proofread the README - -* Tue Mar 10 2015 David Shea - 1.0-1 -- Initial package diff -Nru requests-file-1.4.3/requests_file.py requests-file-1.5.1/requests_file.py --- requests-file-1.4.3/requests_file.py 2018-01-02 21:14:12.000000000 +0000 +++ requests-file-1.5.1/requests_file.py 2020-04-25 13:52:35.000000000 +0000 @@ -9,7 +9,12 @@ from six import BytesIO + class FileAdapter(BaseAdapter): + def __init__(self, set_content_length=True): + super(FileAdapter, self).__init__() + self._set_content_length = set_content_length + def send(self, request, **kwargs): """ Wraps a file, described in request, in a Response object. @@ -36,7 +41,7 @@ try: # Split the path on / (the URL directory separator) and decode any # % escapes in the parts - path_parts = [unquote(p) for p in url_parts.path.split('/')] + path_parts = [unquote(p) for p in url_parts.path.split("/")] # Strip out the leading empty parts created from the leading /'s while path_parts and not path_parts[0]: @@ -51,16 +56,17 @@ # so that a directory separator can correctly be added to the real # path, and remove any empty path parts between the drive and the path. # Assume that a part ending with : or | (legacy) is a drive. - if path_parts and (path_parts[0].endswith('|') or - path_parts[0].endswith(':')): + if path_parts and ( + path_parts[0].endswith("|") or path_parts[0].endswith(":") + ): path_drive = path_parts.pop(0) - if path_drive.endswith('|'): - path_drive = path_drive[:-1] + ':' + if path_drive.endswith("|"): + path_drive = path_drive[:-1] + ":" while path_parts and not path_parts[0]: path_parts.pop(0) else: - path_drive = '' + path_drive = "" # Try to put the path back together # Join the drive back in, and stick os.sep in front of the path to @@ -91,7 +97,8 @@ # representation of the exception into a byte stream resp_str = str(e).encode(locale.getpreferredencoding(False)) resp.raw = BytesIO(resp_str) - resp.headers['Content-Length'] = len(resp_str) + if self._set_content_length: + resp.headers["Content-Length"] = len(resp_str) # Add release_conn to the BytesIO object resp.raw.release_conn = resp.raw.close @@ -101,8 +108,8 @@ # If it's a regular file, set the Content-Length resp_stat = os.fstat(resp.raw.fileno()) - if stat.S_ISREG(resp_stat.st_mode): - resp.headers['Content-Length'] = resp_stat.st_size + if stat.S_ISREG(resp_stat.st_mode) and self._set_content_length: + resp.headers["Content-Length"] = resp_stat.st_size return resp diff -Nru requests-file-1.4.3/setup.py requests-file-1.5.1/setup.py --- requests-file-1.4.3/setup.py 2018-01-02 21:14:12.000000000 +0000 +++ requests-file-1.5.1/setup.py 2020-04-25 13:52:35.000000000 +0000 @@ -1,7 +1,5 @@ #!/usr/bin/env python -import os - try: from setuptools import setup except ImportError: @@ -10,21 +8,22 @@ requires = [line.strip() for line in open("requirements.txt").readlines()] setup( - name='requests-file', - version='1.4.3', - description='File transport adapter for Requests', - author='David Shea', - author_email='dshea@redhat.com', - url='http://github.com/dashea/requests-file', - py_modules=['requests_file'], + name="requests-file", + version="1.5.1", + description="File transport adapter for Requests", + author="David Shea", + author_email="reallylongword@gmail.com", + url="http://github.com/dashea/requests-file", + py_modules=["requests_file"], install_requires=requires, - license='Apache 2.0', - test_suite='tests', - classifiers=['Development Status :: 3 - Alpha', - 'Environment :: Plugins', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4' - ] - ) + license="Apache 2.0", + test_suite="tests", + classifiers=[ + "Development Status :: 3 - Alpha", + "Environment :: Plugins", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + ], +) diff -Nru requests-file-1.4.3/tests/__init__.py requests-file-1.5.1/tests/__init__.py --- requests-file-1.4.3/tests/__init__.py 2018-01-02 21:14:12.000000000 +0000 +++ requests-file-1.5.1/tests/__init__.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,168 +0,0 @@ -import unittest -import requests -from requests_file import FileAdapter - -import os, stat -import tempfile -import shutil -import platform - -class FileRequestTestCase(unittest.TestCase): - def setUp(self): - self._session = requests.Session() - self._session.mount("file://", FileAdapter()) - - def _pathToURL(self, path): - """Convert a filesystem path to a URL path""" - urldrive, urlpath = os.path.splitdrive(path) - - # Split the path on the os spearator and recombine it with / as the - # separator. There probably aren't any OS's that allow / as a path - # component, but just in case, encode any remaining /'s. - urlsplit = (part.replace('/', '%2F') for part in urlpath.split(os.sep)) - urlpath = "/".join(urlsplit) - - # Encode /'s in the drive for the imaginary case where that can be a thing - urldrive = urldrive.replace('/', '%2F') - - # Add the leading /. If there is a drive component, this needs to be - # placed before the drive. - urldrive = "/" + urldrive - - return urldrive + urlpath - - def test_fetch_regular(self): - # Fetch this file using requests - with open(__file__, "rb") as f: - testdata = f.read() - response = self._session.get("file://%s" % self._pathToURL(os.path.abspath(__file__))) - - self.assertEqual(response.status_code, requests.codes.ok) - self.assertEqual(response.headers['Content-Length'], len(testdata)) - self.assertEqual(response.content, testdata) - - response.close() - - def test_fetch_missing(self): - # Fetch a file that (hopefully) doesn't exist, look for a 404 - response = self._session.get("file:///no/such/path") - self.assertEqual(response.status_code, requests.codes.not_found) - self.assertTrue(response.text) - response.close() - - @unittest.skipIf(hasattr(os, "geteuid") and os.geteuid() == 0, - "Skipping permissions test since running as root") - def test_fetch_no_access(self): - # Create a file and remove read permissions, try to get a 403 - # probably doesn't work on windows - with tempfile.NamedTemporaryFile() as tmp: - os.chmod(tmp.name, 0) - response = self._session.get("file://%s" % self._pathToURL(os.path.abspath(tmp.name))) - - self.assertEqual(response.status_code, requests.codes.forbidden) - self.assertTrue(response.text) - - response.close() - - @unittest.skipIf(platform.system() == "Windows", - "skipping locale test on windows") - def test_fetch_missing_localized(self): - # Make sure translated error messages don't cause any problems - import locale - - saved_locale = locale.setlocale(locale.LC_MESSAGES, None) - try: - locale.setlocale(locale.LC_MESSAGES, 'ru_RU.UTF-8') - response = self._session.get("file:///no/such/path") - self.assertEqual(response.status_code, requests.codes.not_found) - self.assertTrue(response.text) - response.close() - except locale.Error: - unittest.SkipTest('ru_RU.UTF-8 locale not available') - finally: - locale.setlocale(locale.LC_MESSAGES, saved_locale) - - def test_head(self): - # Check that HEAD returns the content-length - testlen = os.stat(__file__).st_size - response = self._session.head("file://%s" % self._pathToURL(os.path.abspath(__file__))) - - self.assertEqual(response.status_code, requests.codes.ok) - self.assertEqual(response.headers['Content-Length'], testlen) - - response.close() - - def test_fetch_post(self): - # Make sure that non-GET methods are rejected - self.assertRaises(ValueError, self._session.post, - ("file://%s" % self._pathToURL(os.path.abspath(__file__)))) - - def test_fetch_nonlocal(self): - # Make sure that network locations are rejected - self.assertRaises(ValueError, self._session.get, - ("file://example.com%s" % self._pathToURL(os.path.abspath(__file__)))) - self.assertRaises(ValueError, self._session.get, - ("file://localhost:8080%s" % self._pathToURL(os.path.abspath(__file__)))) - - # localhost is ok, though - with open(__file__, "rb") as f: - testdata = f.read() - response = self._session.get("file://localhost%s" % self._pathToURL(os.path.abspath(__file__))) - self.assertEqual(response.status_code, requests.codes.ok) - self.assertEqual(response.content, testdata) - response.close() - - def test_funny_names(self): - testdata = 'yo wassup man\n'.encode('ascii') - tmpdir = tempfile.mkdtemp() - - try: - with open(os.path.join(tmpdir, 'spa ces'), "w+b") as space_file: - space_file.write(testdata) - space_file.flush() - response = self._session.get("file://%s/spa%%20ces" % self._pathToURL(tmpdir)) - self.assertEqual(response.status_code, requests.codes.ok) - self.assertEqual(response.content, testdata) - response.close() - - with open(os.path.join(tmpdir, 'per%cent'), "w+b") as percent_file: - percent_file.write(testdata) - percent_file.flush() - response = self._session.get("file://%s/per%%25cent" % self._pathToURL(tmpdir)) - self.assertEqual(response.status_code, requests.codes.ok) - self.assertEqual(response.content, testdata) - response.close() - - # percent-encoded directory separators should be rejected - with open(os.path.join(tmpdir, 'badname'), "w+b") as bad_file: - response = self._session.get("file://%s%%%Xbadname" % (self._pathToURL(tmpdir), ord(os.sep))) - self.assertEqual(response.status_code, requests.codes.not_found) - response.close() - - finally: - shutil.rmtree(tmpdir) - - def test_close(self): - # Open a request for this file - response = self._session.get("file://%s" % self._pathToURL(os.path.abspath(__file__))) - - # Try closing it - response.close() - - def test_missing_close(self): - # Make sure non-200 responses can be closed - response = self._session.get("file:///no/such/path") - response.close() - - @unittest.skipIf(platform.system() != "Windows", "skipping windows URL test") - def test_windows_legacy(self): - """Test |-encoded drive characters on Windows""" - with open(__file__, "rb") as f: - testdata = f.read() - - drive, path = os.path.splitdrive(os.path.abspath(__file__)) - response = self._session.get("file:///%s|%s" % (drive[:-1], path.replace(os.sep, "/"))) - self.assertEqual(response.status_code, requests.codes.ok) - self.assertEqual(response.headers['Content-Length'], len(testdata)) - self.assertEqual(response.content, testdata) - response.close() diff -Nru requests-file-1.4.3/tests/test_requests_file.py requests-file-1.5.1/tests/test_requests_file.py --- requests-file-1.4.3/tests/test_requests_file.py 1970-01-01 00:00:00.000000000 +0000 +++ requests-file-1.5.1/tests/test_requests_file.py 2020-04-25 13:52:35.000000000 +0000 @@ -0,0 +1,197 @@ +import unittest +import requests +from requests_file import FileAdapter + +import os, stat +import tempfile +import shutil +import platform + + +class FileRequestTestCase(unittest.TestCase): + def setUp(self): + self._session = requests.Session() + self._session.mount("file://", FileAdapter()) + + def _pathToURL(self, path): + """Convert a filesystem path to a URL path""" + urldrive, urlpath = os.path.splitdrive(path) + + # Split the path on the os spearator and recombine it with / as the + # separator. There probably aren't any OS's that allow / as a path + # component, but just in case, encode any remaining /'s. + urlsplit = (part.replace("/", "%2F") for part in urlpath.split(os.sep)) + urlpath = "/".join(urlsplit) + + # Encode /'s in the drive for the imaginary case where that can be a thing + urldrive = urldrive.replace("/", "%2F") + + # Add the leading /. If there is a drive component, this needs to be + # placed before the drive. + urldrive = "/" + urldrive + + return urldrive + urlpath + + def test_fetch_regular(self): + # Fetch this file using requests + with open(__file__, "rb") as f: + testdata = f.read() + response = self._session.get( + "file://%s" % self._pathToURL(os.path.abspath(__file__)) + ) + + self.assertEqual(response.status_code, requests.codes.ok) + self.assertEqual(response.headers["Content-Length"], len(testdata)) + self.assertEqual(response.content, testdata) + + response.close() + + def test_fetch_missing(self): + # Fetch a file that (hopefully) doesn't exist, look for a 404 + response = self._session.get("file:///no/such/path") + self.assertEqual(response.status_code, requests.codes.not_found) + self.assertTrue(response.text) + response.close() + + @unittest.skipIf( + hasattr(os, "geteuid") and os.geteuid() == 0, + "Skipping permissions test since running as root", + ) + def test_fetch_no_access(self): + # Create a file and remove read permissions, try to get a 403 + # probably doesn't work on windows + with tempfile.NamedTemporaryFile() as tmp: + os.chmod(tmp.name, 0) + response = self._session.get( + "file://%s" % self._pathToURL(os.path.abspath(tmp.name)) + ) + + self.assertEqual(response.status_code, requests.codes.forbidden) + self.assertTrue(response.text) + + response.close() + + @unittest.skipIf(platform.system() == "Windows", "skipping locale test on windows") + def test_fetch_missing_localized(self): + # Make sure translated error messages don't cause any problems + import locale + + saved_locale = locale.setlocale(locale.LC_MESSAGES, None) + try: + locale.setlocale(locale.LC_MESSAGES, "ru_RU.UTF-8") + response = self._session.get("file:///no/such/path") + self.assertEqual(response.status_code, requests.codes.not_found) + self.assertTrue(response.text) + response.close() + except locale.Error: + unittest.SkipTest("ru_RU.UTF-8 locale not available") + finally: + locale.setlocale(locale.LC_MESSAGES, saved_locale) + + def test_head(self): + # Check that HEAD returns the content-length + testlen = os.stat(__file__).st_size + response = self._session.head( + "file://%s" % self._pathToURL(os.path.abspath(__file__)) + ) + + self.assertEqual(response.status_code, requests.codes.ok) + self.assertEqual(response.headers["Content-Length"], testlen) + + response.close() + + def test_fetch_post(self): + # Make sure that non-GET methods are rejected + self.assertRaises( + ValueError, + self._session.post, + ("file://%s" % self._pathToURL(os.path.abspath(__file__))), + ) + + def test_fetch_nonlocal(self): + # Make sure that network locations are rejected + self.assertRaises( + ValueError, + self._session.get, + ("file://example.com%s" % self._pathToURL(os.path.abspath(__file__))), + ) + self.assertRaises( + ValueError, + self._session.get, + ("file://localhost:8080%s" % self._pathToURL(os.path.abspath(__file__))), + ) + + # localhost is ok, though + with open(__file__, "rb") as f: + testdata = f.read() + response = self._session.get( + "file://localhost%s" % self._pathToURL(os.path.abspath(__file__)) + ) + self.assertEqual(response.status_code, requests.codes.ok) + self.assertEqual(response.content, testdata) + response.close() + + def test_funny_names(self): + testdata = "yo wassup man\n".encode("ascii") + tmpdir = tempfile.mkdtemp() + + try: + with open(os.path.join(tmpdir, "spa ces"), "w+b") as space_file: + space_file.write(testdata) + space_file.flush() + response = self._session.get( + "file://%s/spa%%20ces" % self._pathToURL(tmpdir) + ) + self.assertEqual(response.status_code, requests.codes.ok) + self.assertEqual(response.content, testdata) + response.close() + + with open(os.path.join(tmpdir, "per%cent"), "w+b") as percent_file: + percent_file.write(testdata) + percent_file.flush() + response = self._session.get( + "file://%s/per%%25cent" % self._pathToURL(tmpdir) + ) + self.assertEqual(response.status_code, requests.codes.ok) + self.assertEqual(response.content, testdata) + response.close() + + # percent-encoded directory separators should be rejected + with open(os.path.join(tmpdir, "badname"), "w+b") as bad_file: + response = self._session.get( + "file://%s%%%Xbadname" % (self._pathToURL(tmpdir), ord(os.sep)) + ) + self.assertEqual(response.status_code, requests.codes.not_found) + response.close() + + finally: + shutil.rmtree(tmpdir) + + def test_close(self): + # Open a request for this file + response = self._session.get( + "file://%s" % self._pathToURL(os.path.abspath(__file__)) + ) + + # Try closing it + response.close() + + def test_missing_close(self): + # Make sure non-200 responses can be closed + response = self._session.get("file:///no/such/path") + response.close() + + @unittest.skipIf(platform.system() != "Windows", "skipping windows URL test") + def test_windows_legacy(self): + """Test |-encoded drive characters on Windows""" + with open(__file__, "rb") as f: + testdata = f.read() + + drive, path = os.path.splitdrive(os.path.abspath(__file__)) + response = self._session.get( + "file:///%s|%s" % (drive[:-1], path.replace(os.sep, "/")) + ) + self.assertEqual(response.status_code, requests.codes.ok) + self.assertEqual(response.headers["Content-Length"], len(testdata)) + self.assertEqual(response.content, testdata) + response.close()