redirectory.libs_int.hyperscan.hs_actions module

redirectory.libs_int.hyperscan.hs_actions.get_expressions_ids_flags(db_model: sqlalchemy.ext.declarative.api.DeclarativeMeta, expression_path: str, expression_regex_path: str, id_path: str, combine_expr_with: str = None) → Tuple[List[bytes], List[int], List[int]][source]

Gets the expression in the correct format from the database. Depending on the arguments the expression can be combined with another piece of data. The expression will also be regex escaped if it is a literal. If the expression is a regex then a second check will be conducted which checks if the expression matches an empty string. If so a different flag than the default is applied.

Parameters:
  • db_model – The model/table of the current database
  • expression_path – The attribute where the expression can be found in the model
  • expression_regex_path – The attribute holding the value if an expression is regex or not
  • id_path – The attribute where the id can be found
  • combine_expr_with – The attribute of extra piece of data that can be appended before the expression
Returns:

a tuple containing the expressions, the ids and the flags. tuple(expressions, ids, flags)

redirectory.libs_int.hyperscan.hs_actions.get_hs_db_version() → Tuple[Optional[str], Optional[str]][source]

Queries the database for the HsDbVersion table which only has one entry at all times. Return the two numbers which represent the old_version and the current_version of the Hyperscan database.

Returns:tuple of old_version and new_version of the Hyperscan Database
redirectory.libs_int.hyperscan.hs_actions.get_timestamp() → str[source]

Gets the current date and time and converts it to epoch

Returns:an epoch string
redirectory.libs_int.hyperscan.hs_actions.multi_getattr(obj, attr, default=None)[source]

Get a named attribute from an object; multi_getattr(x, ‘a.b.c.d’) is equivalent to x.a.b.c.d. When a default argument is given, it is returned when any attribute in the chain doesn’t exist; without it, an exception is raised when a missing attribute is encountered.

redirectory.libs_int.hyperscan.hs_actions.update_hs_db_version(new_db_version: str = None) → str[source]

Updates the SQLite3 database about the new version of Hyperscan database.

Returns:the new version of the hyperscan database