API

Core Class

class cabu.core.Cabu(import_name='cabu', db=None, *args, **kwargs)[source]
load_config(settings='cabu.default_settings')[source]

Get the given settings module to create a config dict in the class.

All variables defined in upper case in the settings module are imported in the directory and overrided by the corresponding environment variables.

Parameters:settings (Optional[str]) – A module path where stands the settings.

Drivers Class

cabu.drivers.load_chrome(config)[source]

Start Chrome webdriver with the given configuration.

Parameters:config (dict) – The configuration loaded previously in Cabu.
Returns:webdriver – An instance of Chrome webdriver.
Return type:selenium.webdriver
cabu.drivers.load_driver(config, vdisplay=None)[source]

Initialize a weddriver selected in config with given config.

Parameters:config (dict) – The configuration loaded previously in Cabu.
Returns:webdriver – An instance of selenium webdriver or None.
Return type:selenium.webdriver
cabu.drivers.load_firefox(config)[source]

Start Firefox webdriver with the given configuration.

Parameters:config (dict) – The configuration loaded previously in Cabu.
Returns:webdriver – An instance of Firefox webdriver.
Return type:selenium.webdriver
cabu.drivers.load_phantomjs(config)[source]

Start PhantomJS webdriver with the given configuration.

Parameters:config (dict) – The configuration loaded previously in Cabu.
Returns:webdriver – An instance of phantomJS webdriver.
Return type:selenium.webdriver
cabu.drivers.load_vdisplay(config)[source]

Initialize a vdisplay (Xvfb subprocess instance).

Parameters:config (dict) – The configuration loaded previously in Cabu.
Returns:An instance of Xvfb wrapper.
Return type:vdisplay
cabu.drivers.unload_driver(driver)[source]

Shutdown given webdriver instance.

Parameters:driver (selenium.webdriver) – The running webdriver.
cabu.drivers.unload_vdisplay(vdisplay)[source]

Shutdown given Xvfb instance.

Parameters:vdisplay (XvfbWrapper) – The running virtual X server.

Auth Module

cabu.auth.authenticate()[source]

Response helper for un-authorized attempts to access to the app.

Returns:response – A Flask Response object with a custom message and a 401 status.
Return type:object
cabu.auth.check_auth(username, password)[source]

Determines if the given params are similar to the ones stored on config.

This small function compares the given username and password to the ones and returning a boolean accordingly.

Parameters:
  • username (str) – The username used for basic_auth.
  • password (str) – The password used for basic_auth.
Returns:

auth – True if authorized, False if not.

Return type:

bool

cabu.auth.requires_admin(f)[source]

Decorator to define endpoints that requires Basic Auth.

Parameters:f (func) – An route function.
Returns:response – 401 if unauthorized. f (func): The route to call.
Return type:object

Bucket Class

class cabu.utils.bucket.Bucket(bucket_name, access_key, secret_key)[source]

Convenient class to export datas to an Amazon S3 bucket.

Parameters:
  • bucket_name (str) – The name of the bucket to export.
  • access_key (str) – The access_key of the owner of the bucket to export.
  • secret_key (str) – The secret_key of the owner of the bucket to export.
delete(filename)[source]

Delete the file on the distant S3 bucket with the given filename.

Parameters:filename (str) – A string representing the name of the file to delete.
Returns:response – The object returned by requests.
Return type:object
get(filename)[source]

Get the file on the distant S3 bucket with the given filename.

Parameters:filename (str) – A string representing the name of the file to get.
Returns:response – The object returned by requests.
Return type:object
put(filename, data)[source]

Put given datas in the file with the given filename in the S3 bucket.

Parameters:
  • filename (str) – A string representing the name of the file to store.
  • datas (str|object) – The datas to export.
Returns:

response – The object returned by requests.

Return type:

object

Cookies Class

class cabu.utils.cookies.CookieStorage(db)[source]

Interface between Cookies and Database.

Parameters:db (Database) – The Database class instance to wrap.
clean()[source]

Delete all the cookies stored in the database.

Returns:raw_result – The result of the cleaning.
Return type:str
delete(key)[source]

Delete the value of the given cookie key.

Parameters:key (str) – The name of the cookie key to delete.
Returns:raw_result – The result of the attempt to delete the cookie.
Return type:str
get(key)[source]

Get the value of the given cookie key.

Parameters:key (str) – The name of the cookie key to retrieve.
Returns:value – The value of the key or None if undefined.
Return type:str
set(key, value)[source]

Set the value of the defined cookie key.

Parameters:
  • key (str) – The name of the cookie key to set.
  • value (str) – The value associated to the cookie key to set.
Returns:

raw_result – The result of the attempt to store the cookie.

Return type:

str