Skip to content

Commit

Permalink
copy immutabledict here to remove dependency on sqla 0.7, [#36]
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeek committed Mar 13, 2012
1 parent 8abe0a3 commit 4941914
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions alembic/ddl/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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_):
Expand Down Expand Up @@ -58,7 +57,7 @@ def bind(self):

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:
Expand Down
31 changes: 31 additions & 0 deletions alembic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,34 @@ def __get__(self, obj, cls):
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)

0 comments on commit 4941914

Please sign in to comment.