示例#1
0
def _hash_or_string(key):
    if is_string_like(key) or isinstance(key, (types.IntType, types.LongType, types.FloatType)):
        return smart_str(key)
    else:
        try:
            #if it has a PK, use it.
            return str(key._get_pk_val())
        except AttributeError:
            return md5_hash(key)
示例#2
0
        def _resolve_key(self, raw):
            if is_string_like(raw):
                key = raw

            elif isinstance(raw, values.ConfigurationGroup):
                key = raw.key
                
            else:
                group = self.groups()[raw]
                key = group.key

            return key
示例#3
0
        def _resolve_key(self, raw):
            if is_string_like(raw):
                key = raw

            elif isinstance(raw, values.ConfigurationGroup):
                key = raw.key

            else:
                group = self.groups()[raw]
                key = group.key

            return key
示例#4
0
 def to_python(self, value):
     if not value or value == NOTSET:
         return []
     if is_list_or_tuple(value):
         return value
     else:
         try:
             return simplejson.loads(value)
         except:
             if is_string_like(value):
                 return [value]
             else:
                 log.warning('Could not decode returning empty list: %s', value)
                 return []
示例#5
0
 def to_python(self, value):
     if not value or value == NOTSET:
         return []
     if is_list_or_tuple(value):
         return value
     else:
         try:
             return simplejson.loads(value)
         except:
             if is_string_like(value):
                 return [value]
             else:
                 log.warning('Could not decode returning empty list: %s',
                             value)
                 return []
示例#6
0
def cache_key(*keys, **pairs):
    """Smart key maker, returns the object itself if a key, else a list 
    delimited by ':', automatically hashing any non-scalar objects."""

    if is_string_like(keys):
        keys = [keys]
        
    if is_list_or_tuple(keys):
        if len(keys) == 1 and is_list_or_tuple(keys[0]):
            keys = keys[0]
    else:
        keys = [md5_hash(keys)]

    if pairs:
        keys = list(keys)
        klist = pairs.keys()
        klist.sort()
        for k in klist:
            keys.append(k)
            keys.append(pairs[k])
        
    key = KEY_DELIM.join([_hash_or_string(x) for x in keys])
    return key.replace(" ", ".")
示例#7
0
 def get_db_prep_save(self, value):
     if is_string_like(value):
         value = [value]
     return simplejson.dumps(value)
示例#8
0
文件: config.py 项目: abrar78/satchmo
def payment_live(settings):
    if is_string_like(settings):
        settings = config_get_group(settings)

    return config_value('PAYMENT', 'LIVE') and settings['LIVE']
示例#9
0
 def get_db_prep_save(self, value):
     if is_string_like(value):
         value = [value]
     return simplejson.dumps(value)
示例#10
0
def payment_live(settings):
    if is_string_like(settings):
        settings = config_get_group(settings)
        
    return config_value('PAYMENT', 'LIVE') and settings['LIVE']