The swiftclient.client Module

Cloud Files client library used internally

exception swiftclient.client.ClientException(msg, http_scheme='', http_host='', http_port='', http_path='', http_query='', http_status=0, http_reason='', http_device='', http_response_content='')

Bases: exceptions.Exception

class swiftclient.client.Connection(authurl=None, user=None, key=None, retries=5, preauthurl=None, preauthtoken=None, snet=False, starting_backoff=1, tenant_name=None, os_options=None, auth_version='1', cacert=None, insecure=False)

Bases: object

Convenience class to make requests that will also retry the request

delete_container(container)

Wrapper for delete_container()

delete_object(container, obj)

Wrapper for delete_object()

get_account(marker=None, limit=None, prefix=None, full_listing=False)

Wrapper for get_account()

get_auth()
get_container(container, marker=None, limit=None, prefix=None, delimiter=None, full_listing=False)

Wrapper for get_container()

get_object(container, obj, resp_chunk_size=None)

Wrapper for get_object()

head_account()

Wrapper for head_account()

head_container(container)

Wrapper for head_container()

head_object(container, obj)

Wrapper for head_object()

http_connection()
post_account(headers)

Wrapper for post_account()

post_container(container, headers)

Wrapper for post_container()

post_object(container, obj, headers)

Wrapper for post_object()

put_container(container, headers=None)

Wrapper for put_container()

put_object(container, obj, contents, content_length=None, etag=None, chunk_size=65536, content_type=None, headers=None)

Wrapper for put_object()

swiftclient.client.delete_container(url, token, container, http_conn=None)

Delete a container

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name to delete
  • http_conn – HTTP connection object (If None, it will create the conn object)
Raises ClientException:
 

HTTP DELETE request failed

swiftclient.client.delete_object(url, token=None, container=None, name=None, http_conn=None, headers=None, proxy=None)

Delete object

Parameters:
  • url – storage URL
  • token – auth token; if None, no token will be sent
  • container – container name that the object is in; if None, the container name is expected to be part of the url
  • name – object name to delete; if None, the object name is expected to be part of the url
  • http_conn – HTTP connection object (If None, it will create the conn object)
  • headers – additional headers to include in the request
  • proxy – proxy to connect through, if any; None by default; str of the format ‘http://127.0.0.1:8888‘ to set one
Raises ClientException:
 

HTTP DELETE request failed

swiftclient.client.encode_utf8(value)
swiftclient.client.get_account(url, token, marker=None, limit=None, prefix=None, http_conn=None, full_listing=False)

Get a listing of containers for the account.

Parameters:
  • url – storage URL
  • token – auth token
  • marker – marker query
  • limit – limit query
  • prefix – prefix query
  • http_conn – HTTP connection object (If None, it will create the conn object)
  • full_listing – if True, return a full listing, else returns a max of 10000 listings
Returns:

a tuple of (response headers, a list of containers) The response headers will be a dict and all header names will be lowercase.

Raises ClientException:
 

HTTP GET request failed

swiftclient.client.get_auth(auth_url, user, key, **kwargs)

Get authentication/authorization credentials.

The snet parameter is used for Rackspace’s ServiceNet internal network implementation. In this function, it simply adds snet- to the beginning of the host name for the returned storage URL. With Rackspace Cloud Files, use of this network path causes no bandwidth charges but requires the client to be running on Rackspace’s ServiceNet network.

swiftclient.client.get_auth_1_0(url, user, key, snet)
swiftclient.client.get_container(url, token, container, marker=None, limit=None, prefix=None, delimiter=None, http_conn=None, full_listing=False)

Get a listing of objects for the container.

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name to get a listing for
  • marker – marker query
  • limit – limit query
  • prefix – prefix query
  • delimeter – string to delimit the queries on
  • http_conn – HTTP connection object (If None, it will create the conn object)
  • full_listing – if True, return a full listing, else returns a max of 10000 listings
Returns:

a tuple of (response headers, a list of objects) The response headers will be a dict and all header names will be lowercase.

Raises ClientException:
 

HTTP GET request failed

swiftclient.client.get_keystoneclient_2_0(auth_url, user, key, os_options, **kwargs)

Authenticate against a auth 2.0 server.

We are using the keystoneclient library for our 2.0 authentication.

swiftclient.client.get_object(url, token, container, name, http_conn=None, resp_chunk_size=None)

