Sanitize a dictionary containing HTTP headers of sensitive values.

Parameters:headers (dict) – The headers to sanitize.
Returns:A list of headers without sensitive information stripped out.
Return type:dict

Flatten a series of keyword arguments from complex combinations of dictionaries and lists into a list of tuples representing properly-formatted parameters to pass to the Requester object.

Parameters:kwargs (dict) – A dictionary containing keyword arguments to be flattened into properly-formatted parameters.
Returns:A list of tuples that represent flattened kwargs. The first element is a string representing the key. The second element is the value.
Return type:list of tuple

Open a file and return the handler if a path is given. If a file handler is given, return it directly.

Parameters:file – A file handler or path to a file.
Returns:A tuple with the open file handler and whether it was a path.
Return type:(file, bool)
canvasapi.util.flatten_kwarg(key, obj)

Recursive call to flatten sections of a kwarg to be combined

  • key (str) – The partial keyword to add to the full keyword
  • obj – The object to translate into a kwarg. If the type is dict, the key parameter will be added to the keyword between square brackets and recursively call this function. If the type is list, or tuple, a set of empty brackets will be appended to the keyword and recursively call this function. Otherwise, the function returns with the final keyword and value.

A list of tuples that represent flattened kwargs. The first element is a string representing the key. The second element is the value.

Return type:

list of tuple


Clean up a given base URL.

Parameters:base_url (str) – The base URL of the API.
Return type:str

Determine whether the given value should be treated as a sequence of multiple values when used as a request parameter.

In general anything that is iterable is multivalued. For example, list and tuple instances are multivalued. Generators are multivalued, as are the iterable objects returned by zip, itertools.chain, etc. However, a simple int is single-valued. str and bytes are special cases: although these are iterable, we treat each as a single value rather than as a sequence of isolated characters or bytes.

canvasapi.util.normalize_bool(val, param_name)

Normalize boolean-like strings to their corresponding boolean values.

  • val (str or bool) – Value to normalize. Acceptable values: True, “True”, “true”, False, “False”, “false”
  • param_name (str) – Name of the parameter being checked
Return type:


canvasapi.util.obj_or_id(parameter, param_name, object_types)

Accepts either an int (or long or str representation of an integer) or an object. If it is an int, return it. If it is an object and the object is of correct type, return the object’s id. Otherwise, throw an exception.

  • parameter – int, str, long, or object
  • param_name – str
  • object_types – tuple
Return type:


canvasapi.util.obj_or_str(obj, attr, object_types)

Accepts an object. If the object has the attribute, return the corresponding string. Otherwise, throw an exception.

  • obj (object) – object from which to retrieve attribute
  • attr (str) – name of the attribute to retrieve
  • object_types (tuple) – tuple containing the types of the object being passed in
Return type: