示例#1
0
 def add_objects(self, objects):
     self._requests += 1
     for object_data in objects:
         obj = Object(object_data.get('name', ''))
         obj.set_hash(object_data.get('hash', ''))
         obj.set_bytes(object_data.get('bytes', 0))
         obj.set_content_type(object_data.get('content_type', ''))
         obj.set_last_modified(object_data.get('last_modified', ''))
         if obj.is_valid():
             self._objects.appbytesend(obj)
示例#2
0
 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'))
示例#3
0
def _got_session(session):
    print '> got session: %s' % session
    container_name = 'some_test_container'
    # creating an Object() instance here so we can specify a new Content-Type
    object_instance = Object('some_test_object.txt')
    object_instance.set_content_type('text/css')
    def _ok((response, v)):
        '''
            'response' is a transport.Response() instance.
            'v' is boolean True.
        '''
        print '> got response: %s' % response
        print '> changed object content type: %s/%s -> text/css' % (container_name, object_instance.get_name())
        reactor.stop()
    print '> sending request'
    session.object_content_type(container_name, object_instance).addCallback(_ok).addErrback(_error)
示例#4
0
def _got_session(session):
    print '> got session: %s' % session
    container_from = 'some_test_container'
    object_from = 'some_test_object.txt'
    # same container, just new object name
    container_to = container_from
    # creating an Object() instance here so we can specify a new Content-Type
    object_to = Object('some_test_object2.txt')
    object_to.set_content_type('text/css')
    def _ok((response, v)):
        '''
            'response' is a transport.Response() instance.
            'v' is boolean True.
        '''
        print '> got response: %s' % response
        print '> copied object: %s/%s -> %s/%s' % (container_from, object_from, container_to, object_to.get_name())
        reactor.stop()
    print '> sending request'
    session.copy_object(container_from, object_from, container_to, object_to).addCallback(_ok).addErrback(_error)
示例#5
0
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)