common package

Submodules

common.database module

Module that contains database interaction logic.

This module allows for interaction with a database, and can be run by itself. All database URL generic syntax components are assumed to be stored as environment variables at runtime. For more information about URL generic syntax see WIKI Docs

common.database.logger

The logger used to log information of module.

Type

logging.Logger

class common.database.Database[source]

Bases: object

Class that interacts with database.

This class provides further abstraction to a database object that performs database level operations.

SCHEME

Component of the URI that specifies the protocol.

Type

str

SCHEME_POST_FIX

Optional postfix of the SCHEME.

Type

str

DB_USERNAME

Part of the USER_INFO, specifying the database user username.

Type

str

DB_PASSWORD

Part of the USER_INFO, specifying the database user password.

Type

str

USER_INFO

Subcomponent of AUTHORITY that consists of username and password preceded by a colon :.

Type

str

BASE_HOST_NAME

Part of HOST that is proceded by a forward slash :code:`/’ and the database name, DB_NAME.

Type

str

DB_NAME

Part of HOST that specifies the name of the database to connect to.

Type

str

HOST

Subcomponent of AUTHORITY that consists of the BASE_HOST_NAME* and the DB_NAME.

Type

str

PORT

Optional subcomponent of AUTHORITY preceded by a colon :.

Type

str

AUTHORITY

Component of URI preceded by two forward slashes //.

Type

str

CONNECTION_OPTIONS

Component of URI that specifies the behavior of the client.

Type

str

URI

Uniform Resource Identifier for connecting to the database.

Type

str

DATABASE

The database object that performs database level operations.

Type

pymongo.database.Database

AUTHORITY: str = 'DB_USERNAME:DB_PASSWORD@DB_BASE_HOST_NAME/DB_NAME:DB_PORT'
BASE_HOST_NAME: str = 'DB_BASE_HOST_NAME'
CONNECTION_OPTIONS: str = 'DB_CONNECTION_OPTIONS'
DATABASE: pymongo.database.Database
DB_NAME: str = 'DB_NAME'
DB_PASSWORD: str = 'DB_PASSWORD'
DB_USERNAME: str = 'DB_USERNAME'
HOST: str = 'DB_BASE_HOST_NAME/DB_NAME'
PORT: str = 'DB_PORT'
SCHEME: str = 'DB_SCHEME'
SCHEME_POST_FIX: str = 'DB_SCHEME_POST_FIX'
URI: str = 'DB_SCHEMEDB_SCHEME_POST_FIX://DB_USERNAME:DB_PASSWORD@DB_BASE_HOST_NAME/DB_NAME:DB_PORT?DB_CONNECTION_OPTIONS'
USER_INFO: str = 'DB_USERNAME:DB_PASSWORD'
classmethod find(collection: str, query: dict)pymongo.cursor.Cursor[source]

Filters a collection with a query to find all matching documents.

Parameters
  • collection (str) – The collection to be queried.

  • query (dict) – The query to filter the collection with.

Returns

The cursor corresponding to the query.

Return type

pymongo.cursor.Cursor

classmethod find_one(collection: str, query: dict)pymongo.cursor.Cursor[source]

Filters a collection with a query to find matching a document.

Parameters
  • collection (str) – The collection to be queried.

  • query (dict) – The query to filter the collection with.

Returns

Cursor corresponding to the query.

Return type

pymongo.cursor.Cursor

classmethod initialize()[source]
classmethod insert(collection: str, data: dict)None[source]

Insert document into a database collection.

Parameters
  • collection (str) – The collection for document to be inserted into.

  • data (dict) – The document to be inserted into the collection.

classmethod remove(collection: str, query: dict)dict[source]

Filters a collection with a query to remove a matching document.

Parameters
  • collection (str) – The collection to be queried.

  • query (dict) – The query to filter the collection with.

Returns

Cursor corresponding to the query.

Return type

pymongo.cursor.Cursor

classmethod update(collection: str, query: dict, data: dict)None[source]

Filters a collection with a query to update a matching document.

Parameters
  • collection (str) – The collection to be queried.

  • query (dict) – The query to filter the collection with.

  • data (dict) – The document to be updated.

common.utils module

Module that contains a class with utility functions.

class common.utils.Utils[source]

Bases: object

Class that provides utility functions.

static check_hashed_password(password: str, hashed_password: str)bool[source]

Verifies if the provided password matches the hashed_password.

Parameters
  • password (str) – The password provided.

  • hashed_password (str) – The password stored.

Returns

True if passwords match, False otherwise.

Return type

bool

static email_is_valid(email: str)bool[source]

Checks if the email has valid email format.

Parameters

email (str) – The email to be validated.

Returns

True if email is valid, False otherwise.

Return type

bool

static hash_password(password: str)str[source]

Encrypts the provided password.

Parameters

password (str) – The password to be encrypted.

Returns

The encrypted password.

Return type

str

static random_string_generator(str_size=30, allowed_chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~')str[source]

Generates and returns a random string.

Parameters
  • str_size (str) – The size of the string to be generated.

  • allowed_chars (str) – The string containing the characters allowed.

Returns

The random string generated.

Return type

str

Module contents