Python: module utils

utils (version 0.1.0) | index utils.py

`This tools run scripts and display the result in a Web Interface.
This file implement some tools for WebScripts server
and scripts (Logs, Namespace for configuration, ...).`

Modules
`` |  |
gzip json | locale logging | ntpath platform | win32evtlog

Classes
`` |  | logging.handlers.RotatingFileHandler(logging.handlers.BaseRotatingHandler) CustomLogHandler types.SimpleNamespace(builtins.object) DefaultNamespace _Logs(builtins.object) WindowsLogs
class CustomLogHandler(logging.handlers.RotatingFileHandler)
`` | `CustomLogHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None) This class is a custom logging handler.`
| Method resolution order: CustomLogHandler logging.handlers.RotatingFileHandler logging.handlers.BaseRotatingHandler logging.FileHandler logging.StreamHandler logging.Handler logging.Filterer builtins.object Methods defined here: doRollover(self) `Do a rollover, as described in __init__().` namer(self, name: str) -> str `This function returns the new name of the old log files.` rotator(self, source: str, destination: str) -> None `This function compresses old log files.` Methods inherited from logging.handlers.RotatingFileHandler: __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None) `Open the specified file and use it as the stream for logging. By default, the file grows indefinitely. You can specify particular values of maxBytes and backupCount to allow the file to rollover at a predetermined size. Rollover occurs whenever the current log file is nearly maxBytes in length. If backupCount is >= 1, the system will successively create new files with the same pathname as the base file, but with extensions ".1", ".2" etc. appended to it. For example, with a backupCount of 5 and a base file name of "app.log", you would get "app.log", "app.log.1", "app.log.2", ... through to "app.log.5". The file being written to is always "app.log" - when it gets filled up, it is closed and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc. exist, then they are renamed to "app.log.2", "app.log.3" etc. respectively. If maxBytes is zero, rollover never occurs.` shouldRollover(self, record) `Determine if rollover should occur. Basically, see if the supplied record would cause the file to exceed the size limit we have.` Methods inherited from logging.handlers.BaseRotatingHandler: emit(self, record) `Emit a record. Output the record to the file, catering for rollover as described in doRollover().` rotate(self, source, dest) `When rotating, rotate the current log. The default implementation calls the 'rotator' attribute of the handler, if it's callable, passing the source and dest arguments to it. If the attribute isn't callable (the default is None), the source is simply renamed to the destination. :param source: The source filename. This is normally the base filename, e.g. 'test.log' :param dest: The destination filename. This is normally what the source is rotated to, e.g. 'test.log.1'.` rotation_filename(self, default_name) `Modify the filename of a log file when rotating. This is provided so that a custom filename can be provided. The default implementation calls the 'namer' attribute of the handler, if it's callable, passing the default name to it. If the attribute isn't callable (the default is None), the name is returned unchanged. :param default_name: The default name for the log file.` Methods inherited from logging.FileHandler: __repr__(self) `Return repr(self).` close(self) `Closes the stream.` Methods inherited from logging.StreamHandler: flush(self) `Flushes the stream.` setStream(self, stream) `Sets the StreamHandler's stream to the specified value, if it is different. Returns the old stream, if the stream was changed, or None if it wasn't.` Data and other attributes inherited from logging.StreamHandler: terminator = '\n' Methods inherited from logging.Handler: acquire(self) `Acquire the I/O thread lock.` createLock(self) `Acquire a thread lock for serializing access to the underlying I/O.` format(self, record) `Format the specified record. If a formatter is set, use it. Otherwise, use the default formatter for the module.` get_name(self) handle(self, record) `Conditionally emit the specified logging record. Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.` handleError(self, record) `Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.` release(self) `Release the I/O thread lock.` setFormatter(self, fmt) `Set the formatter for this handler.` setLevel(self, level) `Set the logging level of this handler. level must be an int or a str.` set_name(self, name) Data descriptors inherited from logging.Handler: name Methods inherited from logging.Filterer: addFilter(self, filter) `Add the specified filter to this handler.` filter(self, record) `Determine if a record is loggable by consulting all the filters. The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero. .. versionchanged:: 3.2 Allow filters to be just callables.` removeFilter(self, filter) `Remove the specified filter from this handler.` Data descriptors inherited from logging.Filterer: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class DefaultNamespace(types.SimpleNamespace)
`` | `DefaultNamespace(required: List[str] = [], optional: List[str] = [], default: dict = {}, types: dict = {}) This class build simple namespace with default attributs.`
| Method resolution order: DefaultNamespace types.SimpleNamespace builtins.object Methods defined here: __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 defined here: 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 defined here: __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
Logs = class WindowsLogs(_Logs)
`` | `This class log on Windows.`
| Method resolution order: WindowsLogs _Logs builtins.object Methods defined here: critical(log: str) -> None `This function log criticals on Windows.` debug(log: str) -> None `This function log debugs on Windows.` error(log: str) -> None `This function log errors on Windows.` info(log: str) -> None `This function log infos on Windows.` warning(log: str) -> None `This function log warnings on Windows.` Data and other attributes defined here: __annotations__ = {'app': <class 'str'>} app = 'WebScripts' Methods inherited from _Logs: config(*args, **kwargs) `This function config ROOT logger.` exception(log: str) -> None `This function implement basic python exception (error) logs for WebScripts.` trace(log: str) -> None `This function implement trace logs for WebScripts.` Data descriptors inherited from _Logs: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Data and other attributes inherited from _Logs: console = <Logger WebScripts.console (WARNING)> file = <Logger WebScripts.file (WARNING)> log_critical = <Logger WebScripts.critical (WARNING)> log_debug = <Logger WebScripts.debug (WARNING)> log_error = <Logger WebScripts.error (WARNING)> log_info = <Logger WebScripts.info (WARNING)> log_trace = <Logger WebScripts.trace (WARNING)> log_warning = <Logger WebScripts.warning (WARNING)>

Functions
`` |  | get_arguments_count(object_: collections.abc.Callable) `This function return the number of argument to call this Callable object.` get_encodings() `This function returns the probable encodings.` get_file_content(file_path, *args, **kwargs) -> ~StrOrBytes `This function return the file content.` get_ini_dict(filename: str) -> Dict[str, Dict[str, str]] `This function return a dict from ini filename.` get_ip(environ: os._Environ) -> str `This function return the real IP.` get_real_path(file_path: str) -> str `This function return the real path for files.` log_trace(function: function) `This decorator trace functions (start and end)`

Data
`` |  | __all__ = ['Logs', 'DefaultNamespace', 'log_trace', 'get_ip', 'get_arguments_count', 'get_file_content', 'get_real_path', 'get_encodings', 'get_ini_dict', 'server_path', 'CustomLogHandler'] __author_email__ = 'mauricelambert434@gmail.com' __copyright__ = '\nWebScripts Copyright (C) 2021 Maurice Lambert...ome to redistribute it\nunder certain conditions.\n' __description__ = 'This tools run scripts and display the result in...scripts (Logs, Namespace for configuration, ...).' __license__ = 'GPL-3.0 License' __maintainer__ = 'Maurice Lambert' __maintainer_email__ = 'mauricelambert434@gmail.com' __url__ = 'https://github.com/mauricelambert/WebScripts' server_path = /home/WebScripts

Author
`` |  | Maurice Lambert