def _parse(r): if r.OK: object_name = r.request._object.get_name() obj = Object(name=object_name) obj.set_remote_hash(r.headers.get('ETag', '')) obj.set_content_type(r.headers.get('Content-Type', '')) obj.set_remote_lenth(r.headers.get('Content-Length', 0)) obj.set_data(r.body) d.callback((r, obj)) elif r.status_code == 401: d.errback(NotAuthenticatedException('failed to delete object, not authorised')) elif r.status_code == 404: d.errback(ResponseException('failed to delete object, object does not exist')) else: d.errback(ResponseException('failed to delete object'))
def _got_session(session): print '> got session: %s' % session container_name = 'some_test_container' object_instance = Object('some_test_object.txt') object_instance.set_content_type('text/plain') object_instance.set_compressed() object_instance.set_data('example data in object') def _ok((response, obj)): ''' 'response' is a transport.Response() instance. 'obj' is a cfobject.Object() instance. ''' print '> got response: %s' % response print '> created object: %s/%s' % (container_name, object_instance.get_name()) print '> got object populated with response data: %s' % obj reactor.stop() print '> sending request' # create_object() also takes an optional 'delete_at' kwarg which if set to a # datetime.datetime instance in the future will reques the object be deleted # from the rackspace cloudfiles servers at that time, use timedelta's to # specify rolling timers (e.g. delete this 24hr's from now). session.create_object(container_name, object_instance).addCallback(_ok).addErrback(_error)