Example #1
0
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 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)
Example #3
0
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)
Example #5
0
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()))
Example #6
0
File: cache.py Project: anteq/zulip
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()))
Example #7
0
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()))
Example #8
0
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()))
Example #9
0
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)
Example #10
0
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)
Example #11
0
def user_profile_cache_key(email, realm):
    # type: (Text, Realm) -> Text
    return u"user_profile:%s:%s" % (make_safe_digest(email.strip()), realm.id,)
Example #12
0
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)
Example #14
0
def open_graph_description_cache_key(content: Any,
                                     request: HttpRequest) -> str:
    return 'open_graph_description_path:{}'.format(
        make_safe_digest(request.META['PATH_INFO']))
Example #15
0
def open_graph_description_cache_key(content: Any, request: HttpRequest) -> str:
    return 'open_graph_description_path:%s' % (make_safe_digest(request.META['PATH_INFO']))
Example #16
0
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()))
Example #17
0
def bot_profile_cache_key(email: str) -> str:
    return "bot_profile:%s" % (make_safe_digest(email.strip()))
Example #18
0
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()))
Example #19
0
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,
    )
Example #20
0
def bot_profile_cache_key(email):
    # type: (Text) -> Text
    return u"bot_profile:%s" % (make_safe_digest(email.strip()))
Example #21
0
def get_client_cache_key(name):
    return 'get_client:%s' % (make_safe_digest(name), )
Example #22
0
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()))
Example #23
0
def bot_profile_cache_key(email):
    # type: (Text) -> Text
    return u"bot_profile:%s" % (make_safe_digest(email.strip()))
Example #24
0
def user_profile_cache_key(email, realm):
    # type: (Text, Realm) -> Text
    return u"user_profile:%s:%s" % (make_safe_digest(email.strip()), realm.id,)
Example #25
0
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)
Example #26
0
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)
Example #27
0
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()), )
Example #28
0
def preview_url_cache_key(url: str) -> str:
    return "preview_url:%s" % (make_safe_digest(url))
Example #29
0
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()),)
Example #30
0
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,)
Example #31
0
def get_client_cache_key(name):
    return 'get_client:%s' % (make_safe_digest(name),)
Example #32
0
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,)