error_mngr.py : rtype and function doc (part)
This commit is contained in:
parent
92ee19a1ac
commit
7c6504d0aa
|
|
@ -21,11 +21,14 @@ __all__ = _ERRORS+[]
|
||||||
def init_logging(filename=None, loglevel="ERROR", filemode='w', handler=None):
|
def init_logging(filename=None, loglevel="ERROR", filemode='w', handler=None):
|
||||||
"""
|
"""
|
||||||
Initializes logging
|
Initializes logging
|
||||||
:param filename: The name of the log file
|
:param filename: The path for the log file
|
||||||
:param loglevel: The level of logging
|
:param loglevel: The level of logging: "ERROR", "INFO", "WARNING", "DEBUG", "CRITICAL"
|
||||||
:type loglevel: str
|
:param filemode: The mode of the log file: "w", "a"
|
||||||
:param filemode: The mode of the log file
|
|
||||||
:param handler: The handler to use
|
:param handler: The handler to use
|
||||||
|
:type filename: str
|
||||||
|
:type loglevel: str
|
||||||
|
:type filemode: str
|
||||||
|
:type handler: logging.Handler
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
loglevel = loglevel.upper()
|
loglevel = loglevel.upper()
|
||||||
|
|
@ -50,6 +53,7 @@ def log_message(message, level="ERROR"):
|
||||||
:param message: The message to log
|
:param message: The message to log
|
||||||
:param level: The level of the message
|
:param level: The level of the message
|
||||||
:type level: str
|
:type level: str
|
||||||
|
:type message: str
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
level = level.lower()
|
level = level.lower()
|
||||||
|
|
@ -83,25 +87,66 @@ def log_exception(exception, level="ERROR"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def dict_check(dic, *args):
|
||||||
|
"""
|
||||||
|
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]
|
||||||
|
for i in range(len(args)):
|
||||||
|
if args[i] in dic:
|
||||||
|
output[i] = True
|
||||||
|
dic = dic[args[i]]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def str_dict_check(dic, *args):
|
||||||
|
"""
|
||||||
|
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):
|
class BootstraparseError(Exception):
|
||||||
|
"""
|
||||||
|
Base class for all Bootstraparse errors
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ParsingError(Exception):
|
class ParsingError(Exception):
|
||||||
"""
|
"""
|
||||||
Exception class for parsing errors
|
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):
|
def __init__(self, message=None, line=None, column=None, file=None):
|
||||||
"""
|
"""
|
||||||
Initializes the ParsingError class with the filename and a line and column number
|
Initializes the ParsingError class with the filename and a line and column number
|
||||||
based on the current position in the file (if available)
|
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)
|
super().__init__(message)
|
||||||
self.line = line
|
self.line = line
|
||||||
|
|
@ -127,6 +172,11 @@ class MismatchedContainerError(BootstraparseError):
|
||||||
The token is not final and cannot be contained. Indicative of a mismatched token.
|
The token is not final and cannot be contained. Indicative of a mismatched token.
|
||||||
"""
|
"""
|
||||||
def __init__(self, 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
|
self.token = token
|
||||||
if token:
|
if token:
|
||||||
self.line = token.line_number
|
self.line = token.line_number
|
||||||
|
|
@ -144,6 +194,14 @@ class LonelyOptionalError(BootstraparseError):
|
||||||
Optional token could not be matched with last element in pile (not a container).
|
Optional token could not be matched with last element in pile (not a container).
|
||||||
"""
|
"""
|
||||||
def __init__(self, token, last_in_pile):
|
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
|
self.token = token
|
||||||
if token:
|
if token:
|
||||||
self.line = token.line_number
|
self.line = token.line_number
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue