mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 21:00:53 +00:00
e145362726
added tests to test_request keys in attrs() list now snake cased
27 lines
552 B
Python
27 lines
552 B
Python
import re
|
|
from dataclasses import dataclass
|
|
|
|
|
|
def to_camel_case(s):
|
|
return "".join(word.title() for word in s.split("_"))
|
|
|
|
|
|
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}Dataclass",
|
|
(),
|
|
{
|
|
"attrs": attrs,
|
|
**{to_snake_case(k): v for k, v in data.items()},
|
|
},
|
|
)
|
|
)
|