summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r--lib/sqlalchemy/ext/associationproxy.py13
-rw-r--r--lib/sqlalchemy/ext/asyncio/session.py2
-rw-r--r--lib/sqlalchemy/ext/baked.py2
-rw-r--r--lib/sqlalchemy/ext/indexable.py2
-rw-r--r--lib/sqlalchemy/ext/serializer.py17
5 files changed, 14 insertions, 22 deletions
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py
index 0aa836a3c..9e8f84f46 100644
--- a/lib/sqlalchemy/ext/associationproxy.py
+++ b/lib/sqlalchemy/ext/associationproxy.py
@@ -1093,14 +1093,11 @@ class _AssociationList(_AssociationCollection):
col.append(item)
def count(self, value):
- return sum(
- [
- 1
- for _ in util.itertools_filter(
- lambda v: v == value, iter(self)
- )
- ]
- )
+ count = 0
+ for v in self:
+ if v == value:
+ count += 1
+ return count
def extend(self, values):
for v in values:
diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py
index d2c969056..89da4b497 100644
--- a/lib/sqlalchemy/ext/asyncio/session.py
+++ b/lib/sqlalchemy/ext/asyncio/session.py
@@ -540,7 +540,7 @@ class AsyncSession(ReversibleProxy):
await self.close()
def _maker_context_manager(self):
- # no @contextlib.asynccontextmanager until python3.7, gr
+ # TODO: can this use asynccontextmanager ??
return _AsyncSessionContextManager(self)
diff --git a/lib/sqlalchemy/ext/baked.py b/lib/sqlalchemy/ext/baked.py
index efdafff96..e91277311 100644
--- a/lib/sqlalchemy/ext/baked.py
+++ b/lib/sqlalchemy/ext/baked.py
@@ -13,6 +13,7 @@ compiled result to be fully cached.
"""
+import collections.abc as collections_abc
import logging
from .. import exc as sa_exc
@@ -24,7 +25,6 @@ from ..orm.session import Session
from ..sql import func
from ..sql import literal_column
from ..sql import util as sql_util
-from ..util import collections_abc
log = logging.getLogger(__name__)
diff --git a/lib/sqlalchemy/ext/indexable.py b/lib/sqlalchemy/ext/indexable.py
index 313ad11af..70673ac26 100644
--- a/lib/sqlalchemy/ext/indexable.py
+++ b/lib/sqlalchemy/ext/indexable.py
@@ -221,8 +221,6 @@ The above query will render::
WHERE CAST(person.data ->> %(data_1)s AS INTEGER) < %(param_1)s
""" # noqa
-from __future__ import absolute_import
-
from .. import inspect
from .. import util
from ..ext.hybrid import hybrid_property
diff --git a/lib/sqlalchemy/ext/serializer.py b/lib/sqlalchemy/ext/serializer.py
index 18a54e079..c9bff9d28 100644
--- a/lib/sqlalchemy/ext/serializer.py
+++ b/lib/sqlalchemy/ext/serializer.py
@@ -53,6 +53,8 @@ needed for:
"""
+from io import BytesIO
+import pickle
import re
from .. import Column
@@ -64,9 +66,6 @@ from ..orm.mapper import Mapper
from ..orm.session import Session
from ..util import b64decode
from ..util import b64encode
-from ..util import byte_buffer
-from ..util import pickle
-from ..util import text_type
__all__ = ["Serializer", "Deserializer", "dumps", "loads"]
@@ -92,11 +91,9 @@ def Serializer(*args, **kw):
pickle.dumps(obj._annotations["parententity"].class_)
)
else:
- id_ = "table:" + text_type(obj.key)
+ id_ = f"table:{obj.key}"
elif isinstance(obj, Column) and isinstance(obj.table, Table):
- id_ = (
- "column:" + text_type(obj.table.key) + ":" + text_type(obj.key)
- )
+ id_ = f"column:{obj.table.key}:{obj.key}"
elif isinstance(obj, Session):
id_ = "session:"
elif isinstance(obj, Engine):
@@ -129,7 +126,7 @@ def Deserializer(file, metadata=None, scoped_session=None, engine=None):
return None
def persistent_load(id_):
- m = our_ids.match(text_type(id_))
+ m = our_ids.match(str(id_))
if not m:
return None
else:
@@ -165,13 +162,13 @@ def Deserializer(file, metadata=None, scoped_session=None, engine=None):
def dumps(obj, protocol=pickle.HIGHEST_PROTOCOL):
- buf = byte_buffer()
+ buf = BytesIO()
pickler = Serializer(buf, protocol)
pickler.dump(obj)
return buf.getvalue()
def loads(data, metadata=None, scoped_session=None, engine=None):
- buf = byte_buffer(data)
+ buf = BytesIO(data)
unpickler = Deserializer(buf, metadata, scoped_session, engine)
return unpickler.load()