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