Package cloudfiles :: Module storage_object :: Class Object
[frames] | no frames]

Class Object

source code


Storage data representing an object, (metadata and data).

Instance Methods
 
__init__(self, container, name=None, force_exists=False, object_record=None)
Storage objects rarely if ever need to be instantiated directly by the user.
source code
str or None
read(*args, **kwargs)
Read the content from the remote storage object.
 
save_to_filename(self, filename, callback=None)
Save the contents of the object to filename.
source code
str generator
stream(*args, **kwargs)
Return a generator of the remote storage object's data.
 
sync_metadata(*args, **kwargs)
Commits the metadata and custom headers to the remote storage system.
 
sync_manifest(*args, **kwargs)
Commits the manifest to the remote storage system.
 
write(*args, **kwargs)
Write data to the remote storage system.
 
copy_to(*args, **kwargs)
Copy an object's contents to another location.
 
copy_from(*args, **kwargs)
Copy another object's contents to this object.
 
send(*args, **kwargs)
Write potentially transient data to the remote storage system using a generator or stream.
 
load_from_filename(self, filename, verify=True, callback=None)
Put the contents of the named file into remote storage.
source code
 
__str__(self)
str(x)
source code
str
public_uri(self)
Retrieve the URI for this object, if its container is public.
source code
str
public_ssl_uri(self)
Retrieve the SSL URI for this object, if its container is public.
source code
str
public_streaming_uri(self)
Retrieve the streaming URI for this object, if its container is public.
source code
 
purge_from_cdn(self, email=None)
Purge Edge cache for this object.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Instance Variables
Container container
the object's container (generally treat as read-only)
str content_type
the object's content-type (set or read)
str last_modified
date and time of last file modification (cached)
dict metadata
metadata associated with the object (set or read)
str name
the object's name (generally treat as read-only)
number size
the object's size (cached)
Properties
  objsum
  etag

Inherited from object: __class__

Method Details

__init__(self, container, name=None, force_exists=False, object_record=None)
(Constructor)

source code 

Storage objects rarely if ever need to be instantiated directly by the user.

Instead, use the create_object, get_object, list_objects and other methods on its parent Container object.

Overrides: object.__init__

read(*args, **kwargs)

 

Read the content from the remote storage object.

By default this method will buffer the response in memory and return it as a string. However, if a file-like object is passed in using the buffer keyword, the response will be written to it instead.

A callback can be passed in for reporting on the progress of the download. The callback should accept two integers, the first will be for the amount of data written so far, the second for the total size of the transfer. Note: This option is only applicable when used in conjunction with the buffer option.

>>> test_object.write('hello')
>>> test_object.read()
'hello'
Parameters:
  • size (number) - combined with offset, defines the length of data to be read
  • offset (number) - combined with size, defines the start location to be read
  • hdrs (dictionary) - an optional dict of headers to send with the request
  • buffer (file-like object) - an optional file-like object to write the content to
  • callback (callable(transferred, size)) - function to be used as a progress callback
Returns: str or None
a string of all data in the object, or None if a buffer is used
Decorators:
  • @requires_name(InvalidObjectName)

save_to_filename(self, filename, callback=None)

source code 

Save the contents of the object to filename.

>>> container = connection['container1']
>>> obj = container.get_object('backup_file')
>>> obj.save_to_filename('./backup_file')
Parameters:
  • filename (str) - name of the file
  • callback (callable(transferred, size)) - function to be used as a progress callback

stream(*args, **kwargs)

 

Return a generator of the remote storage object's data.

Warning: The HTTP response is only complete after this generator has raised a StopIteration. No other methods can be called until this has occurred.

>>> test_object.write('hello')
>>> test_object.stream()
<generator object at 0xb77939cc>
>>> '-'.join(test_object.stream(chunksize=1))
'h-e-l-l-o'
Parameters:
  • chunksize (number) - size in bytes yielded by the generator
  • hdrs (dict) - an optional dict of headers to send in the request
Returns: str generator
a generator which yields strings as the object is downloaded
Decorators:
  • @requires_name(InvalidObjectName)

sync_metadata(*args, **kwargs)

 

Commits the metadata and custom headers to the remote storage system.

>>> test_object = container['paradise_lost.pdf']
>>> test_object.metadata = {'author': 'John Milton'}
>>> test_object.headers = {'content-disposition': 'foo'}
>>> test_objectt.sync_metadata()

Object metadata can be set and retrieved through the object's .metadata attribute.

Decorators:
  • @requires_name(InvalidObjectName)

