code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
return container.set_object_metadata(obj, metadata, clear=clear, prefix=prefix)
def set_object_metadata(self, container, obj, metadata, clear=False, extra_info=None, prefix=None)
Accepts a dictionary of metadata key/value pairs and updates the specified object metadata with them. If 'clear' is True, any existing metadata is deleted and only the passed metadata is retained. Otherwise, the values passed here update the object's metadata. 'extra_info; is a...
3.597867
6.509856
0.55268
return self.manager.fetch(obj=self, include_meta=include_meta, chunk_size=chunk_size)
def get(self, include_meta=False, chunk_size=None)
Fetches the object from storage. If 'include_meta' is False, only the bytes representing the file is returned. Note: if 'chunk_size' is defined, you must fully read the object's contents before making another request. When 'include_meta' is True, what is returned from this met...
4.943524
5.38529
0.917968
return self.manager.download(self, directory, structure=structure)
def download(self, directory, structure=True)
Fetches the object from storage, and writes it to the specified directory. The directory must exist before calling this method. If the object name represents a nested folder structure, such as "foo/bar/baz.txt", that folder structure will be created in the target directory by default. I...
6.140723
8.93663
0.687141
return self.container.copy_object(self, new_container, new_obj_name=new_obj_name)
def copy(self, new_container, new_obj_name=None, extra_info=None)
Copies this object to the new container, optionally giving it a new name. If you copy to the same container, you must supply a different name.
4.159849
3.624659
1.147652
return self.container.move_object(self, new_container, new_obj_name=new_obj_name)
def move(self, new_container, new_obj_name=None, extra_info=None)
Works just like copy_object, except that this object is deleted after a successful copy. This means that this storage_object reference will no longer be valid.
3.994631
3.558875
1.122442
self.container.change_object_content_type(self, new_ctype=new_ctype, guess=guess)
def change_content_type(self, new_ctype, guess=False)
Copies object to itself, but applies a new content-type. The guess feature requires the container to be CDN-enabled. If not then the content-type must be supplied. If using guess with a CDN-enabled container, new_ctype can be set to None. Failure during the put will result in a swift exc...
5.78123
4.347228
1.329866
self.manager.remove_metadata_key(self, key, prefix=prefix)
def remove_metadata_key(self, key, prefix=None)
Removes the specified key from the storage object's metadata. If the key does not exist in the metadata, nothing is done.
4.695585
4.943568
0.949837
return self.container.get_temp_url(self, seconds=seconds, method=method)
def get_temp_url(self, seconds, method="GET")
Returns a URL that can be used to access this object. The URL will expire after `seconds` seconds. The only methods supported are GET and PUT. Anything else will raise an InvalidTemporaryURLMethod exception.
6.724138
6.839798
0.98309
name = utils.get_name(obj) uri = "/%s/%s" % (self.uri_base, name) resp, resp_body = self.api.method_head(uri) hdrs = resp.headers try: content_length = int(hdrs.get("content-length")) except (TypeError, ValueError): content_length = None ...
def get(self, obj)
Gets the information about the specified object. This overrides the base behavior, since Swift uses HEAD to get information, and GET to download the object.
2.666875
2.416943
1.103409
# First make sure that there is a content source. if (data, file_or_path) == (None, None): raise exc.NoContentSpecified("You must specify either a file path, " "an open file-like object, or a stream of bytes when " "creating an object.") ...
def create(self, file_or_path=None, data=None, obj_name=None, content_type=None, etag=None, content_encoding=None, content_length=None, ttl=None, chunked=False, metadata=None, chunk_size=None, headers=None, return_none=False)
Creates or replaces a storage object in this container. The content of the object can either be a stream of bytes (`data`), or a file on disk (`file_or_path`). The disk file can be either an open file-like object, or an absolute path to the file on disk. When creating object from a dat...
2.828344
2.851002
0.992053
if content_type is not None: headers["Content-Type"] = content_type if content_encoding is not None: headers["Content-Encoding"] = content_encoding if isinstance(content, six.string_types): fsize = len(content) else: if chunked: ...
def _upload(self, obj_name, content, content_type, content_encoding, content_length, etag, chunked, chunk_size, headers)
Handles the uploading of content, including working around the 5GB maximum file size.
2.485116
2.460336
1.010072
head_etag = headers.pop("ETag", "") if chunked: headers.pop("Content-Length", "") headers["Transfer-Encoding"] = "chunked" elif etag is None and content is not None: etag = utils.get_checksum(content) if etag: headers["ETag"] = eta...
def _store_object(self, obj_name, content, etag=None, chunked=False, chunk_size=None, headers=None)
Handles the low-level creation of a storage object and the uploading of the contents of that object.
2.701857
2.803168
0.963858
uri = "/%s/%s" % (self.uri_base, utils.get_name(obj)) if chunk_size: # Need the total size of the object if not isinstance(obj, StorageObject): obj = self.get(obj) obj_size = obj.total_bytes return self._fetch_chunker(uri, chunk_si...
def fetch(self, obj, include_meta=False, chunk_size=None, size=None, extra_info=None)
Fetches the object from storage. If 'include_meta' is False, only the bytes representing the stored object are returned. Note: if 'chunk_size' is defined, the 'include_meta' parameter is ignored. If 'size' is specified, only the first 'size' bytes of the object will be...
3.249452
3.381046
0.961079
pos = 0 total_bytes = 0 size = size or obj_size max_size = min(size, obj_size) while True: endpos = min(obj_size, pos + chunk_size - 1) headers = {"Range": "bytes=%s-%s" % (pos, endpos)} resp, resp_body = self.api.method_get(uri, heade...
def _fetch_chunker(self, uri, chunk_size, size, obj_size)
Returns a generator that returns an object in chunks.
2.799528
2.702543
1.035887
if nms is None: nms = self.api.list_object_names(self.name, full_listing=True) return self.api.bulk_delete(self.name, nms, async_=async_)
def delete_all_objects(self, nms, async_=False)
Deletes all objects from this container. By default the call will block until all objects have been deleted. By passing True for the 'async_' parameter, this method will not block, and instead return an object that can be used to follow the progress of the deletion. When deletion is com...
3.43675
3.883682
0.884921
if not os.path.isdir(directory): raise exc.FolderNotFound("The directory '%s' does not exist." % directory) obj_name = utils.get_name(obj) path, fname = os.path.split(obj_name) if structure: fullpath = os.path.join(directory, path) ...
def download(self, obj, directory, structure=True)
Fetches the object from storage, and writes it to the specified directory. The directory must exist before calling this method. If the object name represents a nested folder structure, such as "foo/bar/baz.txt", that folder structure will be created in the target directory by default. I...
2.478063
2.451976
1.010639
cname = utils.get_name(self.container) oname = utils.get_name(obj) headers = {} if email_addresses: email_addresses = utils.coerce_to_list(email_addresses) headers["X-Purge-Email"] = ", ".join(email_addresses) uri = "/%s/%s" % (cname, oname) ...
def purge(self, obj, email_addresses=None)
Removes a CDN-enabled object from public access before the TTL expires. Please note that there is a limit (at this time) of 25 such requests; if you need to purge more than that, you must contact support. If one or more email_addresses are included, an email confirming the purge is sent...
3.360952
3.681709
0.912878
uri = "/%s/%s" % (self.uri_base, utils.get_name(obj)) resp, resp_body = self.api.method_head(uri) ret = {} # Add the metadata prefix, if needed. if prefix is None: prefix = OBJECT_META_PREFIX low_prefix = prefix.lower() for hkey, hval in list(...
def get_metadata(self, obj, prefix=None)
Returns the metadata for the specified object as a dict.
3.835661
3.565875
1.075658
# Add the metadata prefix, if needed. if prefix is None: prefix = OBJECT_META_PREFIX massaged = _massage_metakeys(metadata, prefix) cname = utils.get_name(self.container) oname = utils.get_name(obj) new_meta = {} # Note that the API for object...
def set_metadata(self, obj, metadata, clear=False, prefix=None)
Accepts a dictionary of metadata key/value pairs and updates the specified object metadata with them. If 'clear' is True, any existing metadata is deleted and only the passed metadata is retained. Otherwise, the values passed here update the object's metadata. By default, the s...
3.830444
3.913226
0.978846
meta_dict = {key: ""} return self.set_metadata(obj, meta_dict)
def remove_metadata_key(self, obj, key)
Removes the specified key from the object's metadata. If the key does not exist in the metadata, nothing is done.
5.975452
5.733942
1.04212
ident = self.identity cdn_svc = ident.services.get("object_cdn") if cdn_svc: ep = cdn_svc.endpoints.get(self.region_name) if ep: self.cdn_management_url = ep.public_url
def _configure_cdn(self)
Initialize CDN-related endpoints, if available.
5.005318
4.361776
1.147541
self.list_containers = self.list_container_names self.get_all_containers = self.list self.get_container = self.get self.create_container = self.create self.delete_container = self.delete self.get_container_objects = self.list_container_objects self.get_co...
def _backwards_aliases(self)
In order to keep this backwards-compatible with previous versions, alias the old names to the new methods.
2.761735
2.374213
1.163221
if isinstance(item, six.string_types): item = super(StorageClient, self).get(item) return item
def get(self, item)
Returns the container whose name is provided as 'item'. If 'item' is not a string, the original item is returned unchanged.
4.897025
5.017166
0.976054
self._manager = ContainerManager(self, resource_class=Container, response_key="", uri_base="")
def _configure_manager(self)
Creates a manager to handle interacting with Containers.
24.98414
11.66826
2.141205
headers = self._manager.get_account_headers() acct_prefix = "x-account-" meta_prefix = ACCOUNT_META_PREFIX.lower() ret = {} for hkey, hval in list(headers.items()): lowkey = hkey.lower() if lowkey.startswith(acct_prefix): if not lo...
def get_account_details(self)
Returns a dictionary containing information about the account.
3.619965
3.498049
1.034853
headers = self._manager.get_account_headers() return (headers.get("x-account-container-count"), headers.get("x-account-bytes-used"))
def get_account_info(self)
Returns a tuple for the number of containers and total bytes in the account.
5.769352
3.834273
1.504679
return self._manager.set_account_metadata(metadata, clear=clear, prefix=prefix)
def set_account_metadata(self, metadata, clear=False, prefix=None, extra_info=None)
Accepts a dictionary of metadata key/value pairs and updates the account's metadata with them. If 'clear' is True, any existing metadata is deleted and only the passed metadata is retained. Otherwise, the values passed here update the account's metadata. By default, the standar...
4.738512
7.30611
0.648568
meta = self._cached_temp_url_key if not cached or not meta: key = "temp_url_key" meta = self.get_account_metadata().get(key) self._cached_temp_url_key = meta return meta
def get_temp_url_key(self, cached=True)
Returns the current TempURL key, or None if it has not been set. By default the value returned is cached. To force an API call to get the current value on the server, pass `cached=False`.
3.767442
3.62663
1.038827
if key is None: key = uuid.uuid4().hex meta = {"Temp-Url-Key": key} self.set_account_metadata(meta) self._cached_temp_url_key = key
def set_temp_url_key(self, key=None)
Sets the key for the Temporary URL for the account. It should be a key that is secret to the owner. If no key is provided, a UUID value will be generated and used. It can later be obtained by calling get_temp_url_key().
3.976249
4.084096
0.973593
return self._manager.get_temp_url(container, obj, seconds, method=method, key=key, cached=cached)
def get_temp_url(self, container, obj, seconds, method="GET", key=None, cached=True)
Given a storage object in a container, returns a URL that can be used to access that object. The URL will expire after `seconds` seconds. The only methods supported are GET and PUT. Anything else will raise an `InvalidTemporaryURLMethod` exception. If you have your Temporary URL key, y...
2.795475
3.900559
0.716686
return self._manager.list(limit=limit, marker=marker, end_marker=end_marker, prefix=prefix)
def list(self, limit=None, marker=None, end_marker=None, prefix=None)
List the containers in this account, using the parameters to control the pagination of containers, since by default only the first 10,000 containers are returned.
3.075173
3.621628
0.849113
return self._manager.make_public(container, ttl=ttl)
def make_container_public(self, container, ttl=None)
Enables CDN access for the specified container, and optionally sets the TTL for the container.
6.633934
10.320889
0.642768
return self._manager.list_containers_info(limit=limit, marker=marker)
def list_containers_info(self, limit=None, marker=None)
Returns a list of info on Containers. For each container, a dict containing the following keys is returned: \code name - the name of the container count - the number of objects in the container bytes - the total bytes in the container
4.032079
8.178046
0.493037
return self._manager.list_subdirs(container, limit=limit, marker=marker, prefix=prefix, delimiter=delimiter, full_listing=full_listing)
def list_container_subdirs(self, container, limit=None, marker=None, prefix=None, delimiter=None, full_listing=False)
Although you cannot nest directories, you can simulate a hierarchical structure within a single container by adding forward slash characters (/) in the object name. This method returns a list of all of these pseudo-subdirectories in the specified container.
2.437113
2.826604
0.862205
return self._manager.list_object_names(container, marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, full_listing=full_listing)
def list_container_object_names(self, container, limit=None, marker=None, prefix=None, delimiter=None, full_listing=False)
Returns the names of all the objects in the specified container, optionally limited by the pagination parameters.
2.511384
3.114272
0.806411
return self._manager.get_metadata(container, prefix=prefix)
def get_container_metadata(self, container, prefix=None)
Returns a dictionary containing the metadata for the container.
7.518631
6.615029
1.136598
return self._manager.set_metadata(container, metadata, clear=clear, prefix=prefix)
def set_container_metadata(self, container, metadata, clear=False, prefix=None)
Accepts a dictionary of metadata key/value pairs and updates the specified container metadata with them. If 'clear' is True, any existing metadata is deleted and only the passed metadata is retained. Otherwise, the values passed here update the container's metadata. By default,...
4.172832
7.441653
0.56074
return self._manager.delete_metadata(container, prefix=prefix)
def delete_container_metadata(self, container, prefix=None)
Removes all of thethe container's metadata. By default, all metadata beginning with the standard container metadata prefix ('X-Container-Meta-') is removed. If you wish to remove all metadata beginning with a different prefix, you must specify that prefix.
6.922988
11.803676
0.586511
return self._manager.get_object_metadata(container, obj, prefix=prefix)
def get_object_metadata(self, container, obj, prefix=None)
Returns the metadata for the specified object as a dict.
4.140017
3.708154
1.116463
self.set_object_metadata(container, obj, {key: ""}, prefix=prefix)
def remove_object_metadata_key(self, container, obj, key, prefix=None)
Removes the specified key from the storage object's metadata. If the key does not exist in the metadata, nothing is done.
4.19534
4.410747
0.951163
if full_listing: return self._manager.object_listing_iterator(container, prefix=prefix) return self._manager.list_objects(container, limit=limit, marker=marker, prefix=prefix, delimiter=delimiter, end_marker=end_marker)
def list_container_objects(self, container, limit=None, marker=None, prefix=None, delimiter=None, end_marker=None, full_listing=False)
Return a list of StorageObjects representing the objects in the container. You can use the marker, end_marker, and limit params to handle pagination, and the prefix and delimiter params to filter the objects returned. Also, by default only the first 10,000 objects are returned; if you s...
2.82057
2.839997
0.99316
return self._manager.delete_object_in_seconds(cont, obj, seconds)
def delete_object_in_seconds(self, cont, obj, seconds, extra_info=None)
Sets the object in the specified container to be deleted after the specified number of seconds. The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, and will not be modified with swiftclient info, since swiftclient is not used any more.
4.513969
6.028794
0.748735
return self.create_object(container, obj_name=obj_name, data=data, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, return_none=return_none, chunk_size=chunk_size, headers=headers, metadata=metadata)
def store_object(self, container, obj_name, data, content_type=None, etag=None, content_encoding=None, ttl=None, return_none=False, chunk_size=None, headers=None, metadata=None, extra_info=None)
Creates a new object in the specified container, and populates it with the given data. A StorageObject reference to the uploaded file will be returned, unless 'return_none' is set to True. The 'extra_info' parameter is included for backwards compatibility. It is no longer used at all, a...
1.58558
1.751278
0.905384
return self.create_object(container, file_or_path=file_or_path, obj_name=obj_name, content_type=content_type, etag=etag, content_encoding=content_encoding, ttl=ttl, headers=headers, metadata=metadata, return_none=return_none)
def upload_file(self, container, file_or_path, obj_name=None, content_type=None, etag=None, content_encoding=None, ttl=None, content_length=None, return_none=False, headers=None, metadata=None, extra_info=None)
Uploads the specified file to the container. If no name is supplied, the file's name will be used. Either a file path or an open file-like object may be supplied. A StorageObject reference to the uploaded file will be returned, unless 'return_none' is set to True. You may optionally set...
1.812768
2.138544
0.847665
return self._manager.fetch_object(container, obj, include_meta=include_meta, chunk_size=chunk_size, size=size)
def fetch_object(self, container, obj, include_meta=False, chunk_size=None, size=None, extra_info=None)
Fetches the object from storage. If 'include_meta' is False, only the bytes representing the stored object are returned. Note: if 'chunk_size' is defined, you must fully read the object's contents before making another request. If 'size' is specified, only the first 'size' byt...
2.567607
3.684901
0.696791
return self._manager.fetch_partial(container, obj, size)
def fetch_partial(self, container, obj, size)
Returns the first 'size' bytes of an object. If the object is smaller than the specified 'size' value, the entire object is returned.
5.037082
5.515052
0.913334
if chunk_size is None: chunk_size = DEFAULT_CHUNKSIZE class FetchChunker(object): def __init__(self, gen, verbose=False): self.gen = gen self.verbose = verbose self.processed = 0 self.count = 0...
def fetch_dlo(self, container, name, chunk_size=None, verbose=False)
Returns a list of 2-tuples in the form of (object_name, fetch_generator) representing the components of a multi-part DLO (Dynamic Large Object). Each fetch_generator object can be interated to retrieve its contents. This is useful when transferring a DLO from one object storage system ...
2.706154
2.67427
1.011922
return self._manager.download_object(container, obj, directory, structure=structure)
def download_object(self, container, obj, directory, structure=True)
Fetches the object from storage, and writes it to the specified directory. The directory must exist before calling this method. If the object name represents a nested folder structure, such as "foo/bar/baz.txt", that folder structure will be created in the target directory by default. I...
4.830221
7.074878
0.682728
return self._manager.delete(container, del_objects=del_objects)
def delete(self, container, del_objects=False)
Deletes the specified container. If the container contains objects, the command will fail unless 'del_objects' is passed as True. In that case, each object will be deleted first, and then the container.
5.171642
5.729047
0.902705
return self._manager.copy_object(container, obj, new_container, new_obj_name=new_obj_name, content_type=content_type)
def copy_object(self, container, obj, new_container, new_obj_name=None, content_type=None, extra_info=None)
Copies the object to the new container, optionally giving it a new name. If you copy to the same container, you must supply a different name. You can optionally change the content_type of the object by supplying that in the 'content_type' parameter. The 'extra_info' parameter is includ...
2.284712
2.844857
0.803102
return self._manager.move_object(container, obj, new_container, new_obj_name=new_obj_name, new_reference=new_reference, content_type=content_type)
def move_object(self, container, obj, new_container, new_obj_name=None, new_reference=False, content_type=None, extra_info=None)
Works just like copy_object, except that the source object is deleted after a successful copy. You can optionally change the content_type of the object by supplying that in the 'content_type' parameter. NOTE: any references to the original object will no longer be valid; you wi...
1.994057
2.419739
0.824079
return self._manager.change_object_content_type(container, obj, new_ctype, guess=guess)
def change_object_content_type(self, container, obj, new_ctype, guess=False, extra_info=None)
Copies object to itself, but applies a new content-type. The guess feature requires the container to be CDN-enabled. If not then the content-type must be supplied. If using guess with a CDN-enabled container, new_ctype can be set to None. Failure during the put will result in a swift exc...
3.466753
4.818812
0.719421
if not os.path.isdir(folder_path): raise exc.FolderNotFound("No such folder: '%s'" % folder_path) ignore = utils.coerce_to_list(ignore) total_bytes = utils.folder_size(folder_path, ignore) upload_key = str(uuid.uuid4()) self.folder_upload_status[upload_key] ...
def upload_folder(self, folder_path, container=None, ignore=None, ttl=None)
Convenience method for uploading an entire folder, including any sub-folders, to Cloud Files. All files will be uploaded to objects with the same name as the file. In the case of nested folders, files will be named with the full path relative to the base folder. E.g., if the folder you ...
3.144237
3.322566
0.946328
uploader = FolderUploader(folder_path, container, ignore, upload_key, self, ttl=ttl) uploader.start()
def _upload_folder_in_background(self, folder_path, container, ignore, upload_key, ttl=None)
Runs the folder upload in the background.
3.463044
3.121858
1.109289
cont = self.get_container(container) self._local_files = [] # Load a list of all the remote objects so we don't have to keep # hitting the service if verbose: log = logging.getLogger("pyrax") log.info("Loading remote object list (prefix=%s)", obje...
def sync_folder_to_container(self, folder_path, container, delete=False, include_hidden=False, ignore=None, ignore_timestamps=False, object_prefix="", verbose=False)
Compares the contents of the specified folder, and checks to make sure that the corresponding object is present in the specified container. If there is no remote object matching the local file, it is created. If a matching object exists, the etag is examined to determine if the object in...
2.564319
2.665746
0.961952
fnames = os.listdir(folder_path) ignore = utils.coerce_to_list(ignore) log = logging.getLogger("pyrax") if not include_hidden: ignore.append(".*") for fname in fnames: if utils.match_pattern(fname, ignore): self._sync_summary["igno...
def _sync_folder_to_container(self, folder_path, container, prefix, delete, include_hidden, ignore, ignore_timestamps, object_prefix, verbose)
This is the internal method that is called recursively to handle nested folder structures.
2.341596
2.347029
0.997685
objnames = set(cont.get_object_names(prefix=object_prefix, full_listing=True)) localnames = set(self._local_files) to_delete = list(objnames.difference(localnames)) self._sync_summary["deleted"] += len(to_delete) # We don't need to wait around for this to...
def _delete_objects_not_in_list(self, cont, object_prefix="")
Finds all the objects in the specified container that are not present in the self._local_files list, and deletes them.
6.054939
5.148809
1.175988
deleter = BulkDeleter(self, container, object_names) deleter.start() if async_: return deleter while not deleter.completed: time.sleep(self.bulk_delete_interval) return deleter.results
def bulk_delete(self, container, object_names, async_=False)
Deletes multiple objects from a container in a single call. The bulk deletion call does not return until all of the specified objects have been processed. For large numbers of objects, this can take quite a while, so there is an 'async_' parameter to give you the option to have this cal...
2.998366
3.26588
0.918088
if not self.cdn_management_url: raise exc.NotCDNEnabled("CDN is not enabled for this service.") cdn_uri = "%s%s" % (self.cdn_management_url, uri) mthd = self.method_dict.get(method.upper()) try: resp, resp_body = mthd(cdn_uri, *args, **kwargs) exc...
def cdn_request(self, uri, method, *args, **kwargs)
If the service supports CDN, use this method to access CDN-specific URIs.
3.138474
3.05296
1.02801
if utils.match_pattern(dirname, self.ignore): return False good_names = (nm for nm in fnames if not utils.match_pattern(nm, self.ignore)) for fname in good_names: if self.client._should_abort_folder_upload(self.upload_key): return ...
def upload_files_in_folder(self, dirname, fnames)
Handles the iteration across files within a folder.
3.565443
3.446651
1.034466
root_path, folder_name = os.path.split(self.root_folder) self.root_folder = os.path.join(root_path, folder_name) for dirname, _, fnames in os.walk(self.root_folder): self.upload_files_in_folder(dirname, fnames)
def run(self)
Starts the uploading thread.
3.311018
3.067882
1.079252
for num, option in enumerate(options): if attr: print("%s: %s" % (num, getattr(option, attr))) else: print("%s: %s" % (num, option)) # Add an escape option escape_opt = num + 1 print("%s: I want to exit!" % escape_opt) choice = six.moves.input("Selection:...
def option_chooser(options, attr=None)
Given an iterable, enumerate its contents for a user to choose from. If the optional `attr` is not None, that attribute in each iterated object will be printed. This function will exit the program if the user chooses the escape option.
3.468849
3.413865
1.016106
@wraps(fnc) def _wrapped(self, queue, *args, **kwargs): if not isinstance(queue, Queue): # Must be the ID queue = self._manager.get(queue) return fnc(self, queue, *args, **kwargs) return _wrapped
def assure_queue(fnc)
Converts a queue ID or name passed as the 'queue' parameter to a Queue object.
2.972323
2.585547
1.149592
return self._message_manager.delete(msg_id, claim_id=claim_id)
def delete_message(self, msg_id, claim_id=None)
Deletes the message whose ID matches the supplied msg_id from the specified queue. If the message has been claimed, the ID of that claim must be passed as the 'claim_id' parameter.
4.376747
5.642648
0.775655
return self._message_manager.list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
def list(self, include_claimed=False, echo=False, marker=None, limit=None)
Returns a list of messages for this queue. By default only unclaimed messages are returned; if you want claimed messages included, pass `include_claimed=True`. Also, the requester's own messages are not returned by default; if you want them included, pass `echo=True`. The 'mark...
3.796596
4.366702
0.869443
if not isinstance(claim, QueueClaim): claim = self._claim_manager.get(claim) return claim.messages
def list_by_claim(self, claim)
Returns a list of all the messages from this queue that have been claimed by the specified claim. The claim can be either a claim ID or a QueueClaim object.
7.611574
4.526918
1.681403
return self._claim_manager.claim(ttl, grace, count=count)
def claim_messages(self, ttl, grace, count=None)
Claims up to `count` unclaimed messages from this queue. If count is not specified, the default is to claim 10 messages. The `ttl` parameter specifies how long the server should wait before releasing the claim. The ttl value MUST be between 60 and 43200 seconds. The `grace` parameter i...
6.941947
10.530852
0.659201
return self._claim_manager.update(claim, ttl=ttl, grace=grace)
def update_claim(self, claim, ttl=None, grace=None)
Updates the specified claim with either a new TTL or grace period, or both.
4.738563
5.867446
0.807602
super(QueueMessage, self)._add_details(info) if self.href is None: return parsed = urllib.parse.urlparse(self.href) self.id = parsed.path.rsplit("/", 1)[-1] query = parsed.query if query: self.claim_id = query.split("claim_id=")[-1]
def _add_details(self, info)
The 'id' and 'claim_id' attributes are not supplied directly, but included as part of the 'href' value.
3.685663
2.768816
1.331133
msg_dicts = info.pop("messages", []) super(QueueClaim, self)._add_details(info) parsed = urllib.parse.urlparse(self.href) self.id = parsed.path.rsplit("/", 1)[-1] self.messages = [QueueMessage(self.manager._message_manager, item) for item in msg_dicts]
def _add_details(self, info)
The 'id' attribute is not supplied directly, but included as part of the 'href' value. Also, convert the dicts for messages into QueueMessage objects.
5.417894
3.91975
1.382204
return self._iterate_list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
def list(self, include_claimed=False, echo=False, marker=None, limit=None)
Need to form the URI differently, so we can't use the default list().
4.047204
3.606021
1.122346
ret = [] if limit is None: this_limit = MSG_LIMIT else: this_limit = min(MSG_LIMIT, limit) limit = limit - this_limit uri = "/%s?include_claimed=%s&echo=%s" % (self.uri_base, json.dumps(include_claimed), json.dumps(echo)) ...
def _iterate_list(self, include_claimed, echo, marker, limit)
Recursive method to work around the hard limit of 10 items per call.
2.763192
2.759976
1.001165
msg_id = utils.get_id(msg) if claim_id: uri = "/%s/%s?claim_id=%s" % (self.uri_base, msg_id, claim_id) else: uri = "/%s/%s" % (self.uri_base, msg_id) return self._delete(uri)
def delete(self, msg, claim_id=None)
Deletes the specified message from its queue. If the message has been claimed, the ID of that claim must be passed as the 'claim_id' parameter.
2.208487
2.235738
0.987811
ids = utils.coerce_to_list(ids) uri = "/%s?ids=%s" % (self.uri_base, ",".join(ids)) # The API is not consistent in how it returns message lists, so this # workaround is needed. curr_prkey = self.plural_response_key self.plural_response_key = "" # BROKEN: ...
def list_by_ids(self, ids)
If you wish to retrieve a list of messages from this queue and know the IDs of those messages, you can pass in a list of those IDs, and only the matching messages will be returned. This avoids pulling down all the messages in a queue and filtering on the client side.
5.99085
5.994991
0.999309
ids = utils.coerce_to_list(ids) uri = "/%s?ids=%s" % (self.uri_base, ",".join(ids)) return self.api.method_delete(uri)
def delete_by_ids(self, ids)
Deletes the messages whose IDs are passed in from this queue.
3.796714
3.376478
1.12446
if count is None: qs = "" else: qs = "?limit=%s" % count uri = "/%s%s" % (self.uri_base, qs) body = {"ttl": ttl, "grace": grace, } resp, resp_body = self.api.method_post(uri, body=body) if resp.status_code =...
def claim(self, ttl, grace, count=None)
Claims up to `count` unclaimed messages from this queue. If count is not specified, the default is to claim 10 messages. The `ttl` parameter specifies how long the server should wait before releasing the claim. The ttl value MUST be between 60 and 43200 seconds. The `grace` parameter i...
3.295189
3.443487
0.956934
body = {} if ttl is not None: body["ttl"] = ttl if grace is not None: body["grace"] = grace if not body: raise exc.MissingClaimParameters("You must supply a value for " "'ttl' or 'grace' when calling 'update()'") ur...
def update(self, claim, ttl=None, grace=None)
Updates the specified claim with either a new TTL or grace period, or both.
3.249983
3.406473
0.954061
if self.api.queue_exists(id_): return Queue(self, {"queue": {"name": id_, "id_": id_}}, key="queue") raise exc.NotFound("The queue '%s' does not exist." % id_)
def get(self, id_)
Need to customize, since Queues are not returned with normal response bodies.
6.48847
5.082392
1.276657
uri = "/%s/%s/stats" % (self.uri_base, utils.get_id(queue)) resp, resp_body = self.api.method_get(uri) return resp_body.get("messages")
def get_stats(self, queue)
Returns the message stats for the specified queue.
5.46012
4.09938
1.331938
uri = "/%s/%s/metadata" % (self.uri_base, utils.get_id(queue)) resp, resp_body = self.api.method_get(uri) return resp_body
def get_metadata(self, queue)
Returns the metadata for the specified queue.
4.740748
3.793853
1.249587
uri = "/%s/%s/metadata" % (self.uri_base, utils.get_id(queue)) if clear: curr = {} else: curr = self.get_metadata(queue) curr.update(metadata) resp, resp_body = self.api.method_put(uri, body=curr)
def set_metadata(self, queue, metadata, clear=False)
Accepts a dictionary and adds that to the specified queue's metadata. If the 'clear' argument is passed as True, any existing metadata is replaced with the new metadata.
3.439104
3.479112
0.9885
self._manager = QueueManager(self, resource_class=Queue, response_key="queue", uri_base="queues")
def _configure_manager(self)
Create the manager to handle queues.
23.502357
14.511688
1.619547
if self.client_id is None: self.client_id = os.environ.get("CLOUD_QUEUES_ID") if self.client_id: dct["Client-ID"] = self.client_id
def _add_custom_headers(self, dct)
Add the Client-ID header required by Cloud Queues
4.165482
2.283811
1.823917
try: return super(QueueClient, self)._api_request(uri, method, **kwargs) except exc.BadRequest as e: if ((e.code == "400") and (e.message == 'The "Client-ID" header is required.')): raise exc.QueueClientIDNotDefined("You must supply a ...
def _api_request(self, uri, method, **kwargs)
Any request that involves messages must define the client ID. This handles all failures due to lack of client ID and raises the appropriate exception.
4.999063
4.335226
1.153126
try: queue = self._manager.head(name) return True except exc.NotFound: return False
def queue_exists(self, name)
Returns True or False, depending on the existence of the named queue.
8.381172
8.223995
1.019112
if self.queue_exists(name): raise exc.DuplicateQueue("The queue '%s' already exists." % name) return self._manager.create(name)
def create(self, name)
Cloud Queues works differently, in that they use the name as the ID for the resource. So for create(), we need to check if a queue by that name exists already, and raise an exception if it does. If not, create the queue and return a reference object for it.
5.465692
4.213337
1.297236
return self._manager.set_metadata(queue, metadata, clear=clear)
def set_metadata(self, queue, metadata, clear=False)
Accepts a dictionary and adds that to the specified queue's metadata. If the 'clear' argument is passed as True, any existing metadata is replaced with the new metadata.
5.205521
5.702772
0.912805
return queue.delete_message(msg_id, claim_id=claim_id)
def delete_message(self, queue, msg_id, claim_id=None)
Deletes the message whose ID matches the supplied msg_id from the specified queue. If the message has been claimed, the ID of that claim must be passed as the 'claim_id' parameter.
3.630536
3.684683
0.985305
return queue.list(include_claimed=include_claimed, echo=echo, marker=marker, limit=limit)
def list_messages(self, queue, include_claimed=False, echo=False, marker=None, limit=None)
Returns a list of messages for the specified queue. By default only unclaimed messages are returned; if you want claimed messages included, pass `include_claimed=True`. Also, the requester's own messages are not returned by default; if you want them included, pass `echo=True`. ...
2.979385
4.370815
0.681654
return queue.claim_messages(ttl, grace, count=count)
def claim_messages(self, queue, ttl, grace, count=None)
Claims up to `count` unclaimed messages from the specified queue. If count is not specified, the default is to claim 10 messages. The `ttl` parameter specifies how long the server should wait before releasing the claim. The ttl value MUST be between 60 and 43200 seconds. The `grace` pa...
5.572802
7.266302
0.766938
return queue.update_claim(claim, ttl=ttl, grace=grace)
def update_claim(self, queue, claim, ttl=None, grace=None)
Updates the specified claim with either a new TTL or grace period, or both.
3.822627
4.423171
0.864228
self._flavor_manager = CloudCDNFlavorManager(self, uri_base="flavors", resource_class=CloudCDNFlavor, response_key=None, plural_response_key="flavors") self._services_manager = CloudCDNServiceManager(self, uri_base="services", resource_class=Cloud...
def _configure_manager(self)
Creates the Manager instances to handle monitoring.
3.666284
3.387218
1.082388
return self._services_manager.list(limit=limit, marker=marker)
def list_services(self, limit=None, marker=None)
List CDN services.
5.97255
6.200324
0.963264
return self._services_manager.create(name, flavor_id, domains, origins, restrictions, caching)
def create_service(self, name, flavor_id, domains, origins, restrictions=None, caching=None)
Create a new CDN service. Arguments: name: The name of the service. flavor_id: The ID of the flavor to use for this service. domains: A list of dictionaries, each of which has a required key "domain" and optional key "protocol" (the default protocol is ...
4.023293
8.291578
0.485226
self._services_manager.delete_assets(service_id, url, all)
def delete_assets(self, service_id, url=None, all=False)
Delete CDN assets Arguments: service_id: The ID of the service to delete from. url: The URL at which to delete assets all: When True, delete all assets associated with the service_id. You cannot specifiy both url and all.
5.328862
6.053626
0.880276
matching_endpoints = [] # We don't always get a service catalog back ... if "serviceCatalog" not in self.catalog["access"]: return None # Full catalog ... catalog = self.catalog["access"]["serviceCatalog"] for service in catalog: if servi...
def url_for(self, attr=None, filter_value=None, service_type=None, endpoint_type="publicURL", service_name=None, volume_service_name=None)
Fetches the public URL from the given service for a particular endpoint attribute. If none given, returns the first. See tests for sample service catalog.
2.970479
2.896686
1.025475
return self.manager.get_usage(self, start=start, end=end)
def get_usage(self, start=None, end=None)
Return the usage records for this load balancer. You may optionally include a start datetime or an end datetime, or both, which will limit the records to those on or after the start time, and those before or on the end time. These times should be Python datetime.datetime objects, Python ...
4.694037
4.405926
1.065392
for (key, val) in six.iteritems(info): if key == "nodes": val = [Node(parent=self, **nd) for nd in val] elif key == "sessionPersistence": val = val['persistenceType'] elif key == "cluster": val = val['name'] ...
def _add_details(self, info)
Override the base behavior to add Nodes, VirtualIPs, etc.
3.575487
3.031291
1.179526
return self.manager.update(self, name=name, algorithm=algorithm, protocol=protocol, halfClosed=halfClosed, port=port, timeout=timeout, httpsRedirect=httpsRedirect)
def update(self, name=None, algorithm=None, protocol=None, halfClosed=None, port=None, timeout=None, httpsRedirect=None)
Provides a way to modify the following attributes of a load balancer: - name - algorithm - protocol - halfClosed - port - timeout - httpsRedirect
1.957939
1.957497
1.000226
return self.manager.update_node(node, diff=diff)
def update_node(self, node, diff=None)
Updates the node's attributes.
5.590097
5.266268
1.061491