Skip to content

Commit

Permalink
Fix Python3 client web support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Apr 13, 2016
1 parent d036356 commit ff8a613
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

* Drop support for Python 2.6.

* Fix python3 client web support. (Jelmer Vernooij)

BUG FIXES

* Fix hang on Gzip decompression. (Jonas Haag)
Expand Down
30 changes: 21 additions & 9 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,16 +980,21 @@ def _discover_references(self, service, url):
url = urlparse.urljoin(url, "info/refs")
headers = {}
if self.dumb is not False:
url += "?service=%s" % service
headers["Content-Type"] = "application/x-%s-request" % service
url += "?service=%s" % service.decode('ascii')
headers["Content-Type"] = "application/x-%s-request" % (
service.decode('ascii'))
resp = self._http_request(url, headers)
try:
self.dumb = (not resp.info().gettype().startswith("application/x-git-"))
content_type = resp.info().gettype()
except AttributeError:
content_type = resp.info().get_content_type()
try:
self.dumb = (not content_type.startswith("application/x-git-"))
if not self.dumb:
proto = Protocol(resp.read, None)
# The first line should mention the service
pkts = list(proto.read_pkt_seq())
if pkts != [('# service=%s\n' % service)]:
if pkts != [b'# service=' + service + b'\n']:
raise GitProtocolError(
"unexpected first line %r from smart server" % pkts)
return read_pkt_refs(proto)
Expand All @@ -1001,11 +1006,18 @@ def _discover_references(self, service, url):
def _smart_request(self, service, url, data):
assert url[-1] == "/"
url = urlparse.urljoin(url, service)
headers = {"Content-Type": "application/x-%s-request" % service}
headers = {
"Content-Type": "application/x-%s-request" % service
}
resp = self._http_request(url, headers, data)
if resp.info().gettype() != ("application/x-%s-result" % service):
try:
content_type = resp.info().gettype()
except AttributeError:
content_type = resp.info().get_content_type()
if content_type != (
"application/x-%s-result" % service):
raise GitProtocolError("Invalid content-type from server: %s"
% resp.info().gettype())
% content_type)
return resp

def send_pack(self, path, determine_wants, generate_pack_contents,
Expand Down Expand Up @@ -1045,7 +1057,7 @@ def send_pack(self, path, determine_wants, generate_pack_contents,
objects = generate_pack_contents(have, want)
if len(objects) > 0:
write_pack(req_proto.write_file(), objects)
resp = self._smart_request(b"git-receive-pack", url,
resp = self._smart_request("git-receive-pack", url,
data=req_data.getvalue())
try:
resp_proto = Protocol(resp.read, None)
Expand Down Expand Up @@ -1083,7 +1095,7 @@ def fetch_pack(self, path, determine_wants, graph_walker, pack_data,
req_proto, negotiated_capabilities, graph_walker, wants,
lambda: False)
resp = self._smart_request(
b"git-upload-pack", url, data=req_data.getvalue())
"git-upload-pack", url, data=req_data.getvalue())
try:
resp_proto = Protocol(resp.read, None)
self._handle_upload_pack_tail(resp_proto, negotiated_capabilities,
Expand Down
15 changes: 9 additions & 6 deletions dulwich/tests/compat/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
SkipTest,
expectedFailure,
)
from dulwich.tests.utils import (
skipIfPY3,
)
from dulwich.tests.compat.utils import (
CompatTestCase,
check_for_daemon,
Expand Down Expand Up @@ -463,7 +460,11 @@ def run_backend(self):
'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
env.setdefault(k, "")

self.send_response(200, "Script output follows")
self.wfile.write(b"HTTP/1.1 200 Script output follows\r\n")
self.wfile.write(
("Server: %s\r\n" % self.server.server_name).encode('ascii'))
self.wfile.write(
("Date: %s\r\n" % self.date_time_string()).encode('ascii'))

decoded_query = query.replace('+', ' ')

Expand Down Expand Up @@ -499,7 +500,6 @@ def get_url(self):
return 'http://%s:%s/' % (self.server_name, self.server_port)


@skipIfPY3
class DulwichHttpClientTest(CompatTestCase, DulwichClientTestBase):

min_git_version = (1, 7, 0, 2)
Expand All @@ -525,7 +525,10 @@ def _client(self):
return client.HttpGitClient(self._httpd.get_url())

def _build_path(self, path):
return path
if sys.version_info[0] == 3:
return path.decode('ascii')
else:
return path

def test_archive(self):
raise SkipTest("exporting archives not supported over http")

0 comments on commit ff8a613

Please sign in to comment.