~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/http_transport.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-11 22:24:03 UTC
  • mto: (1185.11.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050711222403-5dc86e254b69f7ab
Remote functionality work.
Added lock_read/write() to Transport.
Turns out that both urllib2 and urlgrabber don't let you
seek on files that are returned, and GzipFile wants to
seek on the file when it is read. So instead,
we check, and wrap in a StringIO when required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
        """
103
103
        if isinstance(relpath, basestring):
104
104
            relpath = [relpath]
105
 
        return '/'.join(self.base, *relpath)
 
105
        return '/'.join([self.base] + relpath)
 
106
 
 
107
    def relpath(self, abspath):
 
108
        if not abspath.startswith(self.base):
 
109
            raise BzrError('path %r is not under base URL %r'
 
110
                           % (abspath, self.base))
 
111
        pl = len(self.base)
 
112
        return abspath[pl:].lstrip('/')
106
113
 
107
114
    def has(self, relpath):
108
115
        try:
120
127
        """
121
128
        if decode:
122
129
            import codecs
123
 
            return codecs.get_reader('utf-8')(get_url(self.abspath(relpath)))
 
130
            return codecs.getreader('utf-8')(get_url(self.abspath(relpath)))
124
131
        else:
125
132
            return get_url(self.abspath(relpath))
126
133
 
175
182
        """
176
183
        raise TransportNotPossibleError('http does not support stat()')
177
184
 
 
185
    def lock_read(self, relpath):
 
186
        """Lock the given file for shared (read) access.
 
187
        :return: A lock object, which should be passed to Transport.unlock()
 
188
        """
 
189
        # The old RemoteBranch ignore lock for reading, so we will
 
190
        # continue that tradition and return a bogus lock object.
 
191
        class BogusLock(object):
 
192
            def __init__(self, path):
 
193
                self.path = path
 
194
            def unlock(self):
 
195
                pass
 
196
        return BogusLock(relpath)
 
197
 
 
198
    def lock_write(self, relpath):
 
199
        """Lock the given file for exclusive (write) access.
 
200
        WARNING: many transports do not support this, so trying avoid using it
 
201
 
 
202
        :return: A lock object, which should be passed to Transport.unlock()
 
203
        """
 
204
        raise TransportNotPossibleError('http does not support lock_write()')
 
205
 
178
206
# If nothing else matches, try the LocalTransport
179
207
protocol_handlers['http://'] = HttpTransport
180
208
protocol_handlers['https://'] = HttpTransport