Get an object

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name that the object is in
  • name – object name to get
  • http_conn – HTTP connection object (If None, it will create the conn object)
  • resp_chunk_size – if defined, chunk size of data to read. NOTE: If you specify a resp_chunk_size you must fully read the object’s contents before making another request.
Returns:

a tuple of (response headers, the object’s contents) The response headers will be a dict and all header names will be lowercase.

Raises ClientException:
 

HTTP GET request failed

swiftclient.client.head_account(url, token, http_conn=None)

Get account stats.

Parameters:
  • url – storage URL
  • token – auth token
  • http_conn – HTTP connection object (If None, it will create the conn object)
Returns:

a dict containing the response’s headers (all header names will be lowercase)

Raises ClientException:
 

HTTP HEAD request failed

swiftclient.client.head_container(url, token, container, http_conn=None, headers=None)

Get container stats.

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name to get stats for
  • http_conn – HTTP connection object (If None, it will create the conn object)
Returns:

a dict containing the response’s headers (all header names will be lowercase)

Raises ClientException:
 

HTTP HEAD request failed

swiftclient.client.head_object(url, token, container, name, http_conn=None)

Get object info

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name that the object is in
  • name – object name to get info for
  • http_conn – HTTP connection object (If None, it will create the conn object)
Returns:

a dict containing the response’s headers (all header names will be lowercase)

Raises ClientException:
 

HTTP HEAD request failed

swiftclient.client.http_connection(url, proxy=None)

Make an HTTPConnection or HTTPSConnection

Parameters:
  • url – url to connect to
  • proxy – proxy to connect through, if any; None by default; str of the format ‘http://127.0.0.1:8888‘ to set one
Returns:

tuple of (parsed url, connection object)

Raises ClientException:
 

Unable to handle protocol scheme

swiftclient.client.http_log(args, kwargs, resp, body)
swiftclient.client.post_account(url, token, headers, http_conn=None)

Update an account’s metadata.

Parameters:
  • url – storage URL
  • token – auth token
  • headers – additional headers to include in the request
  • http_conn – HTTP connection object (If None, it will create the conn object)
Raises ClientException:
 

HTTP POST request failed

swiftclient.client.post_container(url, token, container, headers, http_conn=None)

Update a container’s metadata.

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name to update
  • headers – additional headers to include in the request
  • http_conn – HTTP connection object (If None, it will create the conn object)
Raises ClientException:
 

HTTP POST request failed

swiftclient.client.post_object(url, token, container, name, headers, http_conn=None)

Update object metadata

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name that the object is in
  • name – name of the object to update
  • headers – additional headers to include in the request
  • http_conn – HTTP connection object (If None, it will create the conn object)
Raises ClientException:
 

HTTP POST request failed

swiftclient.client.put_container(url, token, container, headers=None, http_conn=None)

Create a container

Parameters:
  • url – storage URL
  • token – auth token
  • container – container name to create
  • headers – additional headers to include in the request
  • http_conn – HTTP connection object (If None, it will create the conn object)
Raises ClientException:
 

HTTP PUT request failed

swiftclient.client.put_object(url, token=None, container=None, name=None, contents=None, content_length=None, etag=None, chunk_size=65536, content_type=None, headers=None, http_conn=None, proxy=None)

Put an object

Parameters:
  • url – storage URL
  • token – auth token; if None, no token will be sent
  • container – container name that the object is in; if None, the container name is expected to be part of the url
  • name – object name to put; if None, the object name is expected to be part of the url
  • contents – a string or a file like object to read object data from; if None, a zero-byte put will be done
  • content_length – value to send as content-length header; also limits the amount read from contents; if None, it will be computed via the contents or chunked transfer encoding will be used
  • etag – etag of contents; if None, no etag will be sent
  • chunk_size – chunk size of data to write; default 65536
  • content_type – value to send as content-type header; if None, no content-type will be set (remote end will likely try to auto-detect it)
  • headers – additional headers to include in the request, if any
  • http_conn – HTTP connection object (If None, it will create the conn object)
  • proxy – proxy to connect through, if any; None by default; str of the format ‘http://127.0.0.1:8888‘ to set one
Returns:

etag from server response

Raises ClientException:
 

HTTP PUT request failed

swiftclient.client.quote(value, safe='/')

Patched version of urllib.quote that encodes utf8 strings before quoting

This Page