def PUT(self, REQUEST=None, RESPONSE=None): """WebDAV method to replace self with a new resource. This is also used when initialising an object just created from a NullResource. This will look up an IRawWriteFile adapter on self and write to it, line-by-line, from the request body. """ request = REQUEST is not None and REQUEST or self.REQUEST response = RESPONSE is not None and RESPONSE or request.response self.dav__init(request, response) self.dav__simpleifhandler(request, response, refresh=1) infile = request.get('BODYFILE', None) if infile is None: raise MethodNotAllowed( "Cannot complete PUT request: No BODYFILE in request") writer = IRawWriteFile(self, None) if writer is None: raise MethodNotAllowed( "Cannot complete PUT request: No IRawWriteFile adapter found") contentTypeHeader = request.get_header('content-type', None) if contentTypeHeader is not None: msg = Message() msg['Content-Type'] = contentTypeHeader mimeType = msg.get_content_type() if mimeType is not None: writer.mimeType = mimeType charset = msg.get_param('charset') if charset is not None: writer.encoding = charset try: for chunk in infile: writer.write(chunk) finally: writer.close() modified(self) return response
def PUT(self, REQUEST=None, RESPONSE=None): """WebDAV method to replace self with a new resource. This is also used when initialising an object just created from a NullResource. This will look up an IRawWriteFile adapter on self and write to it, line-by-line, from the request body. """ request = REQUEST is not None and REQUEST or self.REQUEST response = RESPONSE is not None and RESPONSE or request.response self.dav__init(request, response) self.dav__simpleifhandler(request, response, refresh=1) infile = request.get('BODYFILE', None) if infile is None: raise MethodNotAllowed( "Cannot complete PUT request: No BODYFILE in request" ) writer = IRawWriteFile(self, None) if writer is None: raise MethodNotAllowed( "Cannot complete PUT request: No IRawWriteFile adapter found" ) contentTypeHeader = request.get_header('content-type', None) if contentTypeHeader is not None: msg = Message() msg['Content-Type'] = contentTypeHeader mimeType = msg.get_content_type() if mimeType is not None: writer.mimeType = mimeType charset = msg.get_param('charset') if charset is not None: writer.encoding = charset try: for chunk in infile: writer.write(chunk) finally: writer.close() modified(self) return response
def test_updating_a_document_via_webdav_creates_initial_version_too(self, browser): self.login(self.regular_user) versioner = Versioner(self.document) self.assertFalse(versioner.has_initial_version()) writer = IRawWriteFile(self.document, None) writer.write('New Data') writer.close() self.assertTrue(versioner.has_initial_version()) self.assertEquals( 1, versioner.get_history_metadata().getLength(countPurged=False))
def test_cnxmlwritefile(self): cnxml = open(os.path.join(dirname, 'test.cnxml')).read() xmlfile = createObject('rhaptos.xmlfile.xmlfile', id='test.cnxml') writer = IRawWriteFile(xmlfile, None) writer.write(cnxml) self.assertTrue(isinstance(writer, CNXMLWriteFile)) self.assertEquals(writer.mimeType, 'application/cnxml+xml') writer.close() self.assertEquals(xmlfile.title, u'Calculating Descriptive Statistics') self.assertEquals(xmlfile.body.raw_encoded, cnxml) # test with cnxmlfile with entity refs cnxml = open(os.path.join(dirname, 'entityrefs.cnxml')).read() xmlfile = createObject('rhaptos.xmlfile.xmlfile', id='test.cnxml') writer = IRawWriteFile(xmlfile, None) writer.write(cnxml) writer.close() # test cnxmlplus cnxml = open(os.path.join(dirname, 'test.cnxmlplus')).read() xmlfile = createObject('rhaptos.xmlfile.xmlfile', id='test.cnxmlplus') writer = IRawWriteFile(xmlfile, None) self.assertEquals(writer.mimeType, 'application/cnxmlplus+xml')