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

Method encode_hex

hashids.py:250–263  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 3

test_decode_hexMethod · 0.95
test_encode_hexMethod · 0.80
test_illegal_hexMethod · 0.80

Calls 1

encodeMethod · 0.95

Tested by 3

test_decode_hexMethod · 0.76
test_encode_hexMethod · 0.64
test_illegal_hexMethod · 0.64