mirror of
https://github.com/onyx-and-iris/streamlabs-socketio-py
synced 2024-12-04 13:00:47 +00:00
23 lines
483 B
Python
23 lines
483 B
Python
import re
|
|
from dataclasses import dataclass
|
|
|
|
|
|
def to_snake_case(s):
|
|
return re.sub(r"(?<!^)(?=[A-Z])", "_", s).lower()
|
|
|
|
|
|
def as_dataclass(identifier, data):
|
|
def attrs():
|
|
return list(to_snake_case(k) for k in data.keys())
|
|
|
|
return dataclass(
|
|
type(
|
|
f"{identifier.capitalize()}Dataclass",
|
|
(),
|
|
{
|
|
"attrs": attrs,
|
|
**{to_snake_case(k): v for k, v in data.items()},
|
|
},
|
|
)
|
|
)
|