How to use _normalize_key method in Slash

Best Python code snippet using slash

memcached.py

Source:memcached.py Github

copy

Full Screen

...45 # NOTE: servers is actually an already initialized memcache46 # client.47 self._client = servers48 self.key_prefix = to_native(key_prefix)49 def _normalize_key(self, key):50 key = to_native(key, 'utf-8')51 if self.key_prefix:52 key = self.key_prefix + key53 return key54 def _normalize_timeout(self, timeout):55 timeout = BaseCache._normalize_timeout(self, timeout)56 if timeout > 0:57 timeout = int(time()) + timeout58 return timeout59 def get(self, key):60 key = self._normalize_key(key)61 # memcached doesn't support keys longer than that. Because often62 # checks for so long keys can occur because it's tested from user63 # submitted data etc we fail silently for getting.64 if _test_memcached_key(key):65 return self._client.get(key)66 def get_dict(self, *keys):67 key_mapping = {}68 have_encoded_keys = False69 for key in keys:70 encoded_key = self._normalize_key(key)71 if not isinstance(key, str):72 have_encoded_keys = True73 if _test_memcached_key(key):74 key_mapping[encoded_key] = key75 _keys = list(key_mapping)76 d = rv = self._client.get_multi(_keys)77 if have_encoded_keys or self.key_prefix:78 rv = {}79 for key, value in iteritems(d):80 rv[key_mapping[key]] = value81 if len(rv) < len(keys):82 for key in keys:83 if key not in rv:84 rv[key] = None85 return rv86 def add(self, key, value, timeout=None):87 key = self._normalize_key(key)88 timeout = self._normalize_timeout(timeout)89 return self._client.add(key, value, timeout)90 def set(self, key, value, timeout=None):91 key = self._normalize_key(key)92 timeout = self._normalize_timeout(timeout)93 return self._client.set(key, value, timeout)94 def get_many(self, *keys):95 d = self.get_dict(*keys)96 return [d[key] for key in keys]97 def set_many(self, mapping, timeout=None):98 new_mapping = {}99 for key, value in _items(mapping):100 key = self._normalize_key(key)101 new_mapping[key] = value102 timeout = self._normalize_timeout(timeout)103 failed_keys = self._client.set_multi(new_mapping, timeout)104 return not failed_keys105 def delete(self, key):106 key = self._normalize_key(key)107 if _test_memcached_key(key):108 return self._client.delete(key)109 def delete_many(self, *keys):110 new_keys = []111 for key in keys:112 key = self._normalize_key(key)113 if _test_memcached_key(key):114 new_keys.append(key)115 return self._client.delete_multi(new_keys)116 def has(self, key):117 key = self._normalize_key(key)118 if _test_memcached_key(key):119 return self._client.append(key, '')120 return False121 def clear(self):122 return self._client.flush_all()123 def inc(self, key, delta=1):124 key = self._normalize_key(key)125 return self._client.incr(key, delta)126 def dec(self, key, delta=1):127 key = self._normalize_key(key)128 return self._client.decr(key, delta)129 def import_preferred_memcache_lib(self, servers):130 """Returns an initialized memcache client. Used by the constructor."""131 try:132 import pylibmc133 except ImportError:134 pass135 else:136 return pylibmc.Client(servers)137 try:138 from google.appengine.api import memcache139 except ImportError:140 pass141 else:...

Full Screen

Full Screen

word_counter.py

Source:word_counter.py Github

copy

Full Screen

...8 self9 , key: AnyStr10 , value: AnyStr11 ) -> None:12 normalized_key = self._normalize_key(key)13 super().__setitem__(normalized_key, value)14 def __getitem__(15 self16 , key: AnyStr17 ) -> AnyStr:18 normalized_key = self._normalize_key(key)19 return super().__getitem__(normalized_key)20 def get(21 self22 , key: AnyStr23 , default=None24 ) -> AnyStr:25 normalized_key = self._normalize_key(key)26 return super().get(normalized_key, default)27 @staticmethod28 def _normalize_key(29 key: AnyStr30 ) -> AnyStr:31 return key.casefold()32class CaseInsensitiveOrderedCounter(33 Counter34 , CaseInsensitiveOrderedDict35): # pragma no cover36 pass37class CaseInsensitiveOrderedWordCounter(38 CaseInsensitiveOrderedCounter39):40 @classmethod41 def count_words(42 cls...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful