diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-05-12 02:36:05 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-05-12 02:36:05 +0000 |
| commit | 415e84ad53e0d0d8f7df87784c1893489bdbe0b8 (patch) | |
| tree | 09541f8319c45ec51fb44154534abc41cb86aee9 /django/utils | |
| parent | 4938c8ea6db6f23ebb0883b8a092985344508b25 (diff) | |
newforms-admin: Merged to [5194]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5195 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/cache.py | 2 | ||||
| -rw-r--r-- | django/utils/datastructures.py | 23 | ||||
| -rw-r--r-- | django/utils/feedgenerator.py | 1 | ||||
| -rw-r--r-- | django/utils/functional.py | 2 | ||||
| -rw-r--r-- | django/utils/synch.py | 15 | ||||
| -rw-r--r-- | django/utils/timesince.py | 8 | ||||
| -rw-r--r-- | django/utils/translation/trans_real.py | 2 |
7 files changed, 30 insertions, 23 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 5eba302ebe..c8031a409a 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -86,7 +86,7 @@ def patch_response_headers(response, cache_timeout=None): def add_never_cache_headers(response): """ - Add headers to a response to indicate that + Add headers to a response to indicate that a page should never be cached. """ patch_response_headers(response, cache_timeout=-1) diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 7b7fa2b0f0..60bc0051a2 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -16,9 +16,9 @@ class MergeDict(object): def __contains__(self, key): return self.has_key(key) - - def __copy__(self): - return self.__class__(*self.dicts) + + def __copy__(self): + return self.__class__(*self.dicts) def get(self, key, default=None): try: @@ -42,12 +42,12 @@ class MergeDict(object): def has_key(self, key): for dict in self.dicts: - if dict.has_key(key): + if key in dict: return True return False - - def copy(self): - """ returns a copy of this object""" + + def copy(self): + """ returns a copy of this object""" return self.__copy__() class SortedDict(dict): @@ -99,6 +99,13 @@ class SortedDict(dict): obj.keyOrder = self.keyOrder return obj + def __repr__(self): + """ + Replaces the normal dict.__repr__ with a version that returns the keys + in their sorted order. + """ + return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()]) + class MultiValueDictKeyError(KeyError): pass @@ -211,7 +218,7 @@ class MultiValueDict(dict): def update(self, *args, **kwargs): "update() extends rather than replaces existing key lists. Also accepts keyword args." if len(args) > 1: - raise TypeError, "update expected at most 1 arguments, got %d", len(args) + raise TypeError, "update expected at most 1 arguments, got %d" % len(args) if args: other_dict = args[0] if isinstance(other_dict, MultiValueDict): diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index 9397789d6a..aa315b5292 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -132,6 +132,7 @@ class RssFeed(SyndicationFeed): handler.addQuickElement(u"category", cat) if self.feed['feed_copyright'] is not None: handler.addQuickElement(u"copyright", self.feed['feed_copyright']) + handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('ascii')) self.write_items(handler) self.endChannelElement(handler) handler.endElement(u"rss") diff --git a/django/utils/functional.py b/django/utils/functional.py index e3c0a3c76b..0c31c1f375 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -42,7 +42,7 @@ def lazy(func, *resultclasses): res = self.__func(*self.__args, **self.__kw) return self.__dispatch[type(res)][funcname](res, *args, **kw) - if not self.__dispatch.has_key(klass): + if klass not in self.__dispatch: self.__dispatch[klass] = {} self.__dispatch[klass][funcname] = func return __wrapper__ diff --git a/django/utils/synch.py b/django/utils/synch.py index 6fcd81390e..2e808c1e01 100644 --- a/django/utils/synch.py +++ b/django/utils/synch.py @@ -1,6 +1,6 @@ """ Synchronization primitives: - + - reader-writer lock (preference to writers) (Contributed to Django by eugene@lazutkin.com) @@ -14,17 +14,16 @@ except ImportError: class RWLock: """ Classic implementation of reader-writer lock with preference to writers. - + Readers can access a resource simultaneously. Writers get an exclusive access. - + API is self-descriptive: reader_enters() reader_leaves() writer_enters() writer_leaves() """ - def __init__(self): self.mutex = threading.RLock() self.can_read = threading.Semaphore(0) @@ -33,7 +32,7 @@ class RWLock: self.active_writers = 0 self.waiting_readers = 0 self.waiting_writers = 0 - + def reader_enters(self): self.mutex.acquire() try: @@ -45,7 +44,7 @@ class RWLock: finally: self.mutex.release() self.can_read.acquire() - + def reader_leaves(self): self.mutex.acquire() try: @@ -56,7 +55,7 @@ class RWLock: self.can_write.release() finally: self.mutex.release() - + def writer_enters(self): self.mutex.acquire() try: @@ -68,7 +67,7 @@ class RWLock: finally: self.mutex.release() self.can_write.acquire() - + def writer_leaves(self): self.mutex.acquire() try: diff --git a/django/utils/timesince.py b/django/utils/timesince.py index e69c45c8c1..394f818395 100644 --- a/django/utils/timesince.py +++ b/django/utils/timesince.py @@ -1,6 +1,6 @@ import datetime, math, time from django.utils.tzinfo import LocalTimezone -from django.utils.translation import ngettext +from django.utils.translation import ngettext, gettext def timesince(d, now=None): """ @@ -37,14 +37,14 @@ def timesince(d, now=None): if count != 0: break if count < 0: - return '%d milliseconds' % math.floor((now - d).microseconds / 1000) - s = '%d %s' % (count, name(count)) + return gettext('%d milliseconds') % math.floor((now - d).microseconds / 1000) + s = gettext('%(number)d %(type)s') % {'number': count, 'type': name(count)} if i + 1 < len(chunks): # Now get the second item seconds2, name2 = chunks[i + 1] count2 = (since - (seconds * count)) / seconds2 if count2 != 0: - s += ', %d %s' % (count2, name2(count2)) + s += gettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)} return s def timeuntil(d, now=None): diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 0c8dcd540f..293b4ef9cd 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -199,7 +199,7 @@ def deactivate(): will resolve against the default translation object, again. """ global _active - if _active.has_key(currentThread()): + if currentThread() in _active: del _active[currentThread()] def get_language(): |
