def user_avatar_hash(email): # Salting the user_key may be overkill, but it prevents us from # basically mimicking Gravatar's hashing scheme, which could lead # to some abuse scenarios like folks using us as a free Gravatar # replacement. user_key = email.lower() + settings.AVATAR_SALT return make_safe_digest(user_key, hashlib.sha1)
def gravatar_hash(email: Text) -> Text: """Compute the Gravatar hash for an email address.""" # Non-ASCII characters aren't permitted by the currently active e-mail # RFCs. However, the IETF has published https://tools.ietf.org/html/rfc4952, # outlining internationalization of email addresses, and regardless if we # typo an address or someone manages to give us a non-ASCII address, let's # not error out on it. return make_safe_digest(email.lower(), hashlib.md5)
def gravatar_hash(email): """Compute the Gravatar hash for an email address.""" # Non-ASCII characters aren't permitted by the currently active e-mail # RFCs. However, the IETF has published https://tools.ietf.org/html/rfc4952, # outlining internationalization of email addresses, and regardless if we # typo an address or someone manages to give us a non-ASCII address, let's # not error out on it. return make_safe_digest(email.lower(), hashlib.md5)
def get_stream_cache_key(stream_name, realm): from zerver.models import Realm if isinstance(realm, Realm): realm_id = realm.id else: realm_id = realm return "stream_by_realm_and_name:%s:%s" % ( realm_id, make_safe_digest(stream_name.strip().lower()))
def get_stream_cache_key(stream_name, realm): # type: (text_type, Union[Realm, int]) -> text_type from zerver.models import Realm if isinstance(realm, Realm): realm_id = realm.id else: realm_id = realm return u"stream_by_realm_and_name:%s:%s" % (realm_id, make_safe_digest(stream_name.strip().lower()))
def get_stream_cache_key(stream_name, realm): # type: (text_type, Union[Realm, int]) -> text_type from zerver.models import Realm if isinstance(realm, Realm): realm_id = realm.id else: realm_id = realm return u"stream_by_realm_and_name:%s:%s" % ( realm_id, make_safe_digest(stream_name.strip().lower()))
def user_avatar_hash(uid: Text) -> Text: # WARNING: If this method is changed, you may need to do a migration # similar to zerver/migrations/0060_move_avatars_to_be_uid_based.py . # The salt probably doesn't serve any purpose now. In the past we # used a hash of the email address, not the user ID, and we salted # it in order to make the hashing scheme different from Gravatar's. user_key = uid + settings.AVATAR_SALT return make_safe_digest(user_key, hashlib.sha1)
def user_avatar_hash(uid: str) -> str: # WARNING: If this method is changed, you may need to do a migration # similar to zerver/migrations/0060_move_avatars_to_be_uid_based.py . # The salt probably doesn't serve any purpose now. In the past we # used a hash of the email address, not the user ID, and we salted # it in order to make the hashing scheme different from Gravatar's. user_key = uid + settings.AVATAR_SALT return make_safe_digest(user_key, hashlib.sha1)
def user_profile_cache_key(email, realm): # type: (Text, Realm) -> Text return u"user_profile:%s:%s" % (make_safe_digest(email.strip()), realm.id,)
def open_graph_description_cache_key(content: bytes, request: HttpRequest) -> str: return "open_graph_description_path:{}".format(make_safe_digest(request.META["PATH_INFO"]))
def patched_user_avatar_path(user_profile: UserProfile) -> Text: email = user_profile.email user_key = email.lower() + settings.AVATAR_SALT return make_safe_digest(user_key, hashlib.sha1)
def open_graph_description_cache_key(content: Any, request: HttpRequest) -> str: return 'open_graph_description_path:{}'.format( make_safe_digest(request.META['PATH_INFO']))
def open_graph_description_cache_key(content: Any, request: HttpRequest) -> str: return 'open_graph_description_path:%s' % (make_safe_digest(request.META['PATH_INFO']))
def get_stream_cache_key(stream_name: str, realm_id: int) -> str: return "stream_by_realm_and_name:%s:%s" % ( realm_id, make_safe_digest(stream_name.strip().lower()))
def bot_profile_cache_key(email: str) -> str: return "bot_profile:%s" % (make_safe_digest(email.strip()))
def get_stream_cache_key(stream_name, realm_id): # type: (Text, int) -> Text return u"stream_by_realm_and_name:%s:%s" % ( realm_id, make_safe_digest(stream_name.strip().lower()))
def user_profile_cache_key_id(email, realm_id): # type: (Text, int) -> Text return u"user_profile:%s:%s" % ( make_safe_digest(email.strip()), realm_id, )
def bot_profile_cache_key(email): # type: (Text) -> Text return u"bot_profile:%s" % (make_safe_digest(email.strip()))
def get_client_cache_key(name): return 'get_client:%s' % (make_safe_digest(name), )
def get_huddle_hash(id_list): id_list = sorted(set(id_list)) hash_key = ",".join(str(x) for x in id_list) return make_safe_digest(hash_key)
def user_profile_by_email_cache_key(email): # type: (text_type) -> text_type # See the comment in zerver/lib/avatar_hash.py:gravatar_hash for why we # are proactively encoding email addresses even though they will # with high likelihood be ASCII-only for the foreseeable future. return u'user_profile_by_email:%s' % (make_safe_digest(email.strip()), )
def preview_url_cache_key(url: str) -> str: return "preview_url:%s" % (make_safe_digest(url))
def user_profile_by_email_cache_key(email): # type: (Text) -> Text # See the comment in zerver/lib/avatar_hash.py:gravatar_hash for why we # are proactively encoding email addresses even though they will # with high likelihood be ASCII-only for the foreseeable future. return u'user_profile_by_email:%s' % (make_safe_digest(email.strip()),)
def user_profile_cache_key_id(email: str, realm_id: int) -> str: return u"user_profile:%s:%s" % (make_safe_digest(email.strip()), realm_id,)
def get_client_cache_key(name): return 'get_client:%s' % (make_safe_digest(name),)
def user_profile_cache_key_id(email, realm_id): # type: (Text, int) -> Text return u"user_profile:%s:%s" % (make_safe_digest(email.strip()), realm_id,)