Files
SMANAGE/backup/_flask_backup/Utils/Object.py
T

56 lines
1.8 KiB
Python

from tools import *
from AppBridge import *
from Utils.Config import *
from Utils.Models import *
class UnifiedSBinaryType:
Bytes: bytes
LowerStr: str
UpperStr: str
ok: bool | None = None
def __init__(self, a: str | bytes, raiserror: bool = False):
t = type(a)
if t == str:
a = a.replace("-", "")
self.LowerStr = a.lower()
self.UpperStr = a.upper()
self.Bytes = bytes.fromhex(a)
self.ok = True
elif t == bytes:
self.LowerStr = a.hex().lower()
self.UpperStr = a.hex().upper()
self.Bytes = a
self.ok = True
else:
pass
def __str__(self):
return self.UpperStr
def __bytes__(self):
return self.Bytes
class UUIDObj(UnifiedSBinaryType): # UUID 统一型
UUID: uuid.UUID
def __init__(self, UUID: uuid.UUID | str | bytes, raiserror: bool = False):
UnifiedSBinaryType.__init__(self, UUID, raiserror)
t = type(UUID)
self.ok = True
if t == str:
self.UUID = uuid.UUID(UUID)
elif t == bytes:
self.UUID = uuid.UUID(bytes=UUID)
elif t == uuid.UUID:
self.UUID = UUID
else:
if raiserror:
raise TypeError(f"{UUID} Not a valid UUID object.")
self.ok = False
self.LowerStr = str(self.UUID).lower().replace("-", "")
self.UpperStr = str(self.UUID).upper().replace("-", "")
self.Bytes = (self.UUID).bytes
self.bytes = (self.UUID).bytes
def __str__(self):
return self.UpperStr
def __bytes__(self):
return self.Bytes