def parseLockRequest(stream): """ @return a twisted.web2.dav.element.WebDAVElement corresponding to the root element of the request body. Raises an error if the root element is not a lockinfo element, or if the request body (the stream) is empty. The latter is not quite correct, since according to RFC 2518, Section 7.8, a client may submit a LOCK request with an empty body (and an appropriate If: header) in order to refresh a lock, but it should be good enough for now. """ # obtain a DOM representation of the xml on the stream document = waitForDeferred(davXMLFromStream(stream)) yield document document = document.getResult() if document is None: # No request body makes no sense. # this is actually not quite correct, error = "Empty LOCK request." log.error(error) raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, error)) if not isinstance(document.root_element, LockInfo): error = "LOCK request must have lockinfo element as root element." raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, error)) yield document.root_element
def check_result(response): response = IResponse(response) if response.code != responsecode.MULTI_STATUS: self.fail("Incorrect response code for PROPPATCH (%s != %s)" % (response.code, responsecode.MULTI_STATUS)) return davXMLFromStream(response.stream).addCallback(check_xml)
def readRequestBody(request): """ Read XML body from request stream. """ try: doc = waitForDeferred(davXMLFromStream(request.stream)) yield doc doc = doc.getResult() except ValueError, e: log.error("Error while reading PROPPATCH body", exc_info=e) raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
def http_PROPPATCH(self, request): """ Respond to a PROPPATCH request. (RFC 2518, section 8.2) """ if not self.fp.exists(): log.err("File not found: %s" % (self.fp.path, )) raise HTTPError(responsecode.NOT_FOUND) # # Read request body # try: doc = waitForDeferred(davXMLFromStream(request.stream)) yield doc doc = doc.getResult() except ValueError, e: log.err("Error while handling PROPPATCH body: %s" % (e, )) raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
def check_result(response): response = IResponse(response) if response.code != responsecode.MULTI_STATUS: self.fail("Incorrect response code for PROPFIND (%s != %s)" % (response.code, responsecode.MULTI_STATUS)) content_type = response.headers.getHeader("content-type") if content_type not in (http_headers.MimeType("text", "xml"), http_headers.MimeType( "application", "xml")): self.fail( "Incorrect content-type for PROPFIND response (%r not in %r)" % (content_type, (http_headers.MimeType("text", "xml"), http_headers.MimeType("application", "xml")))) return davXMLFromStream(response.stream).addCallback(check_xml)