81
# _proto: "http" or "https"
82
# _qualified_proto: may have "+pycurl", etc
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)
89
92
impl_name = impl_name[1:]
93
self._impl_name = impl_name
90
94
if base[-1] != '/':
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
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
108
This can be supplied with a string or a list.
110
This always returns "http://host" without the implementation
111
qualifier, even if one was originally given.
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, '', '', ''))
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."""
346
# used to form the url that connects to this server
347
_url_protocol = 'http'
338
349
def _http_start(self):
340
351
httpd = TestingHTTPServer(('localhost', 0),
341
352
TestingHTTPRequestHandler,
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)