Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cassandra/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from collections import defaultdict
from collections.abc import Mapping
from functools import total_ordering
from hashlib import md5
import json
import logging
import re
Expand All @@ -28,6 +27,12 @@
import struct
import random

md5 = None
try:
from hashlib import md5
except ImportError as e:
pass

murmur3 = None
try:
from cassandra.murmur3 import murmur3
Expand Down Expand Up @@ -1827,6 +1832,8 @@ def __repr__(self):
class NoMurmur3(Exception):
pass

class NoMD5(Exception):
pass

class HashToken(Token):

Expand Down Expand Up @@ -1862,6 +1869,8 @@ class MD5Token(HashToken):

@classmethod
def hash_fn(cls, key):
if md5 is None:
raise NoMD5()
if isinstance(key, str):
key = key.encode('UTF-8')
return abs(varint_unpack(md5(key).digest()))
Expand Down