Converts a hexadecimal string (e.g. a MongoDB id) to a hashid. :param hex_str The hexadecimal string to encodes >>> Hashids.encode_hex('507f1f77bcf86cd799439011') 'y42LW46J9luq3Xq9XMly'
(self, hex_str)
| 248 | return () |
| 249 | |
| 250 | def encode_hex(self, hex_str): |
| 251 | """Converts a hexadecimal string (e.g. a MongoDB id) to a hashid. |
| 252 | |
| 253 | :param hex_str The hexadecimal string to encodes |
| 254 | |
| 255 | >>> Hashids.encode_hex('507f1f77bcf86cd799439011') |
| 256 | 'y42LW46J9luq3Xq9XMly' |
| 257 | """ |
| 258 | numbers = (int('1' + hex_str[i:i+12], 16) |
| 259 | for i in range(0, len(hex_str), 12)) |
| 260 | try: |
| 261 | return self.encode(*numbers) |
| 262 | except ValueError: |
| 263 | return '' |
| 264 | |
| 265 | def decode_hex(self, hashid): |
| 266 | """Restores a hexadecimal string (e.g. a MongoDB id) from a hashid. |