Загрузить файлы в «venv/Lib/site-packages/sqlalchemy/engine»
This commit is contained in:
62
venv/Lib/site-packages/sqlalchemy/engine/__init__.py
Normal file
62
venv/Lib/site-packages/sqlalchemy/engine/__init__.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# engine/__init__.py
|
||||||
|
# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
|
||||||
|
# <see AUTHORS file>
|
||||||
|
#
|
||||||
|
# This module is part of SQLAlchemy and is released under
|
||||||
|
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
||||||
|
"""SQL connections, SQL execution and high-level DB-API interface.
|
||||||
|
|
||||||
|
The engine package defines the basic components used to interface
|
||||||
|
DB-API modules with higher-level statement construction,
|
||||||
|
connection-management, execution and result contexts. The primary
|
||||||
|
"entry point" class into this package is the Engine and its public
|
||||||
|
constructor ``create_engine()``.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from . import events as events
|
||||||
|
from . import util as util
|
||||||
|
from .base import Connection as Connection
|
||||||
|
from .base import Engine as Engine
|
||||||
|
from .base import NestedTransaction as NestedTransaction
|
||||||
|
from .base import RootTransaction as RootTransaction
|
||||||
|
from .base import Transaction as Transaction
|
||||||
|
from .base import TwoPhaseTransaction as TwoPhaseTransaction
|
||||||
|
from .create import create_engine as create_engine
|
||||||
|
from .create import create_pool_from_url as create_pool_from_url
|
||||||
|
from .create import engine_from_config as engine_from_config
|
||||||
|
from .cursor import CursorResult as CursorResult
|
||||||
|
from .cursor import ResultProxy as ResultProxy
|
||||||
|
from .interfaces import AdaptedConnection as AdaptedConnection
|
||||||
|
from .interfaces import BindTyping as BindTyping
|
||||||
|
from .interfaces import Compiled as Compiled
|
||||||
|
from .interfaces import Connectable as Connectable
|
||||||
|
from .interfaces import ConnectArgsType as ConnectArgsType
|
||||||
|
from .interfaces import ConnectionEventsTarget as ConnectionEventsTarget
|
||||||
|
from .interfaces import CreateEnginePlugin as CreateEnginePlugin
|
||||||
|
from .interfaces import Dialect as Dialect
|
||||||
|
from .interfaces import ExceptionContext as ExceptionContext
|
||||||
|
from .interfaces import ExecutionContext as ExecutionContext
|
||||||
|
from .interfaces import TypeCompiler as TypeCompiler
|
||||||
|
from .mock import create_mock_engine as create_mock_engine
|
||||||
|
from .reflection import Inspector as Inspector
|
||||||
|
from .reflection import ObjectKind as ObjectKind
|
||||||
|
from .reflection import ObjectScope as ObjectScope
|
||||||
|
from .result import ChunkedIteratorResult as ChunkedIteratorResult
|
||||||
|
from .result import FilterResult as FilterResult
|
||||||
|
from .result import FrozenResult as FrozenResult
|
||||||
|
from .result import IteratorResult as IteratorResult
|
||||||
|
from .result import MappingResult as MappingResult
|
||||||
|
from .result import MergedResult as MergedResult
|
||||||
|
from .result import Result as Result
|
||||||
|
from .result import result_tuple as result_tuple
|
||||||
|
from .result import ScalarResult as ScalarResult
|
||||||
|
from .result import TupleResult as TupleResult
|
||||||
|
from .row import BaseRow as BaseRow
|
||||||
|
from .row import Row as Row
|
||||||
|
from .row import RowMapping as RowMapping
|
||||||
|
from .url import make_url as make_url
|
||||||
|
from .url import URL as URL
|
||||||
|
from .util import connection_memoize as connection_memoize
|
||||||
|
from ..sql import ddl as ddl
|
||||||
135
venv/Lib/site-packages/sqlalchemy/engine/_py_processors.py
Normal file
135
venv/Lib/site-packages/sqlalchemy/engine/_py_processors.py
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
# engine/_py_processors.py
|
||||||
|
# Copyright (C) 2010-2026 the SQLAlchemy authors and contributors
|
||||||
|
# <see AUTHORS file>
|
||||||
|
# Copyright (C) 2010 Gaetan de Menten gdementen@gmail.com
|
||||||
|
#
|
||||||
|
# This module is part of SQLAlchemy and is released under
|
||||||
|
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
||||||
|
"""defines generic type conversion functions, as used in bind and result
|
||||||
|
processors.
|
||||||
|
|
||||||
|
They all share one common characteristic: None is passed through unchanged.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from datetime import date as date_cls
|
||||||
|
from datetime import datetime as datetime_cls
|
||||||
|
from datetime import time as time_cls
|
||||||
|
from decimal import Decimal
|
||||||
|
import typing
|
||||||
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Type
|
||||||
|
from typing import TypeVar
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
_DT = TypeVar(
|
||||||
|
"_DT", bound=Union[datetime.datetime, datetime.time, datetime.date]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def str_to_datetime_processor_factory(
|
||||||
|
regexp: typing.Pattern[str], type_: Callable[..., _DT]
|
||||||
|
) -> Callable[[Optional[str]], Optional[_DT]]:
|
||||||
|
rmatch = regexp.match
|
||||||
|
# Even on python2.6 datetime.strptime is both slower than this code
|
||||||
|
# and it does not support microseconds.
|
||||||
|
has_named_groups = bool(regexp.groupindex)
|
||||||
|
|
||||||
|
def process(value: Optional[str]) -> Optional[_DT]:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
m = rmatch(value)
|
||||||
|
except TypeError as err:
|
||||||
|
raise ValueError(
|
||||||
|
"Couldn't parse %s string '%r' "
|
||||||
|
"- value is not a string." % (type_.__name__, value)
|
||||||
|
) from err
|
||||||
|
|
||||||
|
if m is None:
|
||||||
|
raise ValueError(
|
||||||
|
"Couldn't parse %s string: "
|
||||||
|
"'%s'" % (type_.__name__, value)
|
||||||
|
)
|
||||||
|
if has_named_groups:
|
||||||
|
groups = m.groupdict(0)
|
||||||
|
return type_(
|
||||||
|
**dict(
|
||||||
|
list(
|
||||||
|
zip(
|
||||||
|
iter(groups.keys()),
|
||||||
|
list(map(int, iter(groups.values()))),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return type_(*list(map(int, m.groups(0))))
|
||||||
|
|
||||||
|
return process
|
||||||
|
|
||||||
|
|
||||||
|
def to_decimal_processor_factory(
|
||||||
|
target_class: Type[Decimal], scale: int
|
||||||
|
) -> Callable[[Optional[float]], Optional[Decimal]]:
|
||||||
|
fstring = "%%.%df" % scale
|
||||||
|
|
||||||
|
def process(value: Optional[float]) -> Optional[Decimal]:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return target_class(fstring % value)
|
||||||
|
|
||||||
|
return process
|
||||||
|
|
||||||
|
|
||||||
|
def to_float(value: Optional[Union[int, float]]) -> Optional[float]:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return float(value)
|
||||||
|
|
||||||
|
|
||||||
|
def to_str(value: Optional[Any]) -> Optional[str]:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
def int_to_boolean(value: Optional[int]) -> Optional[bool]:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return bool(value)
|
||||||
|
|
||||||
|
|
||||||
|
def str_to_datetime(value: Optional[str]) -> Optional[datetime.datetime]:
|
||||||
|
if value is not None:
|
||||||
|
dt_value = datetime_cls.fromisoformat(value)
|
||||||
|
else:
|
||||||
|
dt_value = None
|
||||||
|
return dt_value
|
||||||
|
|
||||||
|
|
||||||
|
def str_to_time(value: Optional[str]) -> Optional[datetime.time]:
|
||||||
|
if value is not None:
|
||||||
|
dt_value = time_cls.fromisoformat(value)
|
||||||
|
else:
|
||||||
|
dt_value = None
|
||||||
|
return dt_value
|
||||||
|
|
||||||
|
|
||||||
|
def str_to_date(value: Optional[str]) -> Optional[datetime.date]:
|
||||||
|
if value is not None:
|
||||||
|
dt_value = date_cls.fromisoformat(value)
|
||||||
|
else:
|
||||||
|
dt_value = None
|
||||||
|
return dt_value
|
||||||
128
venv/Lib/site-packages/sqlalchemy/engine/_py_row.py
Normal file
128
venv/Lib/site-packages/sqlalchemy/engine/_py_row.py
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# engine/_py_row.py
|
||||||
|
# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
|
||||||
|
# <see AUTHORS file>
|
||||||
|
#
|
||||||
|
# This module is part of SQLAlchemy and is released under
|
||||||
|
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import operator
|
||||||
|
import typing
|
||||||
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Iterator
|
||||||
|
from typing import List
|
||||||
|
from typing import Mapping
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Tuple
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from .result import _KeyType
|
||||||
|
from .result import _ProcessorsType
|
||||||
|
from .result import _RawRowType
|
||||||
|
from .result import _TupleGetterType
|
||||||
|
from .result import ResultMetaData
|
||||||
|
|
||||||
|
MD_INDEX = 0 # integer index in cursor.description
|
||||||
|
|
||||||
|
|
||||||
|
class BaseRow:
|
||||||
|
__slots__ = ("_parent", "_data", "_key_to_index")
|
||||||
|
|
||||||
|
_parent: ResultMetaData
|
||||||
|
_key_to_index: Mapping[_KeyType, int]
|
||||||
|
_data: _RawRowType
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
parent: ResultMetaData,
|
||||||
|
processors: Optional[_ProcessorsType],
|
||||||
|
key_to_index: Mapping[_KeyType, int],
|
||||||
|
data: _RawRowType,
|
||||||
|
):
|
||||||
|
"""Row objects are constructed by CursorResult objects."""
|
||||||
|
object.__setattr__(self, "_parent", parent)
|
||||||
|
|
||||||
|
object.__setattr__(self, "_key_to_index", key_to_index)
|
||||||
|
|
||||||
|
if processors:
|
||||||
|
object.__setattr__(
|
||||||
|
self,
|
||||||
|
"_data",
|
||||||
|
tuple(
|
||||||
|
[
|
||||||
|
proc(value) if proc else value
|
||||||
|
for proc, value in zip(processors, data)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
object.__setattr__(self, "_data", tuple(data))
|
||||||
|
|
||||||
|
def __reduce__(self) -> Tuple[Callable[..., BaseRow], Tuple[Any, ...]]:
|
||||||
|
return (
|
||||||
|
rowproxy_reconstructor,
|
||||||
|
(self.__class__, self.__getstate__()),
|
||||||
|
)
|
||||||
|
|
||||||
|
def __getstate__(self) -> Dict[str, Any]:
|
||||||
|
return {"_parent": self._parent, "_data": self._data}
|
||||||
|
|
||||||
|
def __setstate__(self, state: Dict[str, Any]) -> None:
|
||||||
|
parent = state["_parent"]
|
||||||
|
object.__setattr__(self, "_parent", parent)
|
||||||
|
object.__setattr__(self, "_data", state["_data"])
|
||||||
|
object.__setattr__(self, "_key_to_index", parent._key_to_index)
|
||||||
|
|
||||||
|
def _values_impl(self) -> List[Any]:
|
||||||
|
return list(self)
|
||||||
|
|
||||||
|
def __iter__(self) -> Iterator[Any]:
|
||||||
|
return iter(self._data)
|
||||||
|
|
||||||
|
def __len__(self) -> int:
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash(self._data)
|
||||||
|
|
||||||
|
def __getitem__(self, key: Any) -> Any:
|
||||||
|
return self._data[key]
|
||||||
|
|
||||||
|
def _get_by_key_impl_mapping(self, key: str) -> Any:
|
||||||
|
try:
|
||||||
|
return self._data[self._key_to_index[key]]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
self._parent._key_not_found(key, False)
|
||||||
|
|
||||||
|
def __getattr__(self, name: str) -> Any:
|
||||||
|
try:
|
||||||
|
return self._data[self._key_to_index[name]]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
self._parent._key_not_found(name, True)
|
||||||
|
|
||||||
|
def _to_tuple_instance(self) -> Tuple[Any, ...]:
|
||||||
|
return self._data
|
||||||
|
|
||||||
|
|
||||||
|
# This reconstructor is necessary so that pickles with the Cy extension or
|
||||||
|
# without use the same Binary format.
|
||||||
|
def rowproxy_reconstructor(
|
||||||
|
cls: Type[BaseRow], state: Dict[str, Any]
|
||||||
|
) -> BaseRow:
|
||||||
|
obj = cls.__new__(cls)
|
||||||
|
obj.__setstate__(state)
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def tuplegetter(*indexes: int) -> _TupleGetterType:
|
||||||
|
if len(indexes) != 1:
|
||||||
|
for i in range(1, len(indexes)):
|
||||||
|
if indexes[i - 1] != indexes[i] - 1:
|
||||||
|
return operator.itemgetter(*indexes)
|
||||||
|
# slice form is faster but returns a list if input is list
|
||||||
|
return operator.itemgetter(slice(indexes[0], indexes[-1] + 1))
|
||||||
74
venv/Lib/site-packages/sqlalchemy/engine/_py_util.py
Normal file
74
venv/Lib/site-packages/sqlalchemy/engine/_py_util.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# engine/_py_util.py
|
||||||
|
# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
|
||||||
|
# <see AUTHORS file>
|
||||||
|
#
|
||||||
|
# This module is part of SQLAlchemy and is released under
|
||||||
|
# the MIT License: https://www.opensource.org/licenses/mit-license.php
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import typing
|
||||||
|
from typing import Any
|
||||||
|
from typing import Mapping
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
|
from .. import exc
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from .interfaces import _CoreAnyExecuteParams
|
||||||
|
from .interfaces import _CoreMultiExecuteParams
|
||||||
|
from .interfaces import _DBAPIAnyExecuteParams
|
||||||
|
from .interfaces import _DBAPIMultiExecuteParams
|
||||||
|
|
||||||
|
|
||||||
|
_no_tuple: Tuple[Any, ...] = ()
|
||||||
|
|
||||||
|
|
||||||
|
def _distill_params_20(
|
||||||
|
params: Optional[_CoreAnyExecuteParams],
|
||||||
|
) -> _CoreMultiExecuteParams:
|
||||||
|
if params is None:
|
||||||
|
return _no_tuple
|
||||||
|
# Assume list is more likely than tuple
|
||||||
|
elif isinstance(params, list) or isinstance(params, tuple):
|
||||||
|
# collections_abc.MutableSequence): # avoid abc.__instancecheck__
|
||||||
|
if params and not isinstance(params[0], Mapping):
|
||||||
|
raise exc.ArgumentError(
|
||||||
|
"List argument must consist only of dictionaries"
|
||||||
|
)
|
||||||
|
|
||||||
|
return params
|
||||||
|
elif isinstance(params, dict) or isinstance(
|
||||||
|
# only do immutabledict or abc.__instancecheck__ for Mapping after
|
||||||
|
# we've checked for plain dictionaries and would otherwise raise
|
||||||
|
params,
|
||||||
|
Mapping,
|
||||||
|
):
|
||||||
|
return [params]
|
||||||
|
else:
|
||||||
|
raise exc.ArgumentError("mapping or list expected for parameters")
|
||||||
|
|
||||||
|
|
||||||
|
def _distill_raw_params(
|
||||||
|
params: Optional[_DBAPIAnyExecuteParams],
|
||||||
|
) -> _DBAPIMultiExecuteParams:
|
||||||
|
if params is None:
|
||||||
|
return _no_tuple
|
||||||
|
elif isinstance(params, list):
|
||||||
|
# collections_abc.MutableSequence): # avoid abc.__instancecheck__
|
||||||
|
if params and not isinstance(params[0], (tuple, Mapping)):
|
||||||
|
raise exc.ArgumentError(
|
||||||
|
"List argument must consist only of tuples or dictionaries"
|
||||||
|
)
|
||||||
|
|
||||||
|
return params
|
||||||
|
elif isinstance(params, (tuple, dict)) or isinstance(
|
||||||
|
# only do abc.__instancecheck__ for Mapping after we've checked
|
||||||
|
# for plain dictionaries and would otherwise raise
|
||||||
|
params,
|
||||||
|
Mapping,
|
||||||
|
):
|
||||||
|
# cast("Union[List[Mapping[str, Any]], Tuple[Any, ...]]", [params])
|
||||||
|
return [params] # type: ignore
|
||||||
|
else:
|
||||||
|
raise exc.ArgumentError("mapping or sequence expected for parameters")
|
||||||
3392
venv/Lib/site-packages/sqlalchemy/engine/base.py
Normal file
3392
venv/Lib/site-packages/sqlalchemy/engine/base.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user