def get_avatar_image(request, user, size):
 cache_key = u'-'.join((u'avatar-img', user.username, str(size)))
 try:
  cache = caches[u'avatar']
 except InvalidCacheBackendError:
  cache = caches[u'default']
 image = cache.get(cache_key)
 if (image is None):
  try:
   image = download_avatar_image(user, size)
   cache.set(cache_key, image)
  except IOError as error:
   report_error(error, sys.exc_info(), request, extra_data={u'avatar': user.username}, level=u'debug')
   LOGGER.error(u'Failed to fetch avatar for %s: %s', user.username, str(error))
   return get_fallback_avatar(size)
 return image

def get_avatar_image ( request , user , size ) : cache_key = u'-' . join ( ( u'avatar-img' , user . username , str ( size ) ) ) try : cache = caches [ u'avatar' ] except InvalidCacheBackendError : cache = caches [ u'default' ] image = cache . get ( cache_key ) if ( image is None ) : try : image = download_avatar_image ( user , size ) cache . set ( cache_key , image ) except IOError as error : report_error ( error , sys . exc_info ( ) , request , extra_data = { u'avatar' : user . username } , level = u'debug' ) LOGGER . error ( u'Failed to fetch avatar for %s: %s' , user . username , str ( error ) ) return get_fallback_avatar ( size ) return image
returns avatar image from cache or downloads it .