Esempio n. 1
0
    def __init__(cls, name, bases, dict):
        super(ModelMeta, cls).__init__(name, bases, dict)
        # Make sure this is a subclass of Model - mainly copied from django ModelBase (thanks!)
        cls.__sub_classes__ = []

        # Do a delayed import to prevent possible circular import errors.
        from fcu_boto.sdb.db.manager import get_manager

        try:
            if filter(lambda b: issubclass(b, Model), bases):
                for base in bases:
                    base.__sub_classes__.append(cls)
                cls._manager = get_manager(cls)
                # look for all of the Properties and set their names
                for key in dict.keys():
                    if isinstance(dict[key], Property):
                        property = dict[key]
                        property.__property_config__(cls, key)
                prop_names = []
                props = cls.properties()
                for prop in props:
                    if not prop.__class__.__name__.startswith('_'):
                        prop_names.append(prop.name)
                setattr(cls, '_prop_names', prop_names)
        except NameError:
            # 'Model' isn't defined yet, meaning we're looking at our own
            # Model class, defined below.
            pass
Esempio n. 2
0
 def wrapper(*args, **kw):
     hasgroup = lambda group: all(key in kw for key in group)
     if len(list(filter(hasgroup, groups))) not in (0, 1):
         message = ' OR '.join(['+'.join(g) for g in groups])
         message = "{0} requires either {1}" \
                   "".format(func.action, message)
         raise KeyError(message)
     return func(*args, **kw)
Esempio n. 3
0
 def requires(*args, **kw):
     hasgroup = lambda group: all(key in kw for key in group)
     if 1 != len(list(filter(hasgroup, groups))):
         message = ' OR '.join(['+'.join(g) for g in groups])
         message = "{0} requires {1} argument(s)" \
                   "".format(func.action, message)
         raise KeyError(message)
     return func(*args, **kw)
Esempio n. 4
0
 def __repr__(self):
     render = lambda pair: '{0!s}: {1!r}'.format(*pair)
     do_show = lambda pair: not pair[0].startswith('_')
     attrs = filter(do_show, self.__dict__.items())
     name = self.__class__.__name__
     if name.startswith('JIT_'):
         name = '^{0}^'.format(self._name or '')
     return '{0}{1!r}({2})'.format(name, self.copy(),
                                   ', '.join(map(render, attrs)))
Esempio n. 5
0
    def _declared(self, op, **kw):
        def inherit(obj):
            result = {}
            for cls in getattr(obj, '__bases__', ()):
                result.update(inherit(cls))
            result.update(obj.__dict__)
            return result

        scope = inherit(self.__class__)
        scope.update(self.__dict__)
        declared = lambda attr: isinstance(attr[1], DeclarativeType)
        for name, node in filter(declared, scope.items()):
            getattr(node, op)(self, name, parentname=self._name, **kw)
Esempio n. 6
0
 def _encode_n(self, attr):
     try:
         if isinstance(attr, float) and not hasattr(Decimal, 'from_float'):
             # python2.6 does not support creating Decimals directly
             # from floats so we have to do this ourself.
             n = str(float_to_decimal(attr))
         else:
             n = str(DYNAMODB_CONTEXT.create_decimal(attr))
         if list(filter(lambda x: x in n, ('Infinity', 'NaN'))):
             raise TypeError('Infinity and NaN not supported')
         return n
     except (TypeError, DecimalException) as e:
         msg = '{0} numeric for `{1}`\n{2}'.format(e.__class__.__name__,
                                                   attr,
                                                   str(e) or '')
     raise DynamoDBNumberError(msg)
Esempio n. 7
0
 def __repr__(self):
     values = [getattr(self, key, None) for key in self._dimensions]
     values = filter(None, values)
     return 'x'.join(map('{0.Value:0.2f}{0[Units]}'.format, values))
Esempio n. 8
0
 def wrapper(*args, **kw):
     members = kwargs.get('members', False)
     for field in filter(lambda i: i in kw, fields):
         destructure_object(kw.pop(field), kw, field, members=members)
     return func(*args, **kw)
Esempio n. 9
0
 def __repr__(self):
     render = lambda pair: '{!s}: {!r}'.format(*pair)
     do_show = lambda pair: not pair[0].startswith('_')
     attrs = filter(do_show, self.__dict__.items())
     return '{0}({1})'.format(self.__class__.__name__,
                              ', '.join(map(render, attrs)))