~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_pycurl.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:
54
54
        """
55
55
        return True
56
56
 
 
57
    def _real_abspath(self, relpath):
 
58
        """Produce absolute path, adjusting protocol if needed"""
 
59
        abspath = self.abspath(relpath)
 
60
        if abspath.startswith('http+pycurl'):
 
61
            abspath = 'http' + abspath[11:]
 
62
        elif abspath.startswith('https+pycurl'):
 
63
            abspath = 'https' + abspath[12:]
 
64
        if isinstance(abspath, unicode):
 
65
            abspath = abspath.encode('ascii', 'strict')
 
66
        return abspath
 
67
 
57
68
    def has(self, relpath):
58
69
        curl = pycurl.Curl()
59
 
        abspath = self.abspath(relpath)
60
 
        if isinstance(abspath, unicode):
61
 
            abspath = abspath.encode('ascii', 'strict')
 
70
        abspath = self._real_abspath(relpath)
62
71
        curl.setopt(pycurl.URL, abspath)
63
72
        curl.setopt(pycurl.FOLLOWLOCATION, 1) # follow redirect responses
64
73
        self._set_curl_options(curl)
76
85
        
77
86
    def get(self, relpath):
78
87
        curl = pycurl.Curl()
79
 
        abspath = self.abspath(relpath)
 
88
        abspath = self._real_abspath(relpath)
80
89
        sio = StringIO()
81
 
        if isinstance(abspath, unicode):
82
 
            abspath = abspath.encode('ascii')
83
90
        curl.setopt(pycurl.URL, abspath)
84
91
        self._set_curl_options(curl)
85
92
        curl.setopt(pycurl.WRITEFUNCTION, sio.write)
120
127
                raise NoSuchFile(curl.getinfo(pycurl.EFFECTIVE_URL), e)
121
128
 
122
129
 
 
130
class HttpServer_PyCurl(HttpServer):
 
131
    """Subclass of HttpServer that gives http+pycurl urls.
 
132
 
 
133
    This is for use in testing: connections to this server will always go
 
134
    through pycurl where possible.
 
135
    """
 
136
 
 
137
    # urls returned by this server should require the pycurl client impl
 
138
    _url_protocol = 'http+pycurl'
 
139
 
 
140
 
123
141
def get_test_permutations():
124
142
    """Return the permutations to be used in testing."""
125
 
    return [(PyCurlTransport, HttpServer),
 
143
    return [(PyCurlTransport, HttpServer_PyCurl),
126
144
            ]