tools

tools.check_string(in_str)[source]

Sanatize data :param in_str: List or string of strings to be validated :return boolean:

tools.create_command_obj(session_id, command)[source]

Generate a properly formatted command object

Parameters:
  • session_id
  • command
Return command object:
 
tools.dump_events(events, db)[source]

Dump events :param events: :param db:

tools.fold(string, line_length=120, indent=0, indent_first_line=False, _runs=0)[source]

Fold a string into multiple Lines. Fold function by Max Ertl (https://github.com/Sirs0ri)

Parameters:
  • string – The string you want to fold.
  • line_length – The desired max line length (int)
  • indent – if you want lines to be indented, you can specify the number of spaces here
  • indent_first_line – if this is True, the first line won’t be indented.
Return formatted string:
 
tools.gen_command_uid()[source]

Generate a 16 character url safe base64 string

Return urlsafe base64 string:
 
tools.gen_session(username, client_type, db)[source]
Parameters:
  • username
  • client
Returns:

session_id

tools.get_command_id(session_id)[source]

Incrementing command ids based on the session id

Parameters:session_id
Return command_id:
 
tools.get_event_uid(type)[source]

Get an event uid using the event type :param type: :return: Event uid string

tools.get_session_id(db)[source]

Incrementer for session ids :param db:

tools.get_user_token(username)[source]

Get a customized user token to store encrypted in the cookies

Parameters:username
Return user_token:
 
tools.initialize_session_tracking(db)[source]

Deprecated and out of use

Parameters:db
tools.load_key(key_type, db, load_url=False)[source]

Load a key from the database and implement the cycler

Parameters:
  • key_type
  • db
  • load_url
Return api key:
tools.return_json(response)[source]

Render a response object as json, assert that it has all the correct keys, and return it

Parameters:response
Return json string:
 
tools.set_response(session_id, command_id, event, response_function)[source]

Set a response listener in the session object

Parameters:
  • session_id
  • command_id
  • event
  • response_function