<s> from __future__ import absolute_import <EOL> from django . conf import settings <EOL> import hashlib <EOL> from zerver . lib . utils import make_safe_digest <EOL> def gravatar_hash ( email ) : <EOL> """<STR_LIT>""" <EOL> return make_safe_digest ( email . lower ( ) , hashlib . md5 ) <EOL> def user_avatar_hash ( email ) : <EOL> user_key = email . lower ( ) + settings . AVATAR_SALT <EOL> return make_safe_digest ( user_key , hashlib . sha1 ) <EOL> def avatar_url ( user_profile ) : <EOL> return get_avatar_url ( <EOL> user_profile . avatar_source , <EOL> user_profile . email <EOL> ) <EOL> def get_avatar_url ( avatar_source , email ) : <EOL> if avatar_source == '<STR_LIT>' : <EOL> hash_key = user_avatar_hash ( email ) <EOL> if settings . LOCAL_UPLOADS_DIR is not None : <EOL> return "<STR_LIT>" % ( hash_key ) <EOL> else : <EOL> bucket = settings . S3_AVATAR_BUCKET <EOL> return "<STR_LIT>" % ( bucket , hash_key ) <EOL> elif settings . ENABLE_GRAVATAR : <EOL> hash_key = gravatar_hash ( email ) <EOL> return "<STR_LIT>" % ( hash_key , ) <EOL> else : <EOL> return settings . DEFAULT_AVATAR_URI + '<STR_LIT>' </s>
