error_mngr.py : rtype and function doc (part)

This commit is contained in:
Maximilien Rigaut 2022-06-09 15:21:46 +02:00
parent df2e0941c8
commit e64c6d7f41
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
1 changed files with 44 additions and 13 deletions

View File

@ -21,11 +21,14 @@ __all__ = _ERRORS+[]
def init_logging(filename=None, loglevel="ERROR", filemode='w', handler=None):
"""
Initializes logging
:param filename: The name of the log file
:param loglevel: The level of logging
:type loglevel: str
:param filemode: The mode of the log file
:param filename: The path for the log file
:param loglevel: The level of logging: "ERROR", "INFO", "WARNING", "DEBUG", "CRITICAL"
:param filemode: The mode of the log file: "w", "a"
:param handler: The handler to use
:type filename: str
:type loglevel: str
:type filemode: str
:type handler: logging.Handler
:return: None
"""
loglevel = loglevel.upper()
@ -50,6 +53,7 @@ def log_message(message, level="ERROR"):
:param message: The message to log
:param level: The level of the message
:type level: str
:type message: str
:return: None
"""
level = level.lower()
@ -85,9 +89,11 @@ def log_exception(exception, level="ERROR"):
def dict_check(dic, *args):
"""
Helper function to test existence within a dictionary.
Helper function to test existence of a list of succesive keys within a nested dictionary.
:param dic: The dictionary of dictionaries to check
:param args: Any number of keys to check the dictionaries for
:type dic: dict | config.ConfigLoader
:type args: str
:return: A table of Booleans for every key checked.
"""
output = [False for _ in args]
@ -102,33 +108,45 @@ def dict_check(dic, *args):
def str_dict_check(dic, *args):
"""
Helper function to test existence within a dictionary and return a string of the values.
Helper function to test existence within a dictionary and return a string of the values of the keys checked
and wether they exist.
'arg[0]' : True or False
:param dic: The nested dictionary to check
:param args: Any number of keys to check successively
:type dic: dict
:type args: str
:return: A string of the values of the keys checked and wether they exist.
:rtype: str
"""
out = dict_check(dic, *args)
return "\n".join([f"{args[i]}: {out[i]}" for i in range(len(out))])
class BootstraparseError(Exception):
"""
Base class for all Bootstraparse errors
"""
pass
class ParsingError(Exception):
"""
Exception class for parsing errors
:param message: The message to display
:type message: str
:param line: The line number of the error
:param column: The column number of the error
:param file: The name of the file
:return: None
"""
def __init__(self, message=None, line=None, column=None, file=None):
"""
Initializes the ParsingError class with the filename and a line and column number
based on the current position in the file (if available)
:param message: The message to display
:type message: str
:param line: The line number of the error
:type line: int
:param column: The column number of the error
:type column: int
:param file: The name of the file
:type file: str
:return: None
"""
super().__init__(message)
self.line = line
@ -154,6 +172,11 @@ class MismatchedContainerError(BootstraparseError):
The token is not final and cannot be contained. Indicative of a mismatched token.
"""
def __init__(self, token):
"""
Initializes the MismatchedContainerError class with the token that was not final
:param token: The token that is not final
:type token: syntax.SemanticType
"""
self.token = token
if token:
self.line = token.line_number
@ -171,6 +194,14 @@ class LonelyOptionalError(BootstraparseError):
Optional token could not be matched with last element in pile (not a container).
"""
def __init__(self, token, last_in_pile):
"""
Initializes the LonelyOptionalError class with the token found and the last element in the pile
Used when a token is found that is optional and cannot be matched with the last element in the pile (not a container)
:param token: The token that is not final
:type token: syntax.SemanticType
:param last_in_pile: The last element in the pile
:type last_in_pile: syntax.SemanticType
"""
self.token = token
if token:
self.line = token.line_number