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)
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
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 []
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(" ", ".")
def get_db_prep_save(self, value): if is_string_like(value): value = [value] return simplejson.dumps(value)
def payment_live(settings): if is_string_like(settings): settings = config_get_group(settings) return config_value('PAYMENT', 'LIVE') and settings['LIVE']