summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-15 12:44:37 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-15 12:44:37 -0500
commit5a832a49e37ca9259fbad286335367927d0ec60e (patch)
tree2654979a0c3fdb048588850276e827d93df450e5 /lib/sqlalchemy/util
parentbff2f6f3fbb0450cb9d0d09a25845a437c3df85e (diff)
downloadsqlalchemy-5a832a49e37ca9259fbad286335367927d0ec60e.tar.gz
- an approach I like better, remove most adapt() methods and use a generic
copier - mssql reflection fix, but this will come in again from the tip merge
Diffstat (limited to 'lib/sqlalchemy/util')
-rw-r--r--lib/sqlalchemy/util/__init__.py3
-rw-r--r--lib/sqlalchemy/util/langhelpers.py13
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py
index 9119e35b7..ae1eb3ac5 100644
--- a/lib/sqlalchemy/util/__init__.py
+++ b/lib/sqlalchemy/util/__init__.py
@@ -24,7 +24,8 @@ from langhelpers import iterate_attributes, class_hierarchy, \
reset_memoized, group_expirable_memoized_property, importlater, \
monkeypatch_proxied_specials, asbool, bool_or_str, coerce_kw_type,\
duck_type_collection, assert_arg_type, symbol, dictlike_iteritems,\
- classproperty, set_creation_order, warn_exception, warn, NoneType
+ classproperty, set_creation_order, warn_exception, warn, NoneType,\
+ constructor_copy
from deprecations import warn_deprecated, warn_pending_deprecation, \
deprecated, pending_deprecation
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index d85793ee0..945e2a6bd 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -516,6 +516,19 @@ def coerce_kw_type(kw, key, type_, flexi_bool=True):
else:
kw[key] = type_(kw[key])
+
+def constructor_copy(obj, cls, **kw):
+ """Instantiate cls using the __dict__ of obj as constructor arguments.
+
+ Uses inspect to match the named arguments of ``cls``.
+
+ """
+
+ names = get_cls_kwargs(cls)
+ kw.update((k, obj.__dict__[k]) for k in names if k in obj.__dict__)
+ return cls(**kw)
+
+
def duck_type_collection(specimen, default=None):
"""Given an instance or class, guess if it is or is acting as one of
the basic collection types: list, set and dict. If the __emulates__