56
56
def has(self, relpath):
57
self.curl = pycurl.Curl()
58
58
abspath = self.abspath(relpath)
59
59
if isinstance(abspath, unicode):
60
60
abspath = abspath.encode('ascii', 'strict')
61
self.curl.setopt(pycurl.URL, abspath)
62
self.curl.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirect responses
63
self._set_curl_options()
61
curl.setopt(pycurl.URL, abspath)
62
curl.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirect responses
63
self._set_curl_options(curl)
64
64
# don't want the body - ie just do a HEAD request
65
self.curl.setopt(pycurl.NOBODY, 1)
68
code = self.curl.getinfo(pycurl.HTTP_CODE)
69
if code == 404: # not found
71
elif code in (200, 302): # "ok", "found"
74
raise TransportError('http error %d probing for %s' %
75
(code, self.curl.getinfo(pycurl.EFFECTIVE_URL)))
65
curl.setopt(pycurl.NOBODY, 1)
66
self._curl_perform(curl)
67
code = curl.getinfo(pycurl.HTTP_CODE)
68
if code == 404: # not found
70
elif code in (200, 302): # "ok", "found"
73
raise TransportError('http error %d probing for %s' %
74
(code, curl.getinfo(pycurl.EFFECTIVE_URL)))
79
76
def get(self, relpath):
80
self.curl = pycurl.Curl()
81
78
abspath = self.abspath(relpath)
83
80
if isinstance(abspath, unicode):
84
81
abspath = abspath.encode('ascii')
85
self.curl.setopt(pycurl.URL, abspath)
86
self._set_curl_options(self.curl)
87
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
88
self.curl.setopt(pycurl.NOBODY, 0)
90
code = self.curl.getinfo(pycurl.HTTP_CODE)
82
curl.setopt(pycurl.URL, abspath)
83
self._set_curl_options(curl)
84
curl.setopt(pycurl.WRITEFUNCTION, sio.write)
85
curl.setopt(pycurl.NOBODY, 0)
86
self._curl_perform(curl)
87
code = curl.getinfo(pycurl.HTTP_CODE)
92
89
raise NoSuchFile(abspath)
98
94
raise TransportError('http error %d acccessing %s' %
99
(code, self.curl.getinfo(pycurl.EFFECTIVE_URL)))
95
(code, curl.getinfo(pycurl.EFFECTIVE_URL)))
101
97
def _set_curl_options(self, curl):
102
98
"""Set options for all requests"""
105
101
# provided by Curl.
106
102
headers = ['Cache-control: must-revalidate',
108
## self.curl.setopt(pycurl.VERBOSE, 1)
104
## curl.setopt(pycurl.VERBOSE, 1)
109
105
curl.setopt(pycurl.HTTPHEADER, headers)
110
106
curl.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirect responses
112
def _curl_perform(self):
108
def _curl_perform(self, curl):
113
109
"""Perform curl operation and translate exceptions."""
116
112
except pycurl.error, e:
117
113
# XXX: There seem to be no symbolic constants for these values.
119
115
# couldn't resolve host
120
raise NoSuchFile(self.curl.getinfo(pycurl.EFFECTIVE_URL), e)
116
raise NoSuchFile(curl.getinfo(pycurl.EFFECTIVE_URL), e)
124
119
def get_test_permutations():