Files
DeletedPosts/Bot/logger/__pycache__/logger.cpython-39.pyc

134 lines
12 KiB
Plaintext
Raw Normal View History

2026-02-23 22:48:25 +00:00
a
h<10>d<EFBFBD>'<00>@s<>ddlmZddlZddlZddlmZddlmZddlm Z m
Z
m Z m Z m Z dZgd<07>ZGdd <09>d e<05>Zd
d
d <0B>d d <0A>ZGdd<0F>d<0F>ZGdd<11>de<13>ZGdd<13>de<15>ZGdd<15>ded<16>ZdS)<17>)<01> annotationsN)<01>Enum)<01> currentframe)<05>Optional<61>Tuple<6C>Dict<63>List<73>AnyZtesting)<03>UnhandledLogError<6F> get_color<6F>Loggerc@sPeZdZdZdZdZdZdZdZdZ dZ
d Z d
Z d Z d Zd ZdZdZdZdZdS)<13>ColorzzzzzzzzzzzzzzzzzN)<14>__name__<5F>
__module__<EFBFBD> __qualname__<5F>RESETZBLACK<43>RED<45>GREEN<45>YELLOW<4F>BLUEZMAGENTAZCYANZWHITEZ
BLACK_BOLD<EFBFBD>RED_BOLDZ
GREEN_BOLDZ YELLOW_BOLDZ BLUE_BOLDZ MAGENTA_BOLDZ CYAN_BOLDZ
WHITE_BOLD<EFBFBD>rr<00>:/home/pi/bots/DeletedPosts/CraftSleuthBot/logger/logger.pyr s"r <00>str)<02>color<6F>returncCsdd<02>tD<00>|<00><01>S)a<>Colors:
```
(
"RESET",
"BLACK",
"RED",
"GREEN",
"YELLOW",
"BLUE",
"MAGENTA",
"CYAN",
"WHITE",
"BLACK_BOLD",
"RED_BOLD",
"GREEN_BOLD",
"YELLOW_BOLD",
"BLUE_BOLD",
"MAGENTA_BOLD",
"CYAN_BOLD",
"WHITE_BOLD",
)
```
cSsi|]}|j|j<01>qSr)<02>name<6D>value)<02>.0<EFBFBD>irrr<00>
<dictcomp>F<00>zget_color.<locals>.<dictcomp>)r <00>upper<65>rrrrr .sr c@s eZdZdZddd<04>dd<06>Zdd<08>d d
<EFBFBD>Zdd<08>d d <0C>Zd d<08>dd<0F>Zddd<10>dd<12>Zdd<08>dd<14>Z dd<08>dd<16>Z
dd d<18>dd<1A>Z dd<08>dd<1C>Z dd<08>dd<1E>Z edd<08>d d!<21><04>Zedd<08>d"d#<23><04>Zejddd$<24>d%d#<23><04>Zd&d'<27>Zd(d<08>d)d*<2A>Zd+d<08>d,d-<2D>Zddd.<2E>d/d0<64>Zddd1<64>d2d3<64>Zd4S)5<>Configr<00>int<6E>None)<02>levelrcCs:tjd7_tj|_ddddddd<04>|_||_d|_dS)N<><00><00>)<06>success<73>info<66>custom<6F>warning<6E>error<6F>debugr)r$<00> _INSTANCE<43> _settingsr'<00>_iter)<02>selfr'rrr<00>__init__Ls<02>zConfig.__init__r<00>rcCsd|jj<01>d|j<02>d<03>S)N<><<3C>(<28>)>)<03> __class__rr2<00>r4rrr<00>__str__ZszConfig.__str__c Cs(d|jj<01>d|j<02>d|j<03>d|j<04>d<05> S)Nr7z
(settings=z, level=z
instance=r9)r:rr2<00>_levelr1r;rrr<00>__repr__]s
<04><04>zConfig.__repr__<5F>boolcCs
t|j<01>S<00>N)r?r2r;rrr<00>__bool__aszConfig.__bool__)<02>krcCs
|j|Sr@<00>r2)r4rBrrr<00> __getitem__dszConfig.__getitem__cCs|jSr@)r'r;rrr<00>__int__gszConfig.__int__cCs
t|j<01>Sr@)<02>lenr2r;rrr<00>__len__jszConfig.__len__r )<02>
_Config__orcCs
||jvSr@rC)r4rHrrr<00> __contains__mszConfig.__contains__cCs|Sr@rr;rrr<00>__iter__pszConfig.__iter__cCs<|<00><00>}|jt|<00>kr d|_t<03>||j}|jd7_|S)Nrr()<04>keysr3rF<00> StopIteration)r4rK<00>retvalrrr<00>__next__ss
zConfig.__next__zDict[str, int]cCs|jSr@rCr;rrr<00>settings|szConfig.settingscCs|jSr@)r=r;rrrr'<00>sz Config.level)<02>vrcCs0d|krdks&ntd|<01>d<04><03><01>||_dS)z<>Level setter validator
:param v: The level to change to
:type v: int
:raises ValueError: If the v is invalid for `level`
r<00>z!Level must be between `0-5` not `<60>`N)<02>
ValueErrorr=)r4rPrrrr'<00>sccs|j<00><01>VdSr@)r2<00>itemsr;rrrrT<00>sz Config.itemsz List[str]cCst|j<01><02><00>Sr@)<03>listr2rKr;rrrrK<00>sz Config.keysz List[int]cCst|j<01><02><00>Sr@)rUr2<00>valuesr;rrrrV<00>sz Config.values)rOrc sVt<00>fdd<02><08>D<00><01>r:t<00>fdd<02><08>D<00><01>r:<3A>j<01><02><01>ntd<04><01>d<05>j<04>d<06><05><01>dS)z<>Change the settings configuration for a given instance
:raises ValueError: If the configuraion does not exist or user tries to update to an invalid value
c3s|]}|<01>jvVqdSr@<00>rO<00>r<00>keyr;rr<00> <genexpr><3E>r!z Config.update.<locals>.<genexpr>c3s*|]"}d<00>|kodknVqdS)rrQNrrXrWrrrZ<00>r!zInvalid key or value in z!. Remember, key has to exists in z( and all values have to be between (1-5)N)<05>allr2<00>updaterSrO<00>r4rOrr]rr\<00>s<14>
<04>z Config.update)rYrcCs
|j|S)z<>Get a setting configuration
:param key: Key of the configuration
:type key: str
:return: The level this configuration is set to
:rtype: int
rC)r4rYrrr<00>get<65>sz
Config.getN)rrrr1r5r<r>rArDrErGrIrJrN<00>propertyrOr'<00>setterrTrKrVr\r^rrrrr$Is,   r$c@s eZdZdS)r
N)rrrrrrrr
<00>r!r
c@s$eZdZdZddddd<06>dd<08>Zd S)
<EFBFBD>
MetaLoggerz<EFBFBD>A simple metaclass that checks if all logs/settings are correctly
handled by comaring the ammount of settings in Config._settings agnainst
the functions that live in Logger() - some unnecessary
rz Tuple[type]zDict[str, Any]<5D>type)r<00>bases<65>attrsrc CsXd}d}ttd<03><01>}d}|D]}|<08>d<05>s||vr|d7}q||ksLt|<04><01>t|||<03>S)Nz<4E>We either have a log function that is not in settings OR a function that needs to be dissmissed OR a setting that is not added as a log functionrr()rO<00> get_line_info<66>_)rFr$<00>
startswithr
rb) r4rrcrdZ error_msgZ log_functionsZtarget_log_functionsZ dismiss_attrs<72>logrrr<00>__new__<5F>s 
zMetaLogger.__new__N)rrr<00>__doc__rirrrrra<00>srac @s eZdZdZd/ddd<06>dd<08>Zd d
<EFBFBD>d d <0C>Zd d
<EFBFBD>d d<0E>Zedd
<EFBFBD>dd<11><04>Zd d dd<13>dd<15>Z d dd<17>dd<19>Z
d d d d<1A>dd<1C>Z d0e d<1E>d<1F>d d d d d dd!<21>d"d#<23>Z d d d dd$<24>d%d&<26>Zd d d dd$<24>d'd(<28>Zd d d dd$<24>d)d*<2A>Zd d d dd$<24>d+d,<2C>Zd d d dd$<24>d-d.<2E>ZdS)1r aThe Logger class handles debbuging with colored information
based on the level. Each instance has its own settings which the
user can change independently through `self.settings.update()`.
Mind that level 1 will print evetything and level 5 less
r)Nr%z Optional[str])r'<00>log_pathcCst|<01>|_||_dS)z<>Initializer of Logger object
:param level: The level of debugging. Based on that, some informations can be configured to not show up thus lowering the verbosity, defaults to 2
:type level: int, optional
N)r$r2<00> _log_path)r4r'rkrrrr5<00>s
zLogger.__init__rr6cCsd|jj<01>d|jj<03>d<03>S)Nr7zObject-<2D>><3E>r:rr2r1r;rrrr<<00>szLogger.__str__cCsd|jj<01>d|jj<03>d<03>S)Nr7z
(instance=r9rnr;rrrr><00>szLogger.__repr__r$cCs|jS)zmGetter so self._settings cannot be writable
:return: Config instance
:rtype: Config
rCr;rrrrO<00>szLogger.settingsr&)<03>header<65>msgrcCs<>|jdur<>tj<02>|j<00>sFt|jdd<03><02>}Wd<00>n1s<0Yt|jdd<03><02>,}|<04>d|<01><06><00>d|<02>d<07><05>Wd<00>n1s<>0YdS)z<>If a file log_path is provided in `Logger.__init__`
:param header: The msg header WARNING/ERROR ...
:type header: str
:param msg: The message to be logged
:type msg: str
N<>w)<01>mode<64>a<>[<5B>]: <20>
)rl<00>os<6F>path<74>exists<74>open<65>writer")r4rorprf<00>frrr<00>_log<6F>s

