initial commit
This commit is contained in:
120
bild/selenium_imp/util.py
Normal file
120
bild/selenium_imp/util.py
Normal file
@@ -0,0 +1,120 @@
|
||||
from functools import wraps
|
||||
import random
|
||||
|
||||
|
||||
def link(uri, label=None):
|
||||
if label is None:
|
||||
label = uri
|
||||
parameters = ''
|
||||
|
||||
# OSC 8 ; params ; URI ST <name> OSC 8 ;; ST
|
||||
escape_mask = '\033]8;{};{}\033\\{}\033]8;;\033\\'
|
||||
|
||||
return escape_mask.format(parameters, uri, label)
|
||||
|
||||
class ANSICodes:
|
||||
DEFAULT = OFF = '\x1b[0m'
|
||||
BOLD = STYLE_BOLD = '\x1b[1m'
|
||||
DIM = STYLE_DIM = '\x1b[2m'
|
||||
REGULAR = STYLE_REGULAR = '\x1b[22m'
|
||||
ITALIC = STYLE_ITALIC = '\x1b[3m'
|
||||
NITALIC = STYLE_NITALIC = '\x1b[23m'
|
||||
UNDERLINE = DECO_UNDERLINE = '\x1b[4m'
|
||||
DUNDERLINE = DECO_DUNDERLINE = '\x1b[21m'
|
||||
NUNDERLINE = DECO_NUNDERLINE = '\x1b[24m'
|
||||
OVERLINE = DECO_OVERLINE = '\x1b[53m'
|
||||
NOVERLINE = DECO_NOVERLINE = '\x1b[55m'
|
||||
INVERT = DECO_INVERT = '\x1b[7m'
|
||||
NINVERT = DECO_NINVERT = '\x1b[27m'
|
||||
HIDDEN = DECO_HIDDEN = '\x1b[8m'
|
||||
NHIDDEN = DECO_NHIDDEN = '\x1b[28m'
|
||||
STRIKE = DECO_STRIKE = '\x1b[9m'
|
||||
NSTRIKE = DECO_NSTRIKE = '\x1b[29m'
|
||||
|
||||
GREY = FG_GREY = '\x1b[30m'
|
||||
RED = FG_RED = '\x1b[31m'
|
||||
GREEN = FG_GREEN = '\x1b[32m'
|
||||
YELLOW = FG_YELLOW = '\x1b[33m'
|
||||
PURPLE = FG_PURPLE = '\x1b[34m'
|
||||
PINK = FG_PINK = '\x1b[35m'
|
||||
BLUE = FG_BLUE = '\x1b[36m'
|
||||
WHITE = FG_WHITE = '\x1b[37m'
|
||||
BRIGHT_GREY = FG_BRIGHT_GREY = '\x1b[90m'
|
||||
BRIGHT_RED = FG_BRIGHT_RED = '\x1b[91m'
|
||||
BRIGHT_GREEN = FG_BRIGHT_GREEN = '\x1b[92m'
|
||||
BRIGHT_YELLOW = FG_BRIGHT_YELLOW = '\x1b[93m'
|
||||
BRIGHT_PURPLE = FG_BRIGHT_PURPLE = '\x1b[94m'
|
||||
BRIGHT_PINK = FG_BRIGHT_PINK = '\x1b[95m'
|
||||
BRIGHT_BLUE = FG_BRIGHT_BLUE = '\x1b[96m'
|
||||
BRIGHT_WHITE = FG_BRIGHT_WHITE = '\x1b[97m'
|
||||
|
||||
BG_GREY = '\x1b[40m'
|
||||
BG_RED = '\x1b[41m'
|
||||
BG_GREEN = '\x1b[42m'
|
||||
BG_YELLOW = '\x1b[43m'
|
||||
BG_PURPLE = '\x1b[44m'
|
||||
BG_PINK = '\x1b[45m'
|
||||
BG_BLUE = '\x1b[46m'
|
||||
BG_WHITE = '\x1b[47m'
|
||||
BG_BRIGHT_BLUE = '\x1b[100m'
|
||||
BG_BRIGHT_RED = '\x1b[101m'
|
||||
BG_BRIGHT_GREEN = '\x1b[102m'
|
||||
BG_BRIGHT_YELLOW = '\x1b[103m'
|
||||
BG_BRIGHT_PURPLE = '\x1b[104m'
|
||||
BG_BRIGHT_PINK = '\x1b[105m'
|
||||
BG_BRIGHT_BLUE = '\x1b[106m'
|
||||
BG_BRIGHT_WHITE = '\x1b[107m'
|
||||
|
||||
@staticmethod
|
||||
def FG_CUSTOM_N(n,/):
|
||||
# 0- 7: standard colors (as in ESC [ 30–37 m)
|
||||
# 8- 15: high intensity colors (as in ESC [ 90–97 m)
|
||||
# 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
|
||||
# 232-255: grayscale from dark to light in 24 steps
|
||||
return f'\x1b[38;5;{n}m'
|
||||
|
||||
@staticmethod
|
||||
def FG_CUSTOM_RGB(r,g,b,/):
|
||||
# r, g, b: 0-255
|
||||
return f'\x1b[38;5;{r};{g};{b}m'
|
||||
|
||||
@staticmethod
|
||||
def BG_CUSTOM_N(n,/):
|
||||
# 0- 7: standard colors (as in ESC [ 30–37 m)
|
||||
# 8- 15: high intensity colors (as in ESC [ 90–97 m)
|
||||
# 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
|
||||
# 232-255: grayscale from dark to light in 24 steps
|
||||
return f'\x1b[48;5;{n}m'
|
||||
|
||||
@staticmethod
|
||||
def BG_CUSTOM_RGB(r,g,b,/):
|
||||
# r, g, b: 0-255
|
||||
return f'\x1b[48;5;{r};{g};{b}m'
|
||||
|
||||
|
||||
def debugging_rand(chance):
|
||||
import random
|
||||
class RandomException(Exception):
|
||||
def __init__(self, *args):
|
||||
super().__init__(*args)
|
||||
|
||||
if chance > 1:
|
||||
chance /= 100
|
||||
|
||||
a = random.random()
|
||||
if a <= chance:
|
||||
raise RandomException(f'RandomException {chance*100}%')
|
||||
|
||||
|
||||
def failhandler(callback, exceptions:Union[tuple, list, Exception, None]=None):
|
||||
if exceptions is None:
|
||||
exceptions = Exception
|
||||
def fail_decorator(func):
|
||||
@wraps(func)
|
||||
def wrapped_function(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except exceptions as e:
|
||||
callback(e,*args,**kwargs)
|
||||
return wrapped_function
|
||||
return fail_decorator
|
||||
Reference in New Issue
Block a user