sync_manifest(*args, **kwargs)

 

Commits the manifest to the remote storage system.

>>> test_object = container['paradise_lost.pdf']
>>> test_object.manifest = 'container/prefix'
>>> test_object.sync_manifest()

Object manifests can be set and retrieved through the object's .manifest attribute.

Decorators:
  • @requires_name(InvalidObjectName)

write(*args, **kwargs)

 

Write data to the remote storage system.

By default, server-side verification is enabled, (verify=True), and end-to-end verification is performed using an md5 checksum. When verification is disabled, (verify=False), the etag attribute will be set to the value returned by the server, not one calculated locally. When disabling verification, there is no guarantee that what you think was uploaded matches what was actually stored. Use this optional carefully. You have been warned.

A callback can be passed in for reporting on the progress of the upload. The callback should accept two integers, the first will be for the amount of data written so far, the second for the total size of the transfer.

>>> test_object = container.create_object('file.txt')
>>> test_object.content_type = 'text/plain'
>>> fp = open('./file.txt')
>>> test_object.write(fp)
Parameters:
  • data (str or file) - the data to be written
  • verify (boolean) - enable/disable server-side checksum verification
  • callback (callable(transferred, size)) - function to be used as a progress callback
Decorators:
  • @requires_name(InvalidObjectName)

copy_to(*args, **kwargs)

 

Copy an object's contents to another location.

Decorators:
  • @requires_name(InvalidObjectName)

copy_from(*args, **kwargs)

 

Copy another object's contents to this object.

Decorators:
  • @requires_name(InvalidObjectName)

send(*args, **kwargs)

 

Write potentially transient data to the remote storage system using a generator or stream.

If the object's size is not set, chunked transfer encoding will be used to upload the file.

If the object's size attribute is set, it will be used as the Content-Length. If the generator raises StopIteration prior to yielding the right number of bytes, an IncompleteSend exception is raised.

If the content_type attribute is not set then a value of application/octet-stream will be used.

Server-side verification will be performed if an md5 checksum is assigned to the etag property before calling this method, otherwise no verification will be performed, (verification can be performed afterward though by using the etag attribute which is set to the value returned by the server).

>>> test_object = container.create_object('backup.tar.gz')
>>> pfd = os.popen('tar -czvf - ./data/', 'r')
>>> test_object.send(pfd)
Parameters:
  • iterable (generator or stream) - stream or generator which yields the content to upload
Decorators:
  • @requires_name(InvalidObjectName)

load_from_filename(self, filename, verify=True, callback=None)

source code 

Put the contents of the named file into remote storage.

>>> test_object = container.create_object('file.txt')
>>> test_object.content_type = 'text/plain'
>>> test_object.load_from_filename('./my_file.txt')
Parameters:
  • filename (str) - path to the file
  • verify (boolean) - enable/disable server-side checksum verification
  • callback (callable(transferred, size)) - function to be used as a progress callback

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

public_uri(self)

source code 

Retrieve the URI for this object, if its container is public.

>>> container1 = connection['container1']
>>> container1.make_public()
>>> container1.create_object('file.txt').write('testing')
>>> container1['file.txt'].public_uri()
'http://c00061.cdn.cloudfiles.rackspacecloud.com/file.txt'
Returns: str
the public URI for this object

public_ssl_uri(self)

source code 

Retrieve the SSL URI for this object, if its container is public.

>>> container1 = connection['container1']
>>> container1.make_public()
>>> container1.create_object('file.txt').write('testing')
>>> container1['file.txt'].public_ssl_uri()
'https://c61.ssl.cf0.rackcdn.com/file.txt'
Returns: str
the public SSL URI for this object

public_streaming_uri(self)

source code 

Retrieve the streaming URI for this object, if its container is public.

>>> container1 = connection['container1']
>>> container1.make_public()
>>> container1.create_object('file.txt').write('testing')
>>> container1['file.txt'].public_streaming_uri()
'https://c61.stream.rackcdn.com/file.txt'
Returns: str
the public Streaming URI for this object

purge_from_cdn(self, email=None)

source code 

Purge Edge cache for this object. You will be notified by email if one is provided when the job completes.

>>> obj.purge_from_cdn("user@dmain.com")

or

>>> obj.purge_from_cdn("user@domain.com,user2@domain.com")

or

>>> obj.purge_from_cdn()
Parameters:
  • email (str) - A Valid email address

Property Details

objsum

Get Method:
unreachable(self)

etag

Get Method:
unreachable(self)
Set Method:
__set_etag(self, value)