示例#1
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)