MCPcopy Index your code
hub / github.com/davidaurelio/hashids-python / decode

Method decode

hashids.py:231–248  ·  view source on GitHub ↗

Restore a tuple of numbers from the passed `hashid`. :param hashid The hashid to decode >>> hashids = Hashids('arbitrary salt', 16, 'abcdefghijkl0123456') >>> hashids.decode('1d6216i30h53elk3') (1, 23, 456)

(self, hashid)

Source from the content-addressed store, hash-verified

229 self._separators, self._guards)
230
231 def decode(self, hashid):
232 """Restore a tuple of numbers from the passed `hashid`.
233
234 :param hashid The hashid to decode
235
236 >>> hashids = Hashids('arbitrary salt', 16, 'abcdefghijkl0123456')
237 >>> hashids.decode('1d6216i30h53elk3')
238 (1, 23, 456)
239 """
240 if not hashid or not _is_str(hashid):
241 return ()
242 try:
243 numbers = tuple(_decode(hashid, self._salt, self._alphabet,
244 self._separators, self._guards))
245
246 return numbers if hashid == self.encode(*numbers) else ()
247 except ValueError:
248 return ()
249
250 def encode_hex(self, hex_str):
251 """Converts a hexadecimal string (e.g. a MongoDB id) to a hashid.

Callers 15

decode_hexMethod · 0.95
test_single_numberMethod · 0.95
test_multiple_numbersMethod · 0.95
test_saltMethod · 0.95
test_alphabetMethod · 0.95
test_min_lengthMethod · 0.95
test_all_parametersMethod · 0.95
test_only_one_validMethod · 0.95
test_empty_stringMethod · 0.80
test_non_stringMethod · 0.80

Calls 3

encodeMethod · 0.95
_is_strFunction · 0.85
_decodeFunction · 0.85

Tested by 14

test_single_numberMethod · 0.76
test_multiple_numbersMethod · 0.76
test_saltMethod · 0.76
test_alphabetMethod · 0.76
test_min_lengthMethod · 0.76
test_all_parametersMethod · 0.76
test_only_one_validMethod · 0.76
test_empty_stringMethod · 0.64
test_non_stringMethod · 0.64
test_default_saltMethod · 0.64