# HG changeset patch # User Marcin Kuzminski # Date 1298773103 -3600 # Node ID c1080b42a7cbf233be76602a117d9bd058d562e8 # Parent e7d7f05217c1af14dfdb4e4359cda71f6c3215cf fixed problem with int. chars in gravatars diff -r e7d7f05217c1 -r c1080b42a7cb rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py Sun Feb 27 02:43:44 2011 +0100 +++ b/rhodecode/lib/helpers.py Sun Feb 27 03:18:23 2011 +0100 @@ -6,12 +6,12 @@ import random import hashlib import StringIO +import urllib + from pygments.formatters import HtmlFormatter from pygments import highlight as code_highlight -from pylons import url +from pylons import url, request from pylons.i18n.translation import _, ungettext -from vcs.utils.annotate import annotate_highlight -from rhodecode.lib.utils import repo_name_slug from webhelpers.html import literal, HTML, escape from webhelpers.html.tools import * @@ -33,6 +33,9 @@ from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \ convert_boolean_attrs, NotGiven +from vcs.utils.annotate import annotate_highlight +from rhodecode.lib.utils import repo_name_slug + def _reset(name, value=None, id=NotGiven, type="reset", **attrs): """Reset button """ @@ -557,9 +560,6 @@ #============================================================================== # GRAVATAR URL #============================================================================== -import hashlib -import urllib -from pylons import request def gravatar_url(email_address, size=30): ssl_enabled = 'https' == request.environ.get('wsgi.url_scheme') @@ -568,7 +568,9 @@ baseurl_ssl = "https://secure.gravatar.com/avatar/" baseurl = baseurl_ssl if ssl_enabled else baseurl_nossl - + if isinstance(email_address, unicode): + #hashlib crashes on unicode items + email_address = email_address.encode('utf8', 'replace') # construct the url gravatar_url = baseurl + hashlib.md5(email_address.lower()).hexdigest() + "?" gravatar_url += urllib.urlencode({'d':default, 's':str(size)})