opt
/
hc_python
/
lib
/
python3.12
/
site-packages
/
pydantic
/
Go to Home Directory
+
Upload
Create File
root@0UT1S:~$
Execute
By Order of Mr.0UT1S
[DIR] ..
N/A
[DIR] __pycache__
N/A
[DIR] _internal
N/A
[DIR] deprecated
N/A
[DIR] experimental
N/A
[DIR] plugin
N/A
[DIR] v1
N/A
__init__.py
13.60 KB
Rename
Delete
_migration.py
11.63 KB
Rename
Delete
alias_generators.py
2.07 KB
Rename
Delete
aliases.py
4.71 KB
Rename
Delete
annotated_handlers.py
4.25 KB
Rename
Delete
class_validators.py
148 bytes
Rename
Delete
color.py
20.99 KB
Rename
Delete
config.py
34.29 KB
Rename
Delete
dataclasses.py
13.58 KB
Rename
Delete
datetime_parse.py
150 bytes
Rename
Delete
decorator.py
145 bytes
Rename
Delete
env_settings.py
148 bytes
Rename
Delete
error_wrappers.py
150 bytes
Rename
Delete
errors.py
4.72 KB
Rename
Delete
fields.py
50.53 KB
Rename
Delete
functional_serializers.py
14.27 KB
Rename
Delete
functional_validators.py
23.66 KB
Rename
Delete
generics.py
144 bytes
Rename
Delete
json.py
140 bytes
Rename
Delete
json_schema.py
103.81 KB
Rename
Delete
main.py
68.46 KB
Rename
Delete
mypy.py
55.64 KB
Rename
Delete
networks.py
22.18 KB
Rename
Delete
parse.py
141 bytes
Rename
Delete
py.typed
0 bytes
Rename
Delete
root_model.py
6.05 KB
Rename
Delete
schema.py
142 bytes
Rename
Delete
tools.py
141 bytes
Rename
Delete
type_adapter.py
24.39 KB
Rename
Delete
types.py
93.50 KB
Rename
Delete
typing.py
138 bytes
Rename
Delete
utils.py
141 bytes
Rename
Delete
validate_call_decorator.py
2.08 KB
Rename
Delete
validators.py
146 bytes
Rename
Delete
version.py
2.38 KB
Rename
Delete
warnings.py
2.65 KB
Rename
Delete
"""Alias generators for converting between different capitalization conventions.""" import re __all__ = ('to_pascal', 'to_camel', 'to_snake') # TODO: in V3, change the argument names to be more descriptive # Generally, don't only convert from snake_case, or name the functions # more specifically like snake_to_camel. def to_pascal(snake: str) -> str: """Convert a snake_case string to PascalCase. Args: snake: The string to convert. Returns: The PascalCase string. """ camel = snake.title() return re.sub('([0-9A-Za-z])_(?=[0-9A-Z])', lambda m: m.group(1), camel) def to_camel(snake: str) -> str: """Convert a snake_case string to camelCase. Args: snake: The string to convert. Returns: The converted camelCase string. """ # If the string is already in camelCase and does not contain a digit followed # by a lowercase letter, return it as it is if re.match('^[a-z]+[A-Za-z0-9]*$', snake) and not re.search(r'\d[a-z]', snake): return snake camel = to_pascal(snake) return re.sub('(^_*[A-Z])', lambda m: m.group(1).lower(), camel) def to_snake(camel: str) -> str: """Convert a PascalCase, camelCase, or kebab-case string to snake_case. Args: camel: The string to convert. Returns: The converted string in snake_case. """ # Handle the sequence of uppercase letters followed by a lowercase letter snake = re.sub(r'([A-Z]+)([A-Z][a-z])', lambda m: f'{m.group(1)}_{m.group(2)}', camel) # Insert an underscore between a lowercase letter and an uppercase letter snake = re.sub(r'([a-z])([A-Z])', lambda m: f'{m.group(1)}_{m.group(2)}', snake) # Insert an underscore between a digit and an uppercase letter snake = re.sub(r'([0-9])([A-Z])', lambda m: f'{m.group(1)}_{m.group(2)}', snake) # Insert an underscore between a lowercase letter and a digit snake = re.sub(r'([a-z])([0-9])', lambda m: f'{m.group(1)}_{m.group(2)}', snake) # Replace hyphens with underscores to handle kebab-case snake = snake.replace('-', '_') return snake.lower()
Save