~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2006-03-09 08:01:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060309080151-ad1d845b9aeae633
Add new protocol 'http+pycurl' that always uses PyCurl.

A special http server is provided for testing that asks clients to connect
this way.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
    implementation.
79
79
    """
80
80
 
 
81
    # _proto: "http" or "https"
 
82
    # _qualified_proto: may have "+pycurl", etc
 
83
 
81
84
    def __init__(self, base):
82
85
        """Set the base path where files will be stored."""
83
86
        proto_match = re.match(r'^(https?)(\+\w+)?://', base)
84
87
        if not proto_match:
85
88
            raise AssertionError("not a http url: %r" % base)
86
 
        real_proto=proto_match.group(1)
87
 
        impl_name=proto_match.group(2)
 
89
        self._proto = proto_match.group(1)
 
90
        impl_name = proto_match.group(2)
88
91
        if impl_name:
89
92
            impl_name = impl_name[1:]
 
93
        self._impl_name = impl_name
90
94
        if base[-1] != '/':
91
95
            base = base + '/'
92
96
        super(HttpTransportBase, self).__init__(base)
93
97
        # In the future we might actually connect to the remote host
94
98
        # rather than using get_url
95
99
        # self._connection = None
96
 
        (self._proto, self._host,
 
100
        (apparent_proto, self._host,
97
101
            self._path, self._parameters,
98
102
            self._query, self._fragment) = urlparse.urlparse(self.base)
99
 
        self._proto = real_proto
 
103
        self._qualified_proto = apparent_proto
100
104
 
101
105
    def abspath(self, relpath):
102
106
        """Return the full url to the given relative path.
103
 
        This can be supplied with a string or a list
 
107
 
 
108
        This can be supplied with a string or a list.
 
109
 
 
110
        This always returns "http://host" without the implementation
 
111
        qualifier, even if one was originally given.
104
112
        """
105
113
        assert isinstance(relpath, basestring)
106
114
        if isinstance(relpath, basestring):
133
141
        # I'm concerned about when it chooses to strip the last
134
142
        # portion of the path, and when it doesn't.
135
143
        path = '/'.join(basepath)
136
 
        return urlparse.urlunparse((self._proto,
137
 
                self._host, path, '', '', ''))
 
144
        return urlparse.urlunparse((self._qualified_proto,
 
145
                                    self._host, path, '', '', ''))
138
146
 
139
147
    def get(self, relpath):
140
148
        raise NotImplementedError("has() is abstract on %r" % self)
335
343
class HttpServer(Server):
336
344
    """A test server for http transports."""
337
345
 
 
346
    # used to form the url that connects to this server
 
347
    _url_protocol = 'http'
 
348
 
338
349
    def _http_start(self):
339
350
        httpd = None
340
351
        httpd = TestingHTTPServer(('localhost', 0),
341
352
                                  TestingHTTPRequestHandler,
342
353
                                  self)
343
354
        host, port = httpd.socket.getsockname()
344
 
        self._http_base_url = 'http://localhost:%s/' % port
 
355
        self._http_base_url = '%s://localhost:%s/' % (self._url_protocol, port)
345
356
        self._http_starting.release()
346
357
        httpd.socket.settimeout(0.1)
347
358