/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/_pycurl.py

  • Committer: Andrew Bennetts
  • Date: 2007-08-02 06:40:58 UTC
  • mfrom: (2666 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2668.
  • Revision ID: andrew.bennetts@canonical.com-20070802064058-09eblz1qbc01fcr3
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    Python client.  Advantages include: DNS caching.
88
88
    """
89
89
 
90
 
    def __init__(self, base, from_transport=None):
91
 
        super(PyCurlTransport, self).__init__(base)
 
90
    def __init__(self, base, _from_transport=None):
 
91
        super(PyCurlTransport, self).__init__(base,
 
92
                                              _from_transport=_from_transport)
92
93
        if base.startswith('https'):
93
94
            # Check availability of https into pycurl supported
94
95
            # protocols
96
97
            if 'https' not in supported:
97
98
                raise DependencyNotPresent('pycurl', 'no https support')
98
99
        self.cabundle = ca_bundle.get_ca_path()
99
 
        if from_transport is not None:
100
 
            self._curl = from_transport._curl
101
 
        else:
102
 
            mutter('using pycurl %s' % pycurl.version)
103
 
            self._curl = pycurl.Curl()
 
100
 
 
101
    def _get_curl(self):
 
102
        connection = self._get_connection()
 
103
        if connection is None:
 
104
            # First connection ever. There is no credentials for pycurl, either
 
105
            # the password was embedded in the URL or it's not needed. The
 
106
            # connection for pycurl is just the Curl object, it will not
 
107
            # connect to the http server until the first request (which had
 
108
            # just called us).
 
109
            connection = pycurl.Curl()
 
110
            self._set_connection(connection, None)
 
111
        return connection
104
112
 
105
113
    def should_cache(self):
106
114
        """Return True if the data pulled across should be cached locally.
111
119
        """See Transport.has()"""
112
120
        # We set NO BODY=0 in _get_full, so it should be safe
113
121
        # to re-use the non-range curl object
114
 
        curl = self._curl
115
 
        abspath = self._real_abspath(relpath)
 
122
        curl = self._get_curl()
 
123
        abspath = self._remote_path(relpath)
116
124
        curl.setopt(pycurl.URL, abspath)
117
125
        self._set_curl_options(curl)
118
126
        curl.setopt(pycurl.HTTPGET, 1)
161
169
                 data: file that will be filled with the body
162
170
                 header: file that will be filled with the headers
163
171
        """
164
 
        abspath = self._real_abspath(relpath)
 
172
        abspath = self._remote_path(relpath)
165
173
        curl.setopt(pycurl.URL, abspath)
166
174
        self._set_curl_options(curl)
167
175
 
174
182
 
175
183
    def _get_full(self, relpath):
176
184
        """Make a request for the entire file"""
177
 
        curl = self._curl
 
185
        curl = self._get_curl()
178
186
        abspath, data, header = self._setup_get_request(curl, relpath)
179
187
        self._curl_perform(curl, header)
180
188
 
191
199
 
192
200
    def _get_ranged(self, relpath, offsets, tail_amount):
193
201
        """Make a request for just part of the file."""
194
 
        curl = self._curl
 
202
        curl = self._get_curl()
195
203
        abspath, data, header = self._setup_get_request(curl, relpath)
196
204
 
197
205
        range_header = self._attempted_range_header(offsets, tail_amount)
210
218
 
211
219
    def _post(self, body_bytes):
212
220
        fake_file = StringIO(body_bytes)
213
 
        curl = self._curl
214
 
        # Other places that use _base_curl for GET requests explicitly set
215
 
        # HTTPGET, so it should be safe to re-use the same object for both GETs
216
 
        # and POSTs.
 
221
        curl = self._get_curl()
 
222
        # Other places that use the Curl object (returned by _get_curl)
 
223
        # for GET requests explicitly set HTTPGET, so it should be safe to
 
224
        # re-use the same object for both GETs and POSTs.
217
225
        curl.setopt(pycurl.POST, 1)
218
226
        curl.setopt(pycurl.POSTFIELDSIZE, len(body_bytes))
219
227
        curl.setopt(pycurl.READFUNCTION, fake_file.read)
292
300
            raise errors.RedirectRequested(url,
293
301
                                           redirected_to,
294
302
                                           is_permament=(code == 301),
295
 
                                           qual_proto=self._qualified_proto)
 
303
                                           qual_proto=self._scheme)
296
304
 
297
305
 
298
306
def get_test_permutations():