commit 4af6b54c4cdae8dbfd19cc0da92660d53239127e from: Jelmer Vernooij via: GitHub date: Wed Aug 09 19:50:59 2023 UTC Merge pull request #1200 from jelmer/http-error Raise GitProtocolError when encountering HTTP Errors in HTTPGitClient commit - 7574997132990398779c424b9860c85fae499d31 commit + 4af6b54c4cdae8dbfd19cc0da92660d53239127e blob - dc7bc644ba226294bc67aa1472bbdaa571b486a8 blob + 054be7e3c9fa3de5813c11211ac88df99fd2d3ce --- NEWS +++ NEWS @@ -17,6 +17,9 @@ * objects: Define a stricter return type for _parse_message (Vincent Lorentz) + * Raise GitProtocolError when encountering HTTP Errors in + HTTPGitClient. (Jelmer Vernooij, #1199) + 0.21.5 2023-05-04 * Be more tolerant to non-3-length tuple versions. blob - 87d69bad94d9b3ffd6d33cffcf06ff7f595919f3 blob + bf6b9086caaaf69f33873e012000da2e0f9e5e4d --- dulwich/client.py +++ dulwich/client.py @@ -1949,6 +1949,8 @@ class AbstractHttpGitClient(GitClient): redirect_location properties, and read is a consumable read method for the response data. + Raises: + GitProtocolError """ raise NotImplementedError(self._http_request) @@ -2225,13 +2227,16 @@ class Urllib3HttpGitClient(AbstractHttpGitClient): req_headers.update(headers) req_headers["Pragma"] = "no-cache" - if data is None: - resp = self.pool_manager.request( - "GET", url, headers=req_headers, preload_content=False) - else: - resp = self.pool_manager.request( - "POST", url, headers=req_headers, body=data, preload_content=False - ) + try: + if data is None: + resp = self.pool_manager.request( + "GET", url, headers=req_headers, preload_content=False) + else: + resp = self.pool_manager.request( + "POST", url, headers=req_headers, body=data, preload_content=False + ) + except urllib3.exceptions.HTTPError as e: + raise GitProtocolError(str(e)) from e if resp.status == 404: raise NotGitRepository() blob - d3b2e88d3d449b262ded4588be5c9d1d79a9327e blob + ff5acb5f1c9aa30f1b7df749037340d67de21032 --- dulwich/objects.py +++ dulwich/objects.py @@ -141,7 +141,7 @@ def hex_to_filename(path, hex): # os.path.join accepts bytes or unicode, but all args must be of the same # type. Make sure that hex which is expected to be bytes, is the same type # as path. - if type(path) != type(hex) and getattr(path, "encode", None) is not None: + if type(path) is not type(hex) and getattr(path, "encode", None) is not None: hex = hex.decode("ascii") dir = hex[:2] file = hex[2:] blob - a50e46458e3f145a0786fbe269a83ff49620f67e blob + 253989551f98928a3338363e87522d7de4703416 --- dulwich/tests/test_client.py +++ dulwich/tests/test_client.py @@ -1538,7 +1538,7 @@ class PLinkSSHVendorTests(TestCase): ) for w in warnings_list: - if type(w) == type(expected_warning) and w.args == expected_warning.args: + if type(w) is type(expected_warning) and w.args == expected_warning.args: break else: raise AssertionError( @@ -1583,7 +1583,7 @@ class PLinkSSHVendorTests(TestCase): ) for w in warnings_list: - if type(w) == type(expected_warning) and w.args == expected_warning.args: + if type(w) is type(expected_warning) and w.args == expected_warning.args: break else: raise AssertionError( blob - fbe6adb61368d082ee131ac524c1516887af752f blob + c19fcc1da91f92c7d962e83576465863b11716d9 --- dulwich/tests/test_repository.py +++ dulwich/tests/test_repository.py @@ -842,7 +842,7 @@ exit 1 "non-zero status 1", ) for w in warnings_list: - if type(w) == type(expected_warning) and w.args == expected_warning.args: + if type(w) is type(expected_warning) and w.args == expected_warning.args: break else: raise AssertionError(