GRAYBYTE WORDPRESS FILE MANAGER2091

Server IP : 198.54.121.189 / Your IP : 216.73.216.224
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/cloudlinux/venv/lib/python3.11/site-packages/pydantic/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/pydantic//root_model.py
"""RootModel class and type definitions."""

from __future__ import annotations as _annotations

import typing
from copy import copy, deepcopy

from pydantic_core import PydanticUndefined

from . import PydanticUserError
from ._internal import _repr
from .main import BaseModel, _object_setattr

if typing.TYPE_CHECKING:
    from typing import Any

    from typing_extensions import Literal

    Model = typing.TypeVar('Model', bound='BaseModel')


__all__ = ('RootModel',)


RootModelRootType = typing.TypeVar('RootModelRootType')


class RootModel(BaseModel, typing.Generic[RootModelRootType]):
    """Usage docs: https://docs.pydantic.dev/2.4/concepts/models/#rootmodel-and-custom-root-types

    A Pydantic `BaseModel` for the root object of the model.

    Attributes:
        root: The root object of the model.
        __pydantic_root_model__: Whether the model is a RootModel.
        __pydantic_private__: Private fields in the model.
        __pydantic_extra__: Extra fields in the model.

    """

    __pydantic_root_model__ = True
    __pydantic_private__ = None
    __pydantic_extra__ = None

    root: RootModelRootType

    def __init_subclass__(cls, **kwargs):
        extra = cls.model_config.get('extra')
        if extra is not None:
            raise PydanticUserError(
                "`RootModel` does not support setting `model_config['extra']`", code='root-model-extra'
            )
        super().__init_subclass__(**kwargs)

    def __init__(__pydantic_self__, root: RootModelRootType = PydanticUndefined, **data) -> None:  # type: ignore
        __tracebackhide__ = True
        if data:
            if root is not PydanticUndefined:
                raise ValueError(
                    '"RootModel.__init__" accepts either a single positional argument or arbitrary keyword arguments'
                )
            root = data  # type: ignore
        __pydantic_self__.__pydantic_validator__.validate_python(root, self_instance=__pydantic_self__)

    __init__.__pydantic_base_init__ = True

    @classmethod
    def model_construct(cls: type[Model], root: RootModelRootType, _fields_set: set[str] | None = None) -> Model:
        """Create a new model using the provided root object and update fields set.

        Args:
            root: The root object of the model.
            _fields_set: The set of fields to be updated.

        Returns:
            The new model.

        Raises:
            NotImplemented: If the model is not a subclass of `RootModel`.
        """
        return super().model_construct(root=root, _fields_set=_fields_set)

    def __getstate__(self) -> dict[Any, Any]:
        return {
            '__dict__': self.__dict__,
            '__pydantic_fields_set__': self.__pydantic_fields_set__,
        }

    def __setstate__(self, state: dict[Any, Any]) -> None:
        _object_setattr(self, '__pydantic_fields_set__', state['__pydantic_fields_set__'])
        _object_setattr(self, '__dict__', state['__dict__'])

    def __copy__(self: Model) -> Model:
        """Returns a shallow copy of the model."""
        cls = type(self)
        m = cls.__new__(cls)
        _object_setattr(m, '__dict__', copy(self.__dict__))
        _object_setattr(m, '__pydantic_fields_set__', copy(self.__pydantic_fields_set__))
        return m

    def __deepcopy__(self: Model, memo: dict[int, Any] | None = None) -> Model:
        """Returns a deep copy of the model."""
        cls = type(self)
        m = cls.__new__(cls)
        _object_setattr(m, '__dict__', deepcopy(self.__dict__, memo=memo))
        # This next line doesn't need a deepcopy because __pydantic_fields_set__ is a set[str],
        # and attempting a deepcopy would be marginally slower.
        _object_setattr(m, '__pydantic_fields_set__', copy(self.__pydantic_fields_set__))
        return m

    if typing.TYPE_CHECKING:

        def model_dump(
            self,
            *,
            mode: Literal['json', 'python'] | str = 'python',
            include: Any = None,
            exclude: Any = None,
            by_alias: bool = False,
            exclude_unset: bool = False,
            exclude_defaults: bool = False,
            exclude_none: bool = False,
            round_trip: bool = False,
            warnings: bool = True,
        ) -> RootModelRootType:
            """This method is included just to get a more accurate return type for type checkers.
            It is included in this `if TYPE_CHECKING:` block since no override is actually necessary.

            See the documentation of `BaseModel.model_dump` for more details about the arguments.
            """
            ...

    def __eq__(self, other: Any) -> bool:
        if not isinstance(other, RootModel):
            return NotImplemented
        return self.model_fields['root'].annotation == other.model_fields['root'].annotation and super().__eq__(other)

    def __repr_args__(self) -> _repr.ReprArgs:
        yield 'root', self.root

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
June 25 2025 08:31:36
root / root
0755
__pycache__
--
March 06 2024 00:27:04
root / root
0755
_internal
--
March 06 2024 00:27:04
root / root
0755
deprecated
--
March 06 2024 00:27:04
root / root
0755
plugin
--
March 06 2024 00:27:04
root / root
0755
v1
--
March 06 2024 00:27:04
root / root
0755
__init__.py
5.678 KB
March 06 2024 00:27:04
root / root
0644
_migration.py
11.62 KB
March 06 2024 00:27:04
root / root
0644
alias_generators.py
1.114 KB
March 06 2024 00:27:04
root / root
0644
annotated_handlers.py
4.244 KB
March 06 2024 00:27:04
root / root
0644
class_validators.py
0.144 KB
March 06 2024 00:27:04
root / root
0644
color.py
20.989 KB
March 06 2024 00:27:04
root / root
0644
config.py
24.157 KB
March 06 2024 00:27:04
root / root
0644
dataclasses.py
11.221 KB
March 06 2024 00:27:04
root / root
0644
datetime_parse.py
0.146 KB
March 06 2024 00:27:04
root / root
0644
decorator.py
0.141 KB
March 06 2024 00:27:04
root / root
0644
env_settings.py
0.144 KB
March 06 2024 00:27:04
root / root
0644
error_wrappers.py
0.146 KB
March 06 2024 00:27:04
root / root
0644
errors.py
4.487 KB
March 06 2024 00:27:04
root / root
0644
fields.py
44.446 KB
March 06 2024 00:27:04
root / root
0644
functional_serializers.py
10.527 KB
March 06 2024 00:27:04
root / root
0644
functional_validators.py
19.991 KB
March 06 2024 00:27:04
root / root
0644
generics.py
0.14 KB
March 06 2024 00:27:04
root / root
0644
json.py
0.136 KB
March 06 2024 00:27:04
root / root
0644
json_schema.py
98.326 KB
March 06 2024 00:27:04
root / root
0644
main.py
60.801 KB
March 06 2024 00:27:04
root / root
0644
mypy.py
49.532 KB
March 06 2024 00:27:04
root / root
0644
networks.py
20.062 KB
March 06 2024 00:27:04
root / root
0644
parse.py
0.137 KB
March 06 2024 00:27:04
root / root
0644
py.typed
0 KB
March 06 2024 00:27:04
root / root
0644
root_model.py
4.833 KB
March 06 2024 00:27:04
root / root
0644
schema.py
0.138 KB
March 06 2024 00:27:04
root / root
0644
tools.py
0.137 KB
March 06 2024 00:27:04
root / root
0644
type_adapter.py
18.377 KB
March 06 2024 00:27:04
root / root
0644
types.py
70.538 KB
March 06 2024 00:27:04
root / root
0644
typing.py
0.134 KB
March 06 2024 00:27:04
root / root
0644
utils.py
0.137 KB
March 06 2024 00:27:04
root / root
0644
validate_call.py
1.738 KB
March 06 2024 00:27:04
root / root
0644
validators.py
0.142 KB
March 06 2024 00:27:04
root / root
0644
version.py
2.253 KB
March 06 2024 00:27:04
root / root
0644
warnings.py
1.901 KB
March 06 2024 00:27:04
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF