~bzr/bzr-webdav/webdav

« back to all changes in this revision

Viewing changes to webdav.py

  • Committer: Vincent Ladeuil
  • Date: 2008-06-08 22:35:42 UTC
  • Revision ID: v.ladeuil+lp@free.fr-20080608223542-c47y2fmxuj9jngyy
All bzr tests passing with an apache2-dav local test server.

* test_webdav.py:
(_get_list_dir_apache2_depth_1_allprop): Tweak the the example by
putting non-zero lengths.
(TestDavSaxParser.test_list_dir_apache2_dir_depth_1_example):
<cough> add the forgotten test, we need to test for correct
behaviour and we re-factored two commits ago to do that don't we ?
(TestDavSaxParser.test_stat_apache2_dir_depth_0_example): Update
test '-1' for directory size is as good as None.

* webdav.py:
(DavStatHandler._init_response_attrs): Use '-1' for default length
value instead of None.
(DavStatHandler.endElement): Convert the length to int.
(_extract_dir_content): Return the full tuple instead of just the
name.
(HttpDavTransport.list_dir): Delegate to _list_tree and filter the
result.
(HttpDavTransport._list_tree): Was list_dir but now accept an
additional depth parameter.
(HttpDavTransport.iter_files_recursive): New function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
 
175
175
    def _init_response_attrs(self):
176
176
        self.href = None
177
 
        self.length = None
 
177
        self.length = -1
178
178
        self.executable = None
179
179
        self.is_dir = False
180
180
 
194
194
        if self._href_end():
195
195
            self.href = self.chars
196
196
        elif self._getcontentlength_end():
197
 
            self.length = self.chars
 
197
            self.length = int(self.chars)
198
198
        elif self._executable_end():
199
199
            self.executable = self.chars
200
200
        elif self._collection_end():
289
289
        raise errors.InvalidHttpResponse(
290
290
            url, msg='Malformed xml response: %s' % e)
291
291
    if handler.is_dir:
292
 
        size = None # directory sizes are meaningless for bzr
 
292
        size = -1 # directory sizes are meaningless for bzr
293
293
        is_exec = True
294
294
    else:
295
 
        size = int(handler.length)
 
295
        size = handler.length
296
296
        is_exec = (handler.executable == 'T')
297
297
    return _DAVStat(size, handler.is_dir, is_exec)
298
298
 
358
358
                name = name[0:-1]
359
359
            # We receive already url-encoded strings so down-casting is
360
360
            # safe. And bzr insists on getting strings not unicode strings.
361
 
            elements.append(str(name))
 
361
            elements.append((str(name), is_dir, size, is_exec))
362
362
    return elements
363
363
 
364
364
 
754
754
        """
755
755
        Return a list of all files at the given location.
756
756
        """
 
757
        return [elt[0] for elt in self._list_tree(relpath, 1)]
 
758
 
 
759
    def _list_tree(self, relpath, depth):
757
760
        abspath = self._remote_path(relpath)
758
761
        propfind = """<?xml version="1.0" encoding="utf-8" ?>
759
762
   <D:propfind xmlns:D="DAV:">
761
764
   </D:propfind>
762
765
"""
763
766
        request = _urllib2_wrappers.Request('PROPFIND', abspath, propfind,
764
 
                                            {'Depth': 1},
 
767
                                            {'Depth': depth},
765
768
                                            accepted_errors=[207, 404, 409,])
766
769
        response = self._perform(request)
767
770
 
823
826
                                   'unable to list  %r directory' % (abspath))
824
827
        return _extract_stat_info(abspath, response)
825
828
 
 
829
    def iter_files_recursive(self):
 
830
        """Walk the relative paths of all files in this transport."""
 
831
        # We get the whole tree with a single request
 
832
        tree = self._list_tree('.', 'Infinity')
 
833
        # Now filter out the directories
 
834
        for (name, is_dir, size, is_exex) in tree:
 
835
            if not is_dir:
 
836
                yield name
 
837
 
826
838
    # TODO: Before
827
839
    # www.ietf.org/internet-drafts/draft-suma-append-patch-00.txt
828
840
    # becomes  a real  RFC and  gets implemented,  we can  try to