How to use the xandikos.webdav.Response function in xandikos

To help you get started, we’ve selected a few xandikos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jelmer / xandikos / xandikos / webdav.py View on Github external
def _send_dav_responses(responses, out_encoding):
    if isinstance(responses, Status):
        try:
            (body, body_type) = responses.get_single_body(
                out_encoding)
        except NeedsMultiStatus:
            responses = [responses]
        else:
            return Response(status=responses.status, headers={
                'Content-Type': body_type,
                'Content-Length': str(sum(map(len, body)))},
                body=body)
    ret = ET.Element('{DAV:}multistatus')
    for response in responses:
        ret.append(response.aselement())
    return _send_xml_response('207 Multi-Status', ret, out_encoding)
github jelmer / xandikos / xandikos / caldav.py View on Github external
return as_tz_aware_ts(dt, tz).astimezone(pytz.utc)
        (start, end) = _parse_time_range(requested)
        assert start.tzinfo
        assert end.tzinfo
        ret = ICalendar()
        ret['VERSION'] = '2.0'
        ret['PRODID'] = PRODID
        fb = FreeBusy()
        fb['DTSTAMP'] = vDDDTypes(tzify(datetime.datetime.now()))
        fb['DTSTART'] = vDDDTypes(start)
        fb['DTEND'] = vDDDTypes(end)
        fb['FREEBUSY'] = [item async for item in iter_freebusy(
            webdav.traverse_resource(base_resource, base_href, depth),
            start, end, tzify)]
        ret.add_component(fb)
        return webdav.Response(status='200 OK', body=[ret.to_ical()])
github jelmer / xandikos / xandikos / caldav.py View on Github external
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')
github jelmer / xandikos / xandikos / webdav.py View on Github external
async def handle(self, request, environ, app):
        content_type = request.content_type
        base_content_type, params = parse_type(content_type)
        if base_content_type not in (
            'text/plain', 'text/xml', 'application/xml', None,
            'application/octet-stream',
        ):
            raise UnsupportedMediaType(base_content_type)
        href, path, resource = app._get_resource_from_environ(request, environ)
        if resource is not None:
            return _send_method_not_allowed(
                app._get_allowed_methods(request))
        try:
            resource = app.backend.create_collection(path)
        except FileNotFoundError:
            return Response(status=409, reason='Conflict')
        if base_content_type in ('text/xml', 'application/xml'):
            # Extended MKCOL (RFC5689)
            et = await _readXmlBody(request, '{DAV:}mkcol', strict=app.strict)
            propstat = []
            for el in et:
                if el.tag != '{DAV:}set':
                    raise BadRequestError('Unknown tag %s in mkcol' % el.tag)
                propstat.extend(apply_modify_prop(el, href, resource,
                                                  app.properties))
            ret = ET.Element('{DAV:}mkcol-response')
            for propstat_el in propstat_as_xml(propstat):
                ret.append(propstat_el)
            return _send_xml_response(
                '201 Created', ret, DEFAULT_ENCODING)
        else:
            return Response(status=201, reason='Created')
github jelmer / xandikos / xandikos / webdav.py View on Github external
def _send_not_found(request):
    body = [b'Path ' + request.path.encode(DEFAULT_ENCODING) + b' not found.']
    return Response(body=body, status=404, reason='Not Found')
github jelmer / xandikos / xandikos / webdav.py View on Github external
def _send_method_not_allowed(allowed_methods):
    return Response(
        status=405, reason='Method Not Allowed',
        headers={'Allow': ', '.join(allowed_methods)})
github jelmer / xandikos / xandikos / webdav.py View on Github external
('Content-Length', str(content_length)),
    ]
    if current_etag is not None:
        headers.append(('ETag', current_etag))
    if content_type is not None:
        headers.append(('Content-Type', content_type))
    try:
        last_modified = r.get_last_modified()
    except KeyError:
        pass
    else:
        headers.append(('Last-Modified', last_modified))
    if content_languages is not None:
        headers.append(('Content-Language', ', '.join(content_languages)))
    if send_body:
        return Response(body=body, status=200, reason='OK', headers=headers)
    else:
        return Response(status=200, reason='OK', headers=headers)