diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-02-08 20:57:56 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-02-08 20:57:56 +0000 |
| commit | d06e33a54d93c35584c348b286b6fea4ffdd3868 (patch) | |
| tree | 0cfb5088ec0d9c12df3afce8b85c5c48730e961f /django/utils | |
| parent | 40e0a964ea0eab8353a338d5527988f09a0d6e51 (diff) | |
gis: Merged revisions 7044-7102 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7103 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/datastructures.py | 9 | ||||
| -rw-r--r-- | django/utils/encoding.py | 2 | ||||
| -rw-r--r-- | django/utils/feedgenerator.py | 2 | ||||
| -rw-r--r-- | django/utils/html.py | 23 | ||||
| -rw-r--r-- | django/utils/translation/trans_real.py | 21 |
5 files changed, 34 insertions, 23 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 25e9421575..82d914000f 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -2,6 +2,9 @@ class MergeDict(object): """ A simple class for creating new "virtual" dictionaries that actually look up values in more than one dictionary, passed in the constructor. + + If a key appears in more than one of the passed in dictionaries, only the + first occurrence will be used. """ def __init__(self, *dicts): self.dicts = dicts @@ -25,11 +28,9 @@ class MergeDict(object): def getlist(self, key): for dict_ in self.dicts: - try: + if key in dict_.keys(): return dict_.getlist(key) - except KeyError: - pass - raise KeyError + return [] def items(self): item_list = [] diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 2ab0db7432..33bb37b0ea 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -98,5 +98,5 @@ def iri_to_uri(iri): # section 3.1 of RFC 3987. if iri is None: return iri - return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?') + return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*') diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index 3e0826c968..23400bb8e7 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -53,7 +53,7 @@ class SyndicationFeed(object): 'title': to_unicode(title), 'link': iri_to_uri(link), 'description': to_unicode(description), - 'language': force_unicode(language), + 'language': to_unicode(language), 'author_email': to_unicode(author_email), 'author_name': to_unicode(author_name), 'author_link': iri_to_uri(author_link), diff --git a/django/utils/html.py b/django/utils/html.py index 33e2ee3856..17ff78a2b5 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -102,18 +102,23 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): if middle.startswith('www.') or ('@' not in middle and not middle.startswith('http://') and \ len(middle) > 0 and middle[0] in string.ascii_letters + string.digits and \ (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))): - middle = '<a href="http://%s"%s>%s</a>' % ( - urlquote(middle, safe='/&=:;#?+'), nofollow_attr, - trim_url(middle)) + middle = 'http://%s' % middle if middle.startswith('http://') or middle.startswith('https://'): - middle = '<a href="%s"%s>%s</a>' % ( - urlquote(middle, safe='/&=:;#?+'), nofollow_attr, - trim_url(middle)) - if '@' in middle and not middle.startswith('www.') and \ - not ':' in middle and simple_email_re.match(middle): + url = urlquote(middle, safe='/&=:;#?+*') + if autoescape and not safe_input: + url = escape(url) + trimmed_url = trim_url(middle) + middle = '<a href="%s"%s>%s</a>' % (url, nofollow_attr, + trimmed_url) + elif '@' in middle and not middle.startswith('www.') and \ + not ':' in middle and simple_email_re.match(middle): + if autoescape: + middle = conditional_escape(middle) middle = '<a href="mailto:%s">%s</a>' % (middle, middle) if lead + middle + trail != word: - words[i] = lead + middle + trail + if autoescape and not safe_input: + lead, trail = escape(lead), escape(trail) + words[i] = mark_safe('%s%s%s' % (lead, middle, trail)) elif autoescape and not safe_input: words[i] = escape(word) elif safe_input: diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index a7259b3ce5..f8a39710b4 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -42,7 +42,10 @@ accept_language_re = re.compile(r''' ''', re.VERBOSE) def to_locale(language, to_lower=False): - "Turns a language name (en-us) into a locale name (en_US)." + """ + Turns a language name (en-us) into a locale name (en_US). If 'to_lower' is + True, the last component is lower-cased (en_us). + """ p = language.find('-') if p >= 0: if to_lower: @@ -357,19 +360,20 @@ def get_language_from_request(request): return lang_code accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '') - for lang, unused in parse_accept_lang_header(accept): - if lang == '*': + for accept_lang, unused in parse_accept_lang_header(accept): + if accept_lang == '*': break # We have a very restricted form for our language files (no encoding # specifier, since they all must be UTF-8 and only one possible # language each time. So we avoid the overhead of gettext.find() and - # look up the MO file manually. + # work out the MO file manually. - normalized = locale.locale_alias.get(to_locale(lang, True)) + # 'normalized' is the root name of the locale in POSIX format (which is + # the format used for the directories holding the MO files). + normalized = locale.locale_alias.get(to_locale(accept_lang, True)) if not normalized: continue - # Remove the default encoding from locale_alias normalized = normalized.split('.')[0] @@ -378,10 +382,11 @@ def get_language_from_request(request): # need to check again. return _accepted[normalized] - for lang in (normalized, normalized.split('_')[0]): + for lang, dirname in ((accept_lang, normalized), + (accept_lang.split('-')[0], normalized.split('_')[0])): if lang not in supported: continue - langfile = os.path.join(globalpath, lang, 'LC_MESSAGES', + langfile = os.path.join(globalpath, dirname, 'LC_MESSAGES', 'django.mo') if os.path.exists(langfile): _accepted[normalized] = lang |
