<s> from __future__ import absolute_import , unicode_literals <EOL> import hashlib <EOL> from django import template <EOL> from django . utils . six . moves . urllib . parse import urlencode <EOL> register = template . Library ( ) <EOL> class GravatarUrlNode ( template . Node ) : <EOL> def __init__ ( self , email , size = <NUM_LIT:50> ) : <EOL> self . email = template . Variable ( email ) <EOL> self . size = size <EOL> def render ( self , context ) : <EOL> try : <EOL> email = self . email . resolve ( context ) <EOL> except template . VariableDoesNotExist : <EOL> return '<STR_LIT>' <EOL> default = "<STR_LIT:blank>" <EOL> size = int ( self . size ) * <NUM_LIT:2> <EOL> gravatar_url = "<STR_LIT>" . format ( <EOL> hash = hashlib . md5 ( email . lower ( ) . encode ( '<STR_LIT:utf-8>' ) ) . hexdigest ( ) , <EOL> params = urlencode ( { '<STR_LIT:s>' : size , '<STR_LIT:d>' : default } ) <EOL> ) <EOL> return gravatar_url <EOL> @ register . tag <EOL> def gravatar_url ( parser , token ) : <EOL> bits = token . split_contents ( ) <EOL> return GravatarUrlNode ( * bits [ <NUM_LIT:1> : ] ) </s>
