X7ROOT File Manager
Current Path:
/opt/hc_python/lib/python3.12/site-packages/pydantic
opt
/
hc_python
/
lib
/
python3.12
/
site-packages
/
pydantic
/
📁
..
📄
__init__.py
(13.6 KB)
📁
__pycache__
📁
_internal
📄
_migration.py
(11.63 KB)
📄
alias_generators.py
(2.07 KB)
📄
aliases.py
(4.71 KB)
📄
annotated_handlers.py
(4.25 KB)
📄
class_validators.py
(148 B)
📄
color.py
(20.99 KB)
📄
config.py
(34.29 KB)
📄
dataclasses.py
(13.58 KB)
📄
datetime_parse.py
(150 B)
📄
decorator.py
(145 B)
📁
deprecated
📄
env_settings.py
(148 B)
📄
error_wrappers.py
(150 B)
📄
errors.py
(4.72 KB)
📁
experimental
📄
fields.py
(50.53 KB)
📄
functional_serializers.py
(14.27 KB)
📄
functional_validators.py
(23.66 KB)
📄
generics.py
(144 B)
📄
json.py
(140 B)
📄
json_schema.py
(103.81 KB)
📄
main.py
(68.46 KB)
📄
mypy.py
(55.64 KB)
📄
networks.py
(22.18 KB)
📄
parse.py
(141 B)
📁
plugin
📄
py.typed
(0 B)
📄
root_model.py
(6.05 KB)
📄
schema.py
(142 B)
📄
tools.py
(141 B)
📄
type_adapter.py
(24.39 KB)
📄
types.py
(93.5 KB)
📄
typing.py
(138 B)
📄
utils.py
(141 B)
📁
v1
📄
validate_call_decorator.py
(2.08 KB)
📄
validators.py
(146 B)
📄
version.py
(2.38 KB)
📄
warnings.py
(2.65 KB)
Editing: alias_generators.py
"""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()
Upload File
Create Folder