.z Logger._logr?)<02> func_namercCs|jj|j|kS)z<>Use to check the `self.level` before printing the log
:param func_name: Name of the function as a string
:type func_name: str
:return: Wheather the settings allow this certain function to print
:rtype: bool
)rOr')r4r~rrr<00>_runner<65>szLogger._runner)<03>file<6C>promptrcCs:t<00>}d|<01>d|jj<02><00>}|<00>|<04>d|<02><00><03>t|<01>|S)aMGet the file and the line of where this function is called
:param file: The file where the func is called (Recommended: `__file__`)
:type file: str
:param prompt: Any message to follow after line info
:type prompt: str
:return: *file path*, *line number* *prompt*
:rtype: str
zFile "z", line z : )r<00>f_back<63>f_linenor0<00>print)r4r<>r<><00>cfrprrrres
zLogger.get_line_infor-<00>resetr#r )rpro<00>argsr<00>kwargsrcOsht<00><01>jj}|<00>|<06>rXt|<03>d|<02><06><00>d|<01>td<03><01><00>g|<04>Rddi|<05><01>ttd<03><01>|<00>||<01>dS)Nrtrur<><00>end<6E>) <09>sys<79> _getframe<6D>f_code<64>co_namerr<>r"r r})r4rprorr<>r<>r~rrrr-s
 
