cloudfiles

Package cloudfiles |
[frames] | no frames]

# Source Code for Package cloudfiles

      1  """
      2  Cloud Files python client API.
      3
      4  Working with result sets:
      5
      6      >>> import cloudfiles
      7      >>> # conn = cloudfiles.get_connection(username='jsmith', \
      8                   api_key='1234567890')
      9      >>> conn = cloudfiles.get_connection('jsmith', '1234567890')
     10      >>> # NOTE: For Uk Customers please pass in Default UK Auth URL like EX
     11      >>> conn = cloudfiles.get_connection('username', 'api_key', \
     12      >>>                                  authurl = cloudfiles.uk_authurl)
     13      >>> # This will force connectivity to the UK's Auth Service
     14      >>> containers = conn.get_all_containers()
     15      >>> type(containers)
     16      <class 'cloudfiles.container.ContainerResults'>
     17      >>> len(containers)
     18      2
     19      >>> for container in containers:
     20      >>>     print container.name
     21      fruit
     22      vegitables
     23      >>> print containers[0].name
     24      fruit
     25      >>> fruit_container = containers[0]
     26      >>> objects = fruit_container.get_objects()
     27      >>> for storage_object in objects:
     28      >>>     print storage_object.name
     29      apple
     30      orange
     31      bannana
     32      >>>
     33
     34  Setting the argument servicenet=True to get_conection will use the
     35  Rackspace ServiceNet network to access Cloud Files (and not the public
     36  network) :
     37
     38      >>> import cloudfiles
     39      >>> conn = cloudfiles.get_connection('jsmith', '1234567890', \
     40          servicenet=True)
     41      >>> conn.connection_args[0]
     42      'snet-storage4.clouddrive.com'
     43
     44  If you define the environment variable RACKSPACE_SERVICENET it will
     45  automatically connect via the servicenet network.
     46
     47  Creating Containers and adding Objects to them:
     48
     49      >>> pic_container = conn.create_container('pictures')
     50      >>> my_dog = pic_container.create_object('fido.jpg')
     51      >>> my_dog.load_from_filename('images/IMG-0234.jpg')
     52      >>> text_obj = pic_container.create_object('sample.txt')
     53      >>> text_obj.write('This is not the object you are looking for.\\n')
     54      >>> text_obj.read()
     55      'This is not the object you are looking for.'
     56
     57  Object instances support streaming through the use of a generator:
     58
     59      >>> deb_iso = pic_container.get_object('debian-40r3-i386-netinst.iso')
     60      >>> f = open('/tmp/debian.iso', 'w')
     61      >>> for chunk in deb_iso.stream():
     62      ..     f.write(chunk)
     63      >>> f.close()
     64
     65  Marking a Container as CDN-enabled/public with a TTL of 30 days
     66
     67      >>> pic_container.make_public(2592000)
     68      >>> pic_container.public_uri()
     69      'http://c0001234.cdn.cloudfiles.rackspacecloud.com'
     70      >>> my_dog.public_uri()
     71      'http://c0001234.cdn.cloudfiles.rackspacecloud.com/fido.jpg'
     72
     73  Set the logs retention on CDN-enabled/public Container
     74
     75      >>> pic_container.log_retention(True)
     76
     77  See COPYING for license information.
     78  """
     79
     80  from cloudfiles.connection     import Connection, ConnectionPool
     81  from cloudfiles.container      import Container
     82  from cloudfiles.storage_object import Object
     83  from cloudfiles.consts         import __version__, \
     84  us_authurl, uk_authurl
     85
     86
     87 -def get_connection(*args, **kwargs):
     88      """
     89      Helper function for creating connection instances.
     90
     91      @type username: string
     92      @param username: a Mosso username
     93      @type api_key: string
     94      @param api_key: a Mosso API key
     95      @rtype: L{Connection}
     96      @returns: a connection object
     97      """
     98      return Connection(*args, **kwargs)
     99