Python: module commons

commons (version 0.0.9) | index commons.py

`This package implements a web server to run scripts or
executables from the command line and display the result
in a web interface.
This file implement commons functions and class for WebScripts package.`

Modules
`` |  |
json | ntpath | secrets |

Classes
`` |  | builtins.object Blacklist Session TokenCSRF collections.abc.Callable(builtins.object) CallableFile utils.DefaultNamespace(types.SimpleNamespace) Argument ScriptConfig User
class Argument(utils.DefaultNamespace)
`` | `Argument(required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) This class build argument for script.`
| Method resolution order: Argument utils.DefaultNamespace types.SimpleNamespace builtins.object Static methods defined here: get_command(name: str, argument: Dict[str, ~JsonValue]) -> List[Dict[str, ~JsonValue]] `This function return list for command line execution.` Data and other attributes defined here: __defaults__ = {'default_value': None, 'description': None, 'example': None, 'html_type': 'text', 'input': None, 'is_advanced': False, 'javascript_attributs': {}} __optional__ = ['list', 'input', 'example', 'html_type', 'is_advanced', 'description', 'default_value', 'predefined_values', 'javascript_attributs'] __required__ = ['name'] __types__ = {'input': <class 'bool'>, 'is_advanced': <class 'bool'>, 'list': <class 'bool'>, 'predefined_values': <class 'list'>} Methods inherited from utils.DefaultNamespace: __getitem__(self, key: str) `Compatibility with dict.` __init__(self, required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) `Initialize self. See help(type(self)) for accurate signature.` build_types(self) -> None `This function build type from configuration values.` check_required(self) -> None `This function checks required attributes if one of required attributes is missing this function raise MissingAttributesError.` export_as_json(self, name: str = None) -> None `This function export namespace values (useful for debugging).` get(self, key: str, default=None) `Compatibility with dict.` get_dict(self) -> None `This function return a dict of attributes.` get_missings(self) -> List[str] `This function checks required attributes and return a List[str] of missing required attributes.` get_unexpecteds(self, log: bool = True) -> List[str] `This function return a List[str] of all attributes not in optional and required attributes. If log argument is True a Warning log message is write for all unexpected attributes.` set_defaults(self) -> None `This function set defaults attribut with defaults values.` update(self, **kwargs) `This function add/update attributes with **kwargs arguments.` Class methods inherited from utils.DefaultNamespace: default_build(**kwargs) -> ~DefaultNamespace from builtins.type `Default build for DefaultNamespace (set defaults, add values, check requirements and unexpected values and build types).` Data descriptors inherited from utils.DefaultNamespace: __weakref__ `list of weak references to the object (if defined)` Methods inherited from types.SimpleNamespace: __delattr__(self, name, /) `Implement delattr(self, name).` __eq__(self, value, /) `Return self==value.` __ge__(self, value, /) `Return self>=value.` __getattribute__(self, name, /) `Return getattr(self, name).` __gt__(self, value, /) `Return self>value.` __le__(self, value, /) `Return self<=value.` __lt__(self, value, /) `Return self<value.` __ne__(self, value, /) `Return self!=value.` __reduce__(...) `Return state information for pickling` __repr__(self, /) `Return repr(self).` __setattr__(self, name, value, /) `Implement setattr(self, name, value).` Static methods inherited from types.SimpleNamespace: __new__(*args, **kwargs) from builtins.type `Create and return a new object. See help(type) for accurate signature.` Data descriptors inherited from types.SimpleNamespace: __dict__ Data and other attributes inherited from types.SimpleNamespace: __hash__ = None
class Blacklist(builtins.object)
`` | `Blacklist(configuration: ~ServerConfiguration, last_blacklist: ~Blacklist = None) This class implement blacklist.`
| Methods defined here: __init__(self, configuration: ~ServerConfiguration, last_blacklist: ~Blacklist = None) `Initialize self. See help(type(self)) for accurate signature.` __str__(self) -> str `This function returns a string to represent the Blacklist object.` is_blacklist(self, configuration: ~ServerConfiguration) `This function return True if this object is blacklisted.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class CallableFile(collections.abc.Callable)
`` | `CallableFile(type_: str, path_: str, filename: str, config: dict = None) This class build callable object to return Web files content or script output.`
| Method resolution order: CallableFile collections.abc.Callable builtins.object Methods defined here: __call__(self, user: commons.User) -> Tuple[str, Dict[str, str], List[bytes]] `Call self as a function.` __init__(self, type_: str, path_: str, filename: str, config: dict = None) `Initialize self. See help(type(self)) for accurate signature.` is_html(self) -> bool `This function compare extension with html extensions.` is_jpeg(self) -> bool `This function compare extension with jpeg extensions.` is_tiff(self) -> bool `This function compare extension with tif extensions.` is_xml(self) -> bool `This function compare extension with xml extensions.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Data and other attributes defined here: __abstractmethods__ = frozenset() __annotations__ = {'template_index': <class 'str'>, 'template_script': <class 'str'>} template_index = '<!--\n\n HTML page for index.\n Copyright (C)...ipts(build_categories);</script>\n\t</body>\n</html>' template_script = '<!--\n\n HTML page to launch scripts.\n Copyr...);\n\t\t\tadd_buttons();\n\t\t</script>\n\t</body>\n</html>' Class methods inherited from collections.abc.Callable: __class_getitem__ = _CallableGenericAlias(args) from abc.ABCMeta `Represent `Callable[argtypes, resulttype]`. This sets ``__args__`` to a tuple containing the flattened``argtypes`` followed by ``resulttype``. Example: ``Callable[[int, str], float]`` sets ``__args__`` to ``(int, str, float)``.` __subclasshook__(C) from abc.ABCMeta `Abstract classes can override this to customize issubclass(). This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).`
class ScriptConfig(utils.DefaultNamespace)
`` | `ScriptConfig(required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) This class get script config.`
| Method resolution order: ScriptConfig utils.DefaultNamespace types.SimpleNamespace builtins.object Methods defined here: build_args(self, configuration: ~Configuration) `This function build Arguments from self.args: List[Dict[str, str]]` get_JSON_API(self) -> Dict `This function return a dict for JSON API (visible configuration for user).` Class methods defined here: build_scripts_from_configuration(server_configuration: ~ServerConfiguration) -> Dict[str, ~ScriptConfig] from builtins.type `This function build scripts from server configuration and configurations files.` get_scripts_from_configuration(configuration: ~Configuration, server_configuration: ~ServerConfiguration) -> Dict[str, ~ScriptConfig] from builtins.type `This function build scripts from ServerConfiguration.` Static methods defined here: get_Windows_default_script_launcher(script_config: Dict[str, ~JsonValue]) -> str `This function get the Windows default launcher to execute a file.` get_arguments_from_config(arguments_section: str, configuration: Dict[str, Dict[str, ~JsonValue]]) -> List[Dict[str, ~JsonValue]] `This function get arguments list of script.` get_docfile_from_configuration(configuration: ~ServerConfiguration, filename: str) -> str get_documentation_from_configuration(script_config: Dict[str, ~JsonValue], name: str, paths: List[str]) -> str `This function get documentation from script configuration or search it in documentation path.` get_script_config_from_specific_file_config(script_config: Dict[str, ~JsonValue], configuration: Dict[str, ~JsonValue]) -> Tuple[dict, dict] `This function return all configuration and script configuration from configuration.` get_script_path(server_configuration: ~ServerConfiguration, script_config: Dict[str, ~JsonValue]) -> str `This function return a script path from configuration.` Data and other attributes defined here: __defaults__ = {'access_groups': None, 'access_users': None, 'args': [], 'category': '', 'command_generate_documentation': None, 'content_type': 'text/plain', 'description': None, 'documentation_content_type': 'text/html', 'documentation_file': None, 'launcher': None, ...} __optional__ = ['command_generate_documentation', 'documentation_content_type', 'documentation_file', 'minimum_access', 'access_groups', 'content_type', 'access_users', 'no_password', 'description', 'category', 'launcher', 'timeout', 'path', 'args'] __required__ = ['name', 'dirname'] __types__ = {'access_groups': typing.List[int], 'access_users': typing.List[int], 'minimum_access': <class 'int'>, 'no_password': <class 'bool'>, 'timeout': <class 'int'>} Methods inherited from utils.DefaultNamespace: __getitem__(self, key: str) `Compatibility with dict.` __init__(self, required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) `Initialize self. See help(type(self)) for accurate signature.` build_types(self) -> None `This function build type from configuration values.` check_required(self) -> None `This function checks required attributes if one of required attributes is missing this function raise MissingAttributesError.` export_as_json(self, name: str = None) -> None `This function export namespace values (useful for debugging).` get(self, key: str, default=None) `Compatibility with dict.` get_dict(self) -> None `This function return a dict of attributes.` get_missings(self) -> List[str] `This function checks required attributes and return a List[str] of missing required attributes.` get_unexpecteds(self, log: bool = True) -> List[str] `This function return a List[str] of all attributes not in optional and required attributes. If log argument is True a Warning log message is write for all unexpected attributes.` set_defaults(self) -> None `This function set defaults attribut with defaults values.` update(self, **kwargs) `This function add/update attributes with **kwargs arguments.` Class methods inherited from utils.DefaultNamespace: default_build(**kwargs) -> ~DefaultNamespace from builtins.type `Default build for DefaultNamespace (set defaults, add values, check requirements and unexpected values and build types).` Data descriptors inherited from utils.DefaultNamespace: __weakref__ `list of weak references to the object (if defined)` Methods inherited from types.SimpleNamespace: __delattr__(self, name, /) `Implement delattr(self, name).` __eq__(self, value, /) `Return self==value.` __ge__(self, value, /) `Return self>=value.` __getattribute__(self, name, /) `Return getattr(self, name).` __gt__(self, value, /) `Return self>value.` __le__(self, value, /) `Return self<=value.` __lt__(self, value, /) `Return self<value.` __ne__(self, value, /) `Return self!=value.` __reduce__(...) `Return state information for pickling` __repr__(self, /) `Return repr(self).` __setattr__(self, name, value, /) `Implement setattr(self, name, value).` Static methods inherited from types.SimpleNamespace: __new__(*args, **kwargs) from builtins.type `Create and return a new object. See help(type) for accurate signature.` Data descriptors inherited from types.SimpleNamespace: __dict__ Data and other attributes inherited from types.SimpleNamespace: __hash__ = None
class Session(builtins.object)
`` | `Session(user: commons.User, ip: str) Object to implement session.`
| Methods defined here: __init__(self, user: commons.User, ip: str) `Initialize self. See help(type(self)) for accurate signature.` __str__(self) -> str `This function returns a string to represent the Session object.` Class methods defined here: build_session(user: commons.User, ip: str, Pages: ~Pages) -> str from builtins.type `This function build and add session and return the cookie.` Static methods defined here: check_session(cookie: str, pages: ~Pages, ip: str, default_user: commons.User) -> commons.User `This function check session validity and return user.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class TokenCSRF(builtins.object)
`` | `This class brings together the functions related to the CSRF token`
| Static methods defined here: build_token(user: commons.User) -> str `This function build a CSRF token for a user.` check_csrf(user: commons.User, token: str) -> bool `This function check the validity of a csrf token.` clean(user: commons.User, max_time: float) -> None `This function clean all old CSRF tokens for a user.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class User(utils.DefaultNamespace)
`` | `User(required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) This class implement User object`
| Method resolution order: User utils.DefaultNamespace types.SimpleNamespace builtins.object Data and other attributes defined here: __defaults__ = {'categories': ['*'], 'check_csrf': False, 'csrf': {}, 'groups': [], 'scripts': ['*']} __required__ = ['id', 'name', 'groups', 'csrf', 'ip', 'categories', 'scripts', 'check_csrf'] __types__ = {'categories': <class 'list'>, 'check_csrf': <class 'bool'>, 'groups': typing.List[int], 'id': <class 'int'>, 'scripts': <class 'list'>} Methods inherited from utils.DefaultNamespace: __getitem__(self, key: str) `Compatibility with dict.` __init__(self, required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) `Initialize self. See help(type(self)) for accurate signature.` build_types(self) -> None `This function build type from configuration values.` check_required(self) -> None `This function checks required attributes if one of required attributes is missing this function raise MissingAttributesError.` export_as_json(self, name: str = None) -> None `This function export namespace values (useful for debugging).` get(self, key: str, default=None) `Compatibility with dict.` get_dict(self) -> None `This function return a dict of attributes.` get_missings(self) -> List[str] `This function checks required attributes and return a List[str] of missing required attributes.` get_unexpecteds(self, log: bool = True) -> List[str] `This function return a List[str] of all attributes not in optional and required attributes. If log argument is True a Warning log message is write for all unexpected attributes.` set_defaults(self) -> None `This function set defaults attribut with defaults values.` update(self, **kwargs) `This function add/update attributes with **kwargs arguments.` Class methods inherited from utils.DefaultNamespace: default_build(**kwargs) -> ~DefaultNamespace from builtins.type `Default build for DefaultNamespace (set defaults, add values, check requirements and unexpected values and build types).` Data descriptors inherited from utils.DefaultNamespace: __weakref__ `list of weak references to the object (if defined)` Methods inherited from types.SimpleNamespace: __delattr__(self, name, /) `Implement delattr(self, name).` __eq__(self, value, /) `Return self==value.` __ge__(self, value, /) `Return self>=value.` __getattribute__(self, name, /) `Return getattr(self, name).` __gt__(self, value, /) `Return self>value.` __le__(self, value, /) `Return self<=value.` __lt__(self, value, /) `Return self<value.` __ne__(self, value, /) `Return self!=value.` __reduce__(...) `Return state information for pickling` __repr__(self, /) `Return repr(self).` __setattr__(self, name, value, /) `Implement setattr(self, name, value).` Static methods inherited from types.SimpleNamespace: __new__(*args, **kwargs) from builtins.type `Create and return a new object. See help(type) for accurate signature.` Data descriptors inherited from types.SimpleNamespace: __dict__ Data and other attributes inherited from types.SimpleNamespace: __hash__ = None

Data
`` |  | JsonValue = ~JsonValue ServerConfiguration = ~ServerConfiguration __all__ = ['User', 'Session', 'Argument', 'JsonValue', 'TokenCSRF', 'Blacklist', 'ScriptConfig', 'CallableFile', 'ServerConfiguration'] __author_email__ = 'mauricelambert434@gmail.com' __copyright__ = '\nWebScripts Copyright (C) 2021 Maurice Lambert...ome to redistribute it\nunder certain conditions.\n' __description__ = 'This package implements a web server to run scri...mmons functions and class for WebScripts package.' __license__ = 'GPL-3.0 License' __maintainer__ = 'Maurice Lambert' __maintainer_email__ = 'mauricelambert434@gmail.com' __url__ = 'https://github.com/mauricelambert/WebScripts'

Author
`` |  | Maurice Lambert