6 z Logger.custom)rpr<>r<>rcOsdt<00><01>jj}|<00>|<04>rHttjj<08>d|<04> <09><00>d|<01><00>g|<02>Rddi|<03><01>tt
d<05><01>|<00> ||<01>dS<00>Nrtrur<>r<>r<>) r<>r<>r<>r<>rr<>r rrr"r r}<00>r4rpr<>r<>r~rrrr,s 
<02><02><02> z Logger.infocOsdt<00><01>jj}|<00>|<04>rTttjj<08>d|<04> <09><00>d|<01><00>g|<02>Rddi|<03><01>tt
d<05><01>|<00> ||<01>dSr<>) r<>r<>r<>r<>rr<>r rrr"r r}r<>rrrr+"s 
<02><02><02> zLogger.successcOsdt<00><01>jj}|<00>|<04>rTttjj<08>d|<04> <09><00>d|<01><00>g|<02>Rddi|<03><01>tt
d<05><01>|<00> ||<01>dSr<>) r<>r<>r<>r<>rr<>r rrr"r r}r<>rrrr.*s 
<02><02><02> zLogger.warningcOsdt<00><01>jj}|<00>|<04>rTttjj<08>d|<04> <09><00>d|<01><00>g|<02>Rddi|<03><01>tt
d<05><01>|<00> ||<01>dSr<>) r<>r<>r<>r<>rr<>r rrr"r r}r<>rrrr/2s 
<02><02><02> z Logger.errorcOsdt<00><01>jj}|<00>|<04>rTttjj<08>d|<04> <09><00>d|<01><00>g|<02>Rddi|<03><01>tt
d<05><01>|<00> ||<01>dSr<>) r<>r<>r<>r<>rr<>r rrr"r r}r<>rrrr0:s 
<02><02><02> z Logger.debug)r)N)r-)rrrrjr5r<r>r_rOr}rrer r-r,r+r.r/r0rrrrr <00>s"

<06>r )<01> metaclass)<18>
__future__rrwr<><00>enumr<00>inspectr<00>typingrrrrr r<00>__all__r r r$<00> Exceptionr
rbrar rrrr<00><module>s   h