Esempio n. 1
0
 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'))])
     ])
Esempio n. 2
0
 async def handle(self, request, environ, app):
     content_type = request.content_type
     base_content_type, params = webdav.parse_type(content_type)
     if base_content_type not in (
             "text/xml",
             "application/xml",
             None,
             "text/plain",
             "application/octet-stream",
     ):
         raise webdav.UnsupportedMediaType(content_type)
     href, path, resource = app._get_resource_from_environ(request, environ)
     if resource is not None:
         return webdav._send_simple_dav_error(
             request,
             "403 Forbidden",
             error=ET.Element("{DAV:}resource-must-be-null"),
             description=("Something already exists at %r" % path),
         )
     try:
         resource = app.backend.create_collection(path)
     except FileNotFoundError:
         return webdav.Response(status="409 Conflict")
     el = ET.Element("{DAV:}resourcetype")
     await app.properties["{DAV:}resourcetype"].get_value(
         href, resource, el, environ)
     ET.SubElement(el, "{urn:ietf:params:xml:ns:caldav}calendar")
     app.properties["{DAV:}resourcetype"].set_value(href, resource, el)
     if base_content_type in ("text/xml", "application/xml"):
         et = await webdav._readXmlBody(
             request,
             "{urn:ietf:params:xml:ns:caldav}mkcalendar",
             strict=app.strict,
         )
         propstat = []
         for el in et:
             if el.tag != "{DAV:}set":
                 raise webdav.BadRequestError(
                     "Unknown tag %s in mkcalendar" % el.tag)
             propstat.extend(
                 webdav.apply_modify_prop(el, href, resource,
                                          app.properties))
             ret = ET.Element(
                 "{urn:ietf:params:xml:ns:carldav:}mkcalendar-response")
         for propstat_el in webdav.propstat_as_xml(propstat):
             ret.append(propstat_el)
         return webdav._send_xml_response("201 Created", ret,
                                          webdav.DEFAULT_ENCODING)
     else:
         return webdav.Response(status="201 Created")
Esempio n. 3
0
 def handle(self, environ, start_response, app):
     try:
         content_type = environ['CONTENT_TYPE']
     except KeyError:
         base_content_type = None
     else:
         base_content_type, params = webdav.parse_type(content_type)
     if base_content_type not in ('text/xml', 'application/xml', None,
                                  'text/plain'):
         raise webdav.UnsupportedMediaType(content_type)
     href, path, resource = app._get_resource_from_environ(environ)
     if resource is not None:
         return webdav._send_simple_dav_error(
             environ,
             start_response,
             '403 Forbidden',
             error=ET.Element('{DAV:}resource-must-be-null'),
             description=('Something already exists at %r' % path))
     try:
         resource = app.backend.create_collection(path)
     except FileNotFoundError:
         start_response('409 Conflict', [])
         return []
     el = ET.Element('{DAV:}resourcetype')
     app.properties['{DAV:}resourcetype'].get_value(href, resource, el,
                                                    environ)
     ET.SubElement(el, '{urn:ietf:params:xml:ns:caldav}calendar')
     app.properties['{DAV:}resourcetype'].set_value(href, resource, el)
     if base_content_type in ('text/xml', 'application/xml'):
         et = webdav._readXmlBody(
             environ, '{urn:ietf:params:xml:ns:caldav}mkcalendar')
         propstat = []
         for el in et:
             if el.tag != '{DAV:}set':
                 raise webdav.BadRequestError(
                     'Unknown tag %s in mkcalendar' % el.tag)
             propstat.extend(
                 webdav.apply_modify_prop(el, href, resource,
                                          app.properties))
             ret = ET.Element(
                 '{urn:ietf:params:xml:ns:carldav:}mkcalendar-response')
         for propstat_el in webdav.propstat_as_xml(propstat):
             ret.append(propstat_el)
         return webdav._send_xml_response(start_response, '201 Created',
                                          ret, webdav.DEFAULT_ENCODING)
     else:
         start_response('201 Created', [])
         return []
Esempio n. 4
0
 def test_none(self):
     self.assertEqual([], list(webdav.propstat_as_xml([])))