~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http.py

  • Committer: Jelmer Vernooij
  • Date: 2005-10-17 23:48:28 UTC
  • mto: (1185.16.102)
  • mto: This revision was merged to the branch mainline in revision 1488.
  • Revision ID: jelmer@samba.org-20051017234828-c250f2060f104fcc
Remove TODO item that is already implemented.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.trace import mutter
30
30
 
 
31
# velocitynet.com.au transparently proxies connections and thereby
 
32
# breaks keep-alive -- sucks!
 
33
 
31
34
 
32
35
def get_url(url):
33
36
    import urllib2
75
78
        This can be supplied with a string or a list
76
79
        """
77
80
        if isinstance(relpath, basestring):
78
 
            relpath_parts = relpath.split('/')
79
 
        else:
80
 
            # TODO: Don't call this with an array - no magic interfaces
81
 
            relpath_parts = relpath[:]
82
 
        if len(relpath_parts) > 1:
83
 
            if relpath_parts[0] == '':
84
 
                raise ValueError("path %r within branch %r seems to be absolute"
85
 
                                 % (relpath, self._path))
86
 
            if relpath_parts[-1] == '':
87
 
                raise ValueError("path %r within branch %r seems to be a directory"
88
 
                                 % (relpath, self._path))
 
81
            relpath = [relpath]
89
82
        basepath = self._path.split('/')
90
83
        if len(basepath) > 0 and basepath[-1] == '':
91
84
            basepath = basepath[:-1]
92
 
        for p in relpath_parts:
 
85
 
 
86
        for p in relpath:
93
87
            if p == '..':
94
 
                if len(basepath) == 0:
 
88
                if len(basepath) < 0:
95
89
                    # In most filesystems, a request for the parent
96
90
                    # of root, just returns root.
97
91
                    continue
98
 
                basepath.pop()
99
 
            elif p == '.' or p == '':
 
92
                if len(basepath) > 0:
 
93
                    basepath.pop()
 
94
            elif p == '.':
100
95
                continue # No-op
101
96
            else:
102
97
                basepath.append(p)
 
98
 
103
99
        # Possibly, we could use urlparse.urljoin() here, but
104
100
        # I'm concerned about when it chooses to strip the last
105
101
        # portion of the path, and when it doesn't.
107
103
        return urlparse.urlunparse((self._proto,
108
104
                self._host, path, '', '', ''))
109
105
 
 
106
    def relpath(self, abspath):
 
107
        if not abspath.startswith(self.base):
 
108
            raise NonRelativePath('path %r is not under base URL %r'
 
109
                           % (abspath, self.base))
 
110
        pl = len(self.base)
 
111
        return abspath[pl:].lstrip('/')
 
112
 
110
113
    def has(self, relpath):
111
114
        """Does the target location exist?
112
115
 
146
149
                             % (self.abspath(relpath), str(e)),
147
150
                             orig_error=e)
148
151
 
 
152
    def get_partial(self, relpath, start, length=None):
 
153
        """Get just part of a file.
 
154
 
 
155
        :param relpath: Path to the file, relative to base
 
156
        :param start: The starting position to read from
 
157
        :param length: The length to read. A length of None indicates
 
158
                       read to the end of the file.
 
159
        :return: A file-like object containing at least the specified bytes.
 
160
                 Some implementations may return objects which can be read
 
161
                 past this length, but this is not guaranteed.
 
162
        """
 
163
        # TODO: You can make specialized http requests for just
 
164
        # a portion of the file. Figure out how to do that.
 
165
        # For now, urllib2 returns files that cannot seek() so
 
166
        # we just read bytes off the beginning, until we
 
167
        # get to the point that we care about.
 
168
        f = self.get(relpath)
 
169
        # TODO: read in smaller chunks, in case things are
 
170
        # buffered internally.
 
171
        f.read(start)
 
172
        return f
 
173
 
149
174
    def put(self, relpath, f):
150
175
        """Copy the file-like or string object into the location.
151
176