~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
 
17
from cStringIO import StringIO
 
18
import urllib
 
19
import urlparse
18
20
 
19
21
from bzrlib import (
20
22
    errors,
21
23
    trace,
 
24
    urlutils,
22
25
    )
23
26
from bzrlib.transport import http
24
27
# TODO: handle_response should be integrated into the http/__init__.py
38
41
 
39
42
    _opener_class = Opener
40
43
 
41
 
    def __init__(self, base, _from_transport=None, ca_certs=None):
 
44
    def __init__(self, base, _from_transport=None):
42
45
        super(HttpTransport_urllib, self).__init__(
43
46
            base, 'urllib', _from_transport=_from_transport)
44
47
        if _from_transport is not None:
45
48
            self._opener = _from_transport._opener
46
49
        else:
47
50
            self._opener = self._opener_class(
48
 
                report_activity=self._report_activity, ca_certs=ca_certs)
 
51
                report_activity=self._report_activity)
49
52
 
50
53
    def _perform(self, request):
51
54
        """Send the request to the server and handles common errors.
135
138
        abspath = self._remote_path('.bzr/smart')
136
139
        # We include 403 in accepted_errors so that send_http_smart_request can
137
140
        # handle a 403.  Otherwise a 403 causes an unhandled TransportError.
138
 
        response = self._perform(
139
 
            Request('POST', abspath, body_bytes,
140
 
                    {'Content-Type': 'application/octet-stream'},
141
 
                    accepted_errors=[200, 403]))
 
141
        response = self._perform(Request('POST', abspath, body_bytes,
 
142
                                         accepted_errors=[200, 403]))
142
143
        code = response.code
143
144
        data = handle_response(abspath, code, response.info(), response)
144
145
        return code, data
169
170
 
170
171
def get_test_permutations():
171
172
    """Return the permutations to be used in testing."""
172
 
    from bzrlib.tests import (
173
 
        features,
174
 
        http_server,
175
 
        )
 
173
    from bzrlib import tests
 
174
    from bzrlib.tests import http_server
176
175
    permutations = [(HttpTransport_urllib, http_server.HttpServer_urllib),]
177
 
    if features.HTTPSServerFeature.available():
178
 
        from bzrlib.tests import (
179
 
            https_server,
180
 
            ssl_certs,
181
 
            )
182
 
 
183
 
        class HTTPS_urllib_transport(HttpTransport_urllib):
184
 
 
185
 
            def __init__(self, base, _from_transport=None):
186
 
                super(HTTPS_urllib_transport, self).__init__(
187
 
                    base, _from_transport=_from_transport,
188
 
                    ca_certs=ssl_certs.build_path('ca.crt'))
189
 
 
190
 
        permutations.append((HTTPS_urllib_transport,
 
176
    if tests.HTTPSServerFeature.available():
 
177
        from bzrlib.tests import https_server
 
178
        permutations.append((HttpTransport_urllib,
191
179
                             https_server.HTTPSServer_urllib))
192
180
    return permutations