mbe.misc package

Submodules

mbe.misc.aspect_utilities module

Created on Nov 6, 2012

@author: Nicklas Börjesson @node: Utilities to help creating aspects in AOP.

mbe.misc.aspect_utilities.alter_function_parameter_and_call(function_object, args, kwargs, name, value, err_if_not_set=None)[source]

Changes or sets the value of an argument, if present, and calls the function.

Parameters:
  • function_object – An instance of the called function
  • args – A list of arguments
  • kwargs – A dict of keyword arguments
  • name – Name of the parameter that should be set
  • value – Value to set that parameter to
  • err_if_not_set – If is set, raise as error if the argument isn’t present.
Returns:

The return value of the called function

mbe.misc.init module

The init module is responsible for initializing an MBE backend database.

mbe.misc.init.get_empty_db_da(_database_name, _json_schema_folders=None)[source]

Create an empty database. Drops any existing.

Parameters:
  • _database_name – The name of the database
  • _json_schema_folders – A list of application specific JSON schema folders
Returns:

A database access object for the database

mbe.misc.init.init_database(_database_name='test_database', _data_files=None, _json_schema_folders=None)[source]

Initialises a MBE database. Drops any existing databases and import the provided files

Parameters:
  • _database_name – The name of the database.
  • _data_files – A list of application specific additional files to import
  • _json_schema_folders – A list of application specific JSON schema folders
Returns:

A database access object for the database

mbe.misc.schema_mongodb module

This module serves as an extension for the JSON schema library. It is made in a similar extension-vein as seep (https://github.com/Julian/Seep)

class mbe.misc.schema_mongodb.MongodbValidator(resolver=None)[source]

Bases: object

The MongodbValidator class is a plug-in for JSON schema that converts objectId-formatted strings into actual ObjectId instances if the objectId property is present in the schema,

apply(data, mongodb_schema)[source]

Apply the MBE schema to the data.

Parameters:
  • data – A mongo schema
  • mongodb_schema – mongodb_schema: a mongodb_schema (JSON Schema with Seep properties)
Returns:

the affected data

check_schema(schema)[source]

Check a schema, raises ValidationError if validation failed and RefResolutionError if it can’t find a referenced file.

Parameters:schema – The schema to check.
init_classes()[source]

Initialize all dynamically defined classes

object_setter = None
validator_class = None

The object setter is called to change the value

mbe.misc.schema_mongodb.mbe_object_id(value)[source]

Converts a string value to a MongoDB object value.

Instead of generating a new value, which is the default behaviour of ObjectId(), it returns None if provided None, :param value: A string value. Can be empty. :return: None or a corresponding ObjectId-instance.

Module contents

The misc package contains miscellaneous usable utilities.