~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-18 21:09:19 UTC
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050918210919-efe08efa7113110c
Added implementations and tests for get_partial

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
        """
150
150
        raise NotImplementedError
151
151
 
152
 
    def get_partial(self, relpath, portion):
153
 
        """Get just part of a file.
154
 
 
155
 
        :param relpath: Path to the file, relative to base
156
 
        :param portion: A tuple of [start,length). 
157
 
                        Length can be -1 indicating copy until the end
158
 
                        of the file. If the file ends before length bytes,
159
 
                        just the set of bytes will be returned (think read())
160
 
        :return: A file-like object containing at least the specified bytes.
161
 
                 Some implementations may return objects which can be read
162
 
                 past this length, but this is not guaranteed.
163
 
        """
164
 
        raise NotImplementedError
165
 
 
166
 
    def get_partial_multi(self, files, pb=None):
167
 
        """Put a set of files or strings into the location.
168
 
 
169
 
        Requesting multiple portions of the same file can be dangerous.
170
 
 
171
 
        :param files: A list of tuples of relpath, portion
172
 
                      [(path1, portion1), (path2, portion2),...]
173
 
        :param pb:  An optional ProgressBar for indicating percent done.
174
 
        :return: A generator of file-like objects.
175
 
        """
176
 
        self._iterate_over(files, self.get_partial, pb, 'get_partial', expand=True)
177
 
 
178
152
    def get_multi(self, relpaths, pb=None):
179
153
        """Get a list of file-like objects, one for each entry in relpaths.
180
154
 
192
166
            yield self.get(relpath)
193
167
            count += 1
194
168
 
 
169
    def get_partial(self, relpath, start, length=None):
 
170
        """Get just part of a file.
 
171
 
 
172
        :param relpath: Path to the file, relative to base
 
173
        :param start: The starting position to read from
 
174
        :param length: The length to read. A length of None indicates
 
175
                       read to the end of the file.
 
176
        :return: A file-like object containing at least the specified bytes.
 
177
                 Some implementations may return objects which can be read
 
178
                 past this length, but this is not guaranteed.
 
179
        """
 
180
        raise NotImplementedError
 
181
 
 
182
    def get_partial_multi(self, offsets, pb=None):
 
183
        """Put a set of files or strings into the location.
 
184
 
 
185
        Requesting multiple portions of the same file can be dangerous.
 
186
 
 
187
        :param offsets: A list of tuples of relpath, start, length
 
188
                         [(path1, start1, length1),
 
189
                          (path2, start2, length2),
 
190
                          (path3, start3), ...]
 
191
                         length is optional, defaulting to None
 
192
        :param pb:  An optional ProgressBar for indicating percent done.
 
193
        :return: A generator of file-like objects.
 
194
        """
 
195
        total = self._get_total(offsets)
 
196
        count = 0
 
197
        for offset in offsets:
 
198
            self._update_pb(pb, 'get_partial', count, total)
 
199
            yield self.get_partial(*offset)
 
200
            count += 1
 
201
 
195
202
    def put(self, relpath, f):
196
203
        """Copy the file-like or string object into the location.
197
204