#
# Copyright (C) 2014 Shang Yuanchun <idealities@gmail.com>
#

import hashlib
import requests

GRAVATAR_PREFIX      = 'http://www.gravatar.com/avatar/'
DEFAULT_GRAVATAR_URL = GRAVATAR_PREFIX + '00000000000000000000000000000000?d=mm&s=200'

def make_default_avatar(email):
    """
    """

    digest = hashlib.md5(
                 email.strip().lower()).hexdigest()
    gravatar = GRAVATAR_PREFIX + digest + '?s=200'
    response = requests.head(gravatar)

    return gravatar if response.status_code == 200 else DEFAULT_GRAVATAR_URL


@@ -87,16 +87,31 @@
 requests
+%0Aimport logging
 %0A%0AGRAVAT
@@ -249,16 +249,51 @@
 s=200'%0A%0A
+log = logging.getLogger(__name__)%0A%0A
 def make
@@ -462,16 +462,49 @@
 ?s=200'%0A
+    try:%0A        # for 400ms%0A    
     resp
@@ -532,17 +532,135 @@
 gravatar
-)
+, timeout=0.4)%0A    except:%0A        log.info('http request error, url:%25s', gravatar)%0A        return DEFAULT_GRAVATAR_URL
 %0A%0A    re

add a timeout when request gravatar url