]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
copy immutabledict here to remove dependency on sqla 0.7, [#36] rel_0_2_2
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Mar 2012 04:59:22 +0000 (21:59 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Mar 2012 04:59:22 +0000 (21:59 -0700)
alembic/ddl/impl.py
alembic/util.py

index 32f4860e83f65bc5edaf4b570103b5f7b2c4bde0..c87189b3c478bd385ab6f4884a220fa9cb9c467a 100644 (file)
@@ -5,7 +5,6 @@ from sqlalchemy import schema
 from alembic.ddl import base
 from alembic import util
 from sqlalchemy import types as sqltypes
-from sqlalchemy import util as sqla_util
 
 class ImplMeta(type):
     def __init__(cls, classname, bases, dict_):
@@ -58,7 +57,7 @@ class DefaultImpl(object):
 
     def _exec(self, construct, execution_options=None, 
                             multiparams=(), 
-                            params=sqla_util.immutabledict()):
+                            params=util.immutabledict()):
         if isinstance(construct, basestring):
             construct = text(construct)
         if self.as_sql:
index eb2d11e7b4fd28d6b31a1907c235ce590b70809a..d5fa5a45856e139feb2acbfae37fb8b2fe501e3c 100644 (file)
@@ -210,3 +210,34 @@ class memoized_property(object):
         obj.__dict__[self.__name__] = result = self.fget(obj)
         return result
 
+
+class immutabledict(dict):
+
+    def _immutable(self, *arg, **kw):
+        raise TypeError("%s object is immutable" % self.__class__.__name__)
+
+    __delitem__ = __setitem__ = __setattr__ = \
+    clear = pop = popitem = setdefault = \
+        update = _immutable
+
+    def __new__(cls, *args):
+        new = dict.__new__(cls)
+        dict.__init__(new, *args)
+        return new
+
+    def __init__(self, *args):
+        pass
+
+    def __reduce__(self):
+        return immutabledict, (dict(self), )
+
+    def union(self, d):
+        if not self:
+            return immutabledict(d)
+        else:
+            d2 = immutabledict(self)
+            dict.update(d2, d)
+            return d2
+
+    def __repr__(self):
+        return "immutabledict(%s)" % dict.__repr__(self)