Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(4)  |  Derive(0)  |  Import(4)
Removes control characters and ensures that key will
not hit the memcached key length limit by replacing
the key tail with md5 hash if key is too long.

        def sanitize_memcached_key(key, max_length=250):
    """ Removes control characters and ensures that key will
        not hit the memcached key length limit by replacing
        the key tail with md5 hash if key is too long.
    """
    key = ''.join([c for c in key if c not in CONTROL_CHARACTERS])
    if len(key) > max_length:
        hash = md5(key).hexdigest()
        key = key[:max_length-33]+'-'+hash
    return key
        


src/h/s/hscacheutils-0.1.6/hscacheutils/generational_cache.py   hscacheutils(Download)
 
from cache_utils.utils import _cache_key, _func_info
from cache_utils.utils import sanitize_memcached_key as orig_sanitize_memcached_key
 
from hscacheutils.raw_cache import cache as raw_cache, MAX_MEMCACHE_TIMEOUT
    (since django is still appending it's version number to this key we build).
    """
    return orig_sanitize_memcached_key(key, max_length=240)
 
def parse_generation(generation):

src/d/j/django-cache-utils-0.7.2/cache_utils/decorators.py   django-cache-utils(Download)
#coding: utf-8
from django.core.cache import cache
from django.utils.functional import wraps
from cache_utils.utils import _cache_key, _func_info, _func_type, sanitize_memcached_key
 
        def get_key(*args, **kwargs):
            return sanitize_memcached_key(_cache_key(*args, **kwargs))
 
    def _cached(func):
 

src/d/j/django-cache-utils-0.7.2/cache_utils/group_backend.py   django-cache-utils(Download)
from django.utils.encoding import smart_str
 
from cache_utils.utils import sanitize_memcached_key
 
# This prefix is appended to the group name to prevent cache key clashes.
                hashkey = self._get_hashkey(group)
            key = "%s:%s-%s" % (group, key, hashkey)
        return sanitize_memcached_key(key)
 
    def make_key(self, key, *args, **kwargs):

src/d/j/django-cache-utils-0.7.2/cache_utils/tests.py   django-cache-utils(Download)
from django.core.cache import cache
from cache_utils.decorators import cached
from cache_utils.utils import sanitize_memcached_key, _func_type, _func_info
 
def foo(a,b):
    def test_sanitize_keys(self):
        key = u"12345678901234567890123456789012345678901234567890"
        self.assertTrue(len(key) >= 40)
        key = sanitize_memcached_key(key, 40)
        self.assertTrue(len(key) <= 40)