def test_multiple(self): self.assertEqual({ ('200 OK', None): ['foo'], ('404 Not Found', 'Cannot find'): ['bar']}, webdav.propstat_by_status([ webdav.PropStatus('200 OK', None, 'foo'), webdav.PropStatus('404 Not Found', 'Cannot find', 'bar')]))
def test_multiple(self): self.assertEqual( { ("200 OK", None): ["foo"], ("404 Not Found", "Cannot find"): ["bar"], }, webdav.propstat_by_status([ webdav.PropStatus("200 OK", None, "foo"), webdav.PropStatus("404 Not Found", "Cannot find", "bar"), ]), )
def test_one(self): self.assertEqual([ b'<ns0:propstat xmlns:ns0="DAV:"><ns0:status>HTTP/1.1 200 ' b'OK</ns0:status><ns0:prop><foo /></ns0:prop></ns0:propstat>' ], [ ET.tostring(x) for x in webdav.propstat_as_xml( [webdav.PropStatus('200 OK', None, ET.Element('foo'))]) ])
def report(self, environ, request_body, resources_by_hrefs, properties, href, resource, depth): old_token = None sync_level = None limit = None requested = None for el in request_body: if el.tag == '{DAV:}sync-token': old_token = el.text elif el.tag == '{DAV:}sync-level': sync_level = el.text elif el.tag == '{DAV:}limit': limit = el.text elif el.tag == '{DAV:}prop': requested = list(el) else: raise webdav.BadRequestError('unknown tag %s' % el.tag) # TODO(jelmer): Implement sync_level infinite if sync_level not in ("1", ): raise webdav.BadRequestError("sync level %r unsupported" % sync_level) new_token = resource.get_sync_token() try: diff_iter = resource.iter_differences_since(old_token, new_token) except NotImplementedError: yield webdav.Status( href, '403 Forbidden', error=ET.Element('{DAV:}sync-traversal-supported')) return if limit is not None: try: [nresults_el] = list(limit) except ValueError: raise webdav.BadRequestError( 'Invalid number of subelements in limit') try: nresults = int(nresults_el.text) except ValueError: raise webdav.BadRequestError('nresults not a number') diff_iter = itertools.islice(diff_iter, nresults) for (name, old_resource, new_resource) in diff_iter: propstat = [] if new_resource is None: for prop in requested: propstat.append( webdav.PropStatus('404 Not Found', None, ET.Element(prop.tag))) else: for prop in requested: if old_resource is not None: old_propstat = webdav.get_property_from_element( href, old_resource, properties, prop, environ) else: old_propstat = None new_propstat = webdav.get_property_from_element( href, new_resource, properties, prop, environ) if old_propstat != new_propstat: propstat.append(new_propstat) yield webdav.Status(urllib.parse.urljoin( webdav.ensure_trailing_slash(href), name), propstat=propstat) yield SyncToken(new_token)
def test_one(self): self.assertEqual({ ('200 OK', None): ['foo']}, webdav.propstat_by_status([ webdav.PropStatus('200 OK', None, 'foo')]))
def test_one(self): self.assertEqual( {("200 OK", None): ["foo"]}, webdav.propstat_by_status( [webdav.PropStatus("200 OK", None, "foo")]), )