/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib.py

  • Committer: Lukáš Lalinský
  • Date: 2007-12-17 17:28:25 UTC
  • mfrom: (3120 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3123.
  • Revision ID: lalinsky@gmail.com-20071217172825-tr3pqm1mhvs3gwnn
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
from bzrlib import (
22
22
    errors,
 
23
    trace,
23
24
    urlutils,
24
25
    )
25
 
from bzrlib.trace import mutter
26
 
from bzrlib.transport.http import HttpTransportBase
27
 
# TODO: handle_response should be integrated into the _urllib2_wrappers
 
26
from bzrlib.transport import http
 
27
# TODO: handle_response should be integrated into the http/__init__.py
28
28
from bzrlib.transport.http.response import handle_response
29
29
from bzrlib.transport.http._urllib2_wrappers import (
30
30
    Opener,
32
32
    )
33
33
 
34
34
 
35
 
class HttpTransport_urllib(HttpTransportBase):
 
35
class HttpTransport_urllib(http.HttpTransportBase):
36
36
    """Python urllib transport for http and https."""
37
37
 
38
38
    # In order to debug we have to issue our traces in sync with
70
70
            # Give back shared info
71
71
            request.connection = connection
72
72
            (auth, proxy_auth) = self._get_credentials()
 
73
            # Clean the httplib.HTTPConnection pipeline in case the previous
 
74
            # request couldn't do it
 
75
            connection.cleanup_pipe()
73
76
        else:
74
77
            # First request, intialize credentials.
75
78
            # scheme and realm will be set by the _urllib2_wrappers.AuthHandler
85
88
        request.auth = auth
86
89
        request.proxy_auth = proxy_auth
87
90
 
88
 
        mutter('%s: [%s]' % (request.method, request.get_full_url()))
89
91
        if self._debuglevel > 0:
90
92
            print 'perform: %s base: %s, url: %s' % (request.method, self.base,
91
93
                                                     request.get_full_url())
108
110
                                           qual_proto=self._scheme)
109
111
 
110
112
        if request.redirected_to is not None:
111
 
            mutter('redirected from: %s to: %s' % (request.get_full_url(),
112
 
                                                   request.redirected_to))
 
113
            trace.mutter('redirected from: %s to: %s' % (request.get_full_url(),
 
114
                                                         request.redirected_to))
113
115
 
114
116
        return response
115
117
 
124
126
            if range_header is not None:
125
127
                accepted_errors.append(206)
126
128
                accepted_errors.append(400)
 
129
                accepted_errors.append(416)
127
130
                bytes = 'bytes=' + range_header
128
131
                headers = {'Range': bytes}
129
132
 
133
136
 
134
137
        code = response.code
135
138
        if code == 404: # not found
136
 
            self._get_connection().fake_close()
137
139
            raise errors.NoSuchFile(abspath)
 
140
        elif code in (400, 416):
 
141
            # We don't know which, but one of the ranges we specified was
 
142
            # wrong.
 
143
            raise errors.InvalidHttpRange(abspath, range_header,
 
144
                                          'Server return code %d' % code)
138
145
 
139
 
        data = handle_response(abspath, code, response.headers, response)
140
 
        # Close response to free the httplib.HTTPConnection pipeline
141
 
        self._get_connection().fake_close()
 
146
        data = handle_response(abspath, code, response.info(), response)
142
147
        return code, data
143
148
 
144
149
    def _post(self, body_bytes):
145
150
        abspath = self._remote_path('.bzr/smart')
146
151
        response = self._perform(Request('POST', abspath, body_bytes))
147
152
        code = response.code
148
 
        data = handle_response(abspath, code, response.headers, response)
149
 
        # Close response to free the httplib.HTTPConnection pipeline
150
 
        self._get_connection().fake_close()
 
153
        data = handle_response(abspath, code, response.info(), response)
151
154
        return code, data
152
155
 
153
156
    def _head(self, relpath):
160
163
                          accepted_errors=[200, 404])
161
164
        response = self._perform(request)
162
165
 
163
 
        self._get_connection().fake_close()
164
166
        return response
165
167
 
166
168
    def has(self, relpath):