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)
| 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. |