From 233254d63455b05dbfb9aa2ce81b83d7d1ae2586 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Thu, 19 Jan 2006 01:09:28 +0000 Subject: [PATCH] magic-removal: Merged to [2059] git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2060 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/bin/compile-messages.py | 8 ++++---- django/bin/unique-messages.py | 9 ++++----- django/utils/html.py | 7 ++++--- django/views/debug.py | 2 +- django/views/i18n.py | 11 ++++------- docs/i18n.txt | 26 +++++++++++++------------- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/django/bin/compile-messages.py b/django/bin/compile-messages.py index 7e5be279f6..c81a2caa29 100755 --- a/django/bin/compile-messages.py +++ b/django/bin/compile-messages.py @@ -16,10 +16,10 @@ def compile_messages(): sys.exit(1) for (dirpath, dirnames, filenames) in os.walk(basedir): - for file in filenames: - if file.endswith('.po'): - sys.stderr.write('processing file %s in %s\n' % (file, dirpath)) - pf = os.path.splitext(os.path.join(dirpath, file))[0] + for f in filenames: + if f.endswith('.po'): + sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) + pf = os.path.splitext(os.path.join(dirpath, f))[0] cmd = 'msgfmt -o "%s.mo" "%s.po"' % (pf, pf) os.system(cmd) diff --git a/django/bin/unique-messages.py b/django/bin/unique-messages.py index c85561ca29..e29f2b8deb 100755 --- a/django/bin/unique-messages.py +++ b/django/bin/unique-messages.py @@ -2,7 +2,6 @@ import os import sys -import getopt def unique_messages(): basedir = None @@ -16,10 +15,10 @@ def unique_messages(): sys.exit(1) for (dirpath, dirnames, filenames) in os.walk(basedir): - for file in filenames: - if file.endswith('.po'): - sys.stderr.write('processing file %s in %s\n' % (file, dirpath)) - pf = os.path.splitext(os.path.join(dirpath, file))[0] + for f in filenames: + if f.endswith('.po'): + sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) + pf = os.path.splitext(os.path.join(dirpath, f))[0] cmd = 'msguniq "%s.po"' % pf stdout = os.popen(cmd) msg = stdout.read() diff --git a/django/utils/html.py b/django/utils/html.py index 9e239cad1f..6c9779a156 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -12,13 +12,14 @@ DOTS = ['·', '*', '\xe2\x80\xa2', '•', '•', '•'] unencoded_ampersands_re = re.compile(r'&(?!(\w+|#\d+);)') word_split_re = re.compile(r'(\s+)') punctuation_re = re.compile('^(?P(?:%s)*)(?P.*?)(?P(?:%s)*)$' % \ - ('|'.join([re.escape(p) for p in LEADING_PUNCTUATION]), - '|'.join([re.escape(p) for p in TRAILING_PUNCTUATION]))) + ('|'.join([re.escape(x) for x in LEADING_PUNCTUATION]), + '|'.join([re.escape(x) for x in TRAILING_PUNCTUATION]))) simple_email_re = re.compile(r'^\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+$') link_target_attribute_re = re.compile(r'(]*?)target=[^\s>]+') html_gunk_re = re.compile(r'(?:
|<\/i>|<\/b>|<\/em>|<\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE) -hard_coded_bullets_re = re.compile(r'((?:

(?:%s).*?[a-zA-Z].*?

\s*)+)' % '|'.join([re.escape(d) for d in DOTS]), re.DOTALL) +hard_coded_bullets_re = re.compile(r'((?:

(?:%s).*?[a-zA-Z].*?

\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL) trailing_empty_content_re = re.compile(r'(?:

(?: |\s|
)*?

\s*)+\Z') +del x # Temporary variable def escape(html): "Returns the given HTML with ampersands, quotes and carets encoded" diff --git a/django/views/debug.py b/django/views/debug.py index 09ae11477a..d2e6f06b3b 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -2,7 +2,7 @@ from django.conf import settings from django.template import Template, Context, TemplateDoesNotExist from django.utils.html import escape from django.http import HttpResponseServerError, HttpResponseNotFound -import inspect, os, re, sys +import os, re from itertools import count, izip from os.path import dirname, join as pathjoin diff --git a/django/views/i18n.py b/django/views/i18n.py index f0478994ac..a2bc54c9ed 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -1,12 +1,9 @@ -import re -import os - -import gettext as gettext_module - from django import http from django.utils.translation import check_for_language, activate, to_locale, get_language from django.utils.text import javascript_quote from django.conf import settings +import os +import gettext as gettext_module def set_language(request): """ @@ -145,7 +142,7 @@ def javascript_catalog(request, domain='djangojs', packages=None): for path in paths: try: catalog = gettext_module.translation(domain, path, [default_locale]) - except IOError, e: + except IOError: catalog = None if catalog is not None: t.update(catalog._catalog) @@ -154,7 +151,7 @@ def javascript_catalog(request, domain='djangojs', packages=None): for path in paths: try: catalog = gettext_module.translation(domain, path, [locale]) - except IOError, e: + except IOError: catalog = None if catalog is not None: t.update(catalog._catalog) diff --git a/docs/i18n.txt b/docs/i18n.txt index 782f6a4ffc..9199a74295 100644 --- a/docs/i18n.txt +++ b/docs/i18n.txt @@ -447,24 +447,24 @@ Notes: en-us). .. _LANGUAGES setting: http://www.djangoproject.com/documentation/settings/#languages - * the LocaleMiddleware can only select languages for which there is a - django provided base translation. If you want to provide translations + * The ``LocaleMiddleware`` can only select languages for which there is a + Django-provided base translation. If you want to provide translations for your application that aren't already in the set of translations - in Djangos source tree, you will want to at least provide basic - translations for that language. For example Django uses technical - message IDs to translate date formats and time formats - so you will + in Django's source tree, you'll want to provide at least basic + translations for that language. For example, Django uses technical + message IDs to translate date formats and time formats -- so you will need at least those translations for the system to work correctly. - A good starting point is to just copy over the english ``.po`` file - and to translate at least the technical messages and maybe the validator + A good starting point is to copy the English ``.po`` file and to + translate at least the technical messages -- maybe the validator messages, too. - - Technical message IDs are easily recognized by them being all upper case. - You don't translate the message ID as with other messages, you provide - the correct local variant on the provided english value. For example with + + Technical message IDs are easily recognized; they're all upper case. You + don't translate the message ID as with other messages, you provide the + correct local variant on the provided English value. For example, with ``DATETIME_FORMAT`` (or ``DATE_FORMAT`` or ``TIME_FORMAT``), this would - be the format string that you want to use in your language. The format - is identical to the ``now`` tag date formattings. + be the format string that you want to use in your language. The format + is identical to the format strings used by the ``now`` template tag. Once ``LocaleMiddleware`` determines the user's preference, it makes this preference available as ``request.LANGUAGE_CODE`` for each `request object`_.