예제 #1
0
 def test_keys(self):
     self.assertTrue(StrKey(['id']) not in Dummy.__index_keys__)
     self.assertTrue(StrKey(['name']) in Dummy.__index_keys__)
     self.assertTrue(StrKey(['name', 'age']) in Dummy.__index_keys__)
     self.assertTrue(StrKey(['name', 'age']) not in Dummy.__unique_keys__)
     self.assertTrue(StrKey(['id']) not in Lala.__unique_keys__)
     self.assertTrue(StrKey(['name', 'age']) in Lala.__unique_keys__)
예제 #2
0
def _process_key(cls, key):
    if isinstance(key, StrKey):
        return key
    if not isinstance(key, (list, tuple, set)):
        key = (key, )
    _key = []
    for item in key:
        if isinstance(item, Field):
            _key.append(item.attr_name)
        elif isinstance(item, basestring):
            attr_name = item
            attr_name = cls.__field_name_map__.get(attr_name, attr_name)
            if not hasattr(cls, attr_name):
                cls._options.report(  # pragma: no cover
                    'The key of {} is error: {}. '
                    'Cannot find the attribute: `{}`'.format(
                        cls.__name__, key, attr_name))
                return  # pragma: no cover
            _key.append(item)
        else:
            raise RuntimeError(  # pragma: no cover
                '{}\'s key is not support this item: `{}`'.format(
                    cls.__name__, repr(item)))
    return StrKey(_key)
예제 #3
0
def get_str_key(keys):
    return StrKey(k.attr_name if not isinstance(k, str_types) else k
                  for k in keys)
예제 #4
0
def _product_index_keys(key):
    if len(key) == 0:
        yield StrKey()
    for i in xrange(1, len(key) + 1):
        yield StrKey(key[0:i])
예제 #5
0
def get_str_key(keys):
    return StrKey(k.attr_name if not isinstance(k, basestring) else k
                  for k in keys)