#!/usr/bin/env python3
# -*- coding: utf-8 -*-
################################################################################
# MusaMusa-Errors Copyright (C) 2021 suizokukan
# Contact: suizokukan _A.T._ orange dot fr
#
# This file is part of MusaMusa-Errors.
# MusaMusa-Errors is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MusaMusa-Errors is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MusaMusa-Errors. If not, see <http://www.gnu.org/licenses/>.
################################################################################
"""
MusaMusa-Errors project : musamusa_errors/error_messages.py
A convenient way to store and display error messages.
Please notice that this code uses the `rich` package.
Classes:
Iaswn Iaswn + list
| |
MusaMusaEW ListOfErrorMessages
|
+-----------+------+-------------+
| | |
MusaMusaWarning MusaMusaError MusTextFileEW
|
+---------+--------------+
| |
MusTextFileWarning MusTextFileError
____________________________________________________________________________
o ListOfErrorMessages class
o MusaMusaEW class
o MusaMusaWarning class
o MusaMusaError class
o MusTextFileError class
o MusTextFileWarning class
"""
from dataclasses import dataclass, field
from iaswn.iaswn import Iaswn
# https://docs.python.org/3/library/logging.html#logging-levels
LEVEL_ERROR = 40
LEVEL_WARNING = 30
class ListOfErrorMessages(Iaswn, list):
"""
ListOfErrorMessages class
Just a wrapper around a <list> of MusaMusaError and similar objects.
_______________________________________________________________________
METHODS:
o __str__(self)
o first_msgid_is(self, msgid: str)
o improved_str()
o last_msgid_is(self, msgid: str)
o zero_error(self)
o zero_error_or_warning(self)
o zero_warning(self)
"""
def __init__(self):
"""
ListOfErrorMessages.__init__()
This method is necessary to ignore the parameters required by the list type
(namely args, **kwargs): indeed the Iaswn class requires no parameter
without default value.
"""
list.__init__(self)
Iaswn.__init__(self)
def __str__(self):
"""
ListOfErrorMessages.__str__()
"""
if self.zero_error():
return "No error or warning"
res = ["*** Errors/Warnings ***", ]
# ew_object : MusaMusaEW_like object
for index, ew_object in enumerate(self):
_line = "* #{index:0>5d} " \
": {ew_object}".format(
index=index,
ew_object=str(ew_object))
res.append(_line)
return "\n".join(res)
def first_msgid_is(self,
msgid: str):
"""
ListOfErrorMessages.first_msgid_is()
Return True if the first *Error object stored in self has .msgid
equal to <msgid>.
__________________________________________________________________
RETURNED VALUE : (bool)
"""
if len(self) == 0:
return False
return self[0].msgid == msgid
def improved_str(self):
"""
ListOfErrorMessages.improved_str()
Return a nice representation of <self>, using colorized output.
This functions should be used with the `rich` package : BE CAREFUL
WHEN USING THESE CHARACTERS in the result string, since they have a
special meaning for the `rich` package.
__________________________________________________________________
RETURNED VALUE : (str)a nice representation of <self>.
"""
if self.zero_error_or_warning():
return "[yellow]*** No error or warning***[/yellow]"
res = ["[yellow]*** Errors/Warnings ***[/yellow]", ]
# ew_object : MusaMusaEW_like object
for index, ew_object in enumerate(self):
_line = "* [white]#{index:0>5d}[/white] " \
": {ew_object}".format(
index=index,
ew_object=ew_object.improved_str())
res.append(_line)
return "\n".join(res)
def last_msgid_is(self,
msgid: str):
"""
ListOfErrorMessages.last_msgid_is()
Return True if the last *Error object stored in self has .msgid
equal to <msgid>.
__________________________________________________________________
RETURNED VALUE : (bool)
"""
if len(self) == 0:
return False
return self[-1].msgid == msgid
def zero_error(self):
"""
ListOfErrorMessages.zero_error()
Return True if <self> doesn't contain any error.
__________________________________________________________________
RETURNED VALUE : (bool)
"""
# ew_object : MusaMusaEW_like object
for ew_object in self:
if ew_object.level == LEVEL_ERROR:
return False
return True
def zero_error_or_warning(self):
"""
ListOfErrorMessages.zero_error_or_warning()
Return True if <self> is empty.
__________________________________________________________________
RETURNED VALUE : (bool)
"""
return len(self) == 0
def zero_warning(self):
"""
ListOfErrorMessages.zero_warning()
Return True if <self> doesn't contain any error.
__________________________________________________________________
RETURNED VALUE : (bool)
"""
# ew_object : MusaMusaEW_like object
for ew_object in self:
if ew_object.level == LEVEL_WARNING:
return False
return True
@dataclass
class MusaMusaEW(Iaswn):
"""
MusaMusaEW class
(internal class) mother-class of all error classes
The user doesn't normally has to create MusaMusaEW objects.
_______________________________________________________________________
ATTRIBUTES:
o (str)msgid
o (str)msg
o (int)level
o (None or list)suberrors
METHODS:
o __str__(self, depth=0)
o improved_str(self, depth=0)
o str_word_suberrors(suberrors_nbr)
"""
msgid: str = ""
msg: str = ""
level: int = LEVEL_ERROR
suberrors: list = field(default_factory=list)
def __str__(self,
depth=0):
"""
MusaMusaEW.__str__()
___________________________________________________________________
ARGUMENT:
o depth: (int)level of depth for suberrors
0 is the first level (no suberrors)
1 is the second level (suberrors of an error)
2 is the third level (suberrors of suberrors of an error)

挣扎的蓝藻
- 粉丝: 15w+
最新资源
- 本库是个基于python的工具集,用于记录数据到文件。 使用方便,代码简洁, 是一个可靠、省心且实用的工具。 支持多线程同时写入。.zip
- 本科毕业设计,基于python的图像复制粘贴篡改识别软件。.zip
- 本项目是基于计算机视觉的端到端交通路口智能监控系统.采用的设计架构由SRS
- 碧蓝航线ios平台自动脚本,基于python+opencv+facebook_wda实现.zip
- 毕业设计中基于给定微博数据的反作弊识别,用python开发。.zip
- 毕业设计项目,基于深度学习的实时语义分割算法研究,python实现。.zip
- 对基于python的微博爬虫进行重写,重写语言:java.zip
- 此框架是基于Python+Pytest+Requests+Allure+Yaml+Json实现全链路接口自动化测试
- 程序语言课程作业在线评测平台(实现Java、C、Python的选择、填空、代码题在线评测),基于SpringBoot+Layui+MySQL实现.zip
- 非官方的科大讯飞语音合成(用于朗读,配音场景)python API (基于官方demo增加了:超过2000字上限自动分割再合并音频的功能).zip
- 非官方的简易中国铁路列车运行图系统,基于Python + PyQt5
- 超市POS销售与后台管理系统_商品录入收银业务会员管理进货销售库存人员权限断网收银断电保护_实现超市前台POS销售商品扫描条形码输入收银计算找零打印清单会员折扣累计消费以及后台管理.zip
- 俄罗斯方块闯关版,基于Python实现.zip
- 该项目是基于Python和数据库实现的学生信息管理系统.zip
- 该仓库为agv系统调度软件的前后端实现。项目基于fastapi(python后端框架)和vue2实现了RESTful风格的前后端分离.zip
- 该项目是基于Scrapy框架的Python新闻爬虫,能够爬取网易,搜狐,凤凰和澎湃网站上的新闻,将标题,内容,评论,时间等内容整理并保存到本地.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


