summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/datastructures.py16
-rw-r--r--django/utils/dateformat.py13
-rw-r--r--django/utils/encoding.py2
-rw-r--r--django/utils/feedgenerator.py1
-rw-r--r--django/utils/functional.py7
-rw-r--r--django/utils/translation/trans_real.py2
6 files changed, 27 insertions, 14 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index d96e45b9c8..ac890d5da6 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -238,22 +238,20 @@ class DotExpandedDict(dict):
may contain dots to specify inner dictionaries. It's confusing, but this
example should make sense.
- >>> d = DotExpandedDict({'person.1.firstname': ['Simon'],
- 'person.1.lastname': ['Willison'],
- 'person.2.firstname': ['Adrian'],
+ >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], \
+ 'person.1.lastname': ['Willison'], \
+ 'person.2.firstname': ['Adrian'], \
'person.2.lastname': ['Holovaty']})
>>> d
- {'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']},
- '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
+ {'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
>>> d['person']
- {'1': {'firstname': ['Simon'], 'lastname': ['Willison'],
- '2': {'firstname': ['Adrian'], 'lastname': ['Holovaty']}
+ {'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}
>>> d['person']['1']
- {'firstname': ['Simon'], 'lastname': ['Willison']}
+ {'lastname': ['Willison'], 'firstname': ['Simon']}
# Gotcha: Results are unpredictable if the dots are "uneven":
>>> DotExpandedDict({'c.1': 2, 'c.2': 3, 'c': 1})
- >>> {'c': 1}
+ {'c': 1}
"""
def __init__(self, key_to_list_mapping):
for k, v in key_to_list_mapping.items():
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index d5f3499d82..0e6541c721 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -248,10 +248,15 @@ class DateFormat(TimeFormat):
return doy
def Z(self):
- """Time zone offset in seconds (i.e. '-43200' to '43200'). The offset
- for timezones west of UTC is always negative, and for those east of UTC
- is always positive."""
- return self.timezone.utcoffset(self.data).seconds
+ """
+ Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for
+ timezones west of UTC is always negative, and for those east of UTC is
+ always positive.
+ """
+ offset = self.timezone.utcoffset(self.data)
+ # Only days can be negative, so negative offsets have days=-1 and
+ # seconds positive. Positive offsets have days=0
+ return offset.days * 86400 + offset.seconds
def format(value, format_string):
"Convenience function"
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 2319496538..69c3e9c28b 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -30,7 +30,7 @@ def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
If strings_only is True, don't convert (some) non-string-like objects.
"""
- if strings_only and isinstance(s, (types.NoneType, int)):
+ if strings_only and isinstance(s, (types.NoneType, int, long)):
return s
if not isinstance(s, basestring,):
if hasattr(s, '__unicode__'):
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index 44c96af147..e296331324 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -3,6 +3,7 @@ Syndication feed generation library -- used for generating RSS, etc.
Sample usage:
+>>> from django.utils import feedgenerator
>>> feed = feedgenerator.Rss201rev2Feed(
... title=u"Poynter E-Media Tidbits",
... link=u"http://www.poynter.org/column.asp?id=31",
diff --git a/django/utils/functional.py b/django/utils/functional.py
index 734704f6f3..f4580e7bd5 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -101,6 +101,13 @@ def lazy(func, *resultclasses):
else:
raise AssertionError('__mod__ not supported for non-string types')
+ def __deepcopy__(self, memo):
+ # Instances of this class are effectively immutable. It's just a
+ # collection of functions. So we don't need to do anything
+ # complicated for copying.
+ memo[id(self)] = self
+ return self
+
def __wrapper__(*args, **kw):
# Creates the proxy object, instead of the actual value.
return __proxy__(args, kw)
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 765152afce..5fff1ea63a 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -491,6 +491,8 @@ def templatize(src):
elif g[0] == "'": g = g.strip("'")
out.write(' gettext(%r) ' % g)
elif bmatch:
+ for fmatch in constant_re.findall(t.contents):
+ out.write(' _(%s) ' % fmatch)
intrans = True
inplural = False
singular = []