def test_unicode_key(self): decorate, canary = self._keygen_decorator("mynamespace", to_str=compat.text_type) @decorate def one(a, b): pass gen = canary[0] eq_(gen(compat.u('méil'), compat.u('drôle')), compat.ue("tests.cache.test_decorator:" "one|mynamespace|m\xe9il dr\xf4le"))
def get_mutex(self, key): if self.distributed_lock: _key = u(self.lock_prefix).format(key) _mutex = self.client.lock(_key, self.lock_timeout, self.lock_sleep) if self.lock_class: return self.lock_class(_mutex) return _mutex else: return None
def test_unicode_key_multi(self): decorate, canary = self._multi_keygen_decorator( "mynamespace", to_str=compat.text_type) @decorate def one(a, b): pass gen = canary[0] eq_( gen(compat.u("méil"), compat.u("drôle")), [ compat.ue( "tests.cache.test_decorator:one|mynamespace|m\xe9il"), compat.ue( "tests.cache.test_decorator:one|mynamespace|dr\xf4le"), ], )
def get_mutex(self, key): if isinstance(key, tuple): # key can be a tuple key = ",".join(key) if self.distributed_lock: # redis.py command: `lock(name, timeout=None, sleep=0.1)` _key = u(self.lock_prefix).format(key) _mutex = self.client.lock(_key, self.lock_timeout, self.lock_sleep) if self.lock_class: return self.lock_class(_mutex) return _mutex else: return None