Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (5 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis

    • Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
  • django/branches/gis/django/core/cache/backends/base.py

    r6815 r8215  
    6464        return self.get(key) is not None 
    6565 
    66     __contains__ = has_key 
     66    def __contains__(self, key): 
     67        """ 
     68        Returns True if the key is in the cache and has not expired. 
     69        """ 
     70        # This is a separate method, rather than just a copy of has_key(), 
     71        # so that it always has the same functionality as has_key(), even 
     72        # if a subclass overrides it. 
     73        return self.has_key(key) 
  • django/branches/gis/django/core/cache/backends/filebased.py

    r6920 r8215  
    11"File-based cache backend" 
    22 
    3 import md5 
    4 import os, time 
     3import os 
     4import time 
    55try: 
    66    import cPickle as pickle 
    77except ImportError: 
    88    import pickle 
     9 
    910from django.core.cache.backends.base import BaseCache 
     11from django.utils.hashcompat import md5_constructor 
    1012 
    1113class CacheClass(BaseCache): 
    1214    def __init__(self, dir, params): 
    1315        BaseCache.__init__(self, params) 
    14          
     16 
    1517        max_entries = params.get('max_entries', 300) 
    1618        try: 
     
    1820        except (ValueError, TypeError): 
    1921            self._max_entries = 300 
    20              
     22 
    2123        cull_frequency = params.get('cull_frequency', 3) 
    2224        try: 
     
    2426        except (ValueError, TypeError): 
    2527            self._cull_frequency = 3 
    26              
     28 
    2729        self._dir = dir 
    2830        if not os.path.exists(self._dir): 
     
    3234        if self.has_key(key): 
    3335            return None 
    34          
     36 
    3537        self.set(key, value, timeout) 
    3638 
     
    5355        fname = self._key_to_file(key) 
    5456        dirname = os.path.dirname(fname) 
    55          
     57 
    5658        if timeout is None: 
    5759            timeout = self.default_timeout 
    58              
     60 
    5961        self._cull() 
    60          
     62 
    6163        try: 
    6264            if not os.path.exists(dirname): 
     
    104106        if int(self._num_entries) < self._max_entries: 
    105107            return 
    106          
     108 
    107109        try: 
    108110            filelist = os.listdir(self._dir) 
    109111        except (IOError, OSError): 
    110112            return 
    111          
     113 
    112114        if self._cull_frequency == 0: 
    113115            doomed = filelist 
     
    134136        bits of the path into directory prefixes to be nice to filesystems 
    135137        that have problems with large numbers of files in a directory. 
    136          
     138 
    137139        Thus, a cache key of "foo" gets turnned into a file named 
    138140        ``{cache-dir}ac/bd/18db4cc2f85cedef654fccc4a4d8``. 
    139141        """ 
    140         path = md5.new(key.encode('utf-8')).hexdigest() 
     142        path = md5_constructor(key.encode('utf-8')).hexdigest() 
    141143        path = os.path.join(path[:2], path[2:4], path[4:]) 
    142144        return os.path.join(self._dir, path) 
     
    148150        return count 
    149151    _num_entries = property(_get_num_entries) 
    150  
  • django/branches/gis/django/core/cache/backends/locmem.py

    r6920 r8215  
    108108            doomed = [k for (i, k) in enumerate(self._cache) if i % self._cull_frequency == 0] 
    109109            for k in doomed: 
    110                 self.delete(k) 
     110                self._delete(k) 
    111111 
    112112    def _delete(self, key): 
  • django/branches/gis/django/core/cache/__init__.py

    r6920 r8215  
    2020from django.core.cache.backends.base import InvalidCacheBackendError 
    2121 
     22# Name for use in settings file --> name of module in "backends" directory. 
     23# Any backend scheme that is not in this dictionary is treated as a Python 
     24# import path to a custom backend. 
    2225BACKENDS = { 
    23     # name for use in settings file --> name of module in "backends" directory 
    2426    'memcached': 'memcached', 
    2527    'locmem': 'locmem', 
     
    2729    'db': 'db', 
    2830    'dummy': 'dummy', 
    29 } 
    30  
    31 DEPRECATED_BACKENDS = { 
    32     # deprecated backend --> replacement module 
    33     'simple': 'locmem', 
    3431} 
    3532 
     
    4037    if not rest.startswith('//'): 
    4138        raise InvalidCacheBackendError, "Backend URI must start with scheme://" 
    42     if scheme in DEPRECATED_BACKENDS: 
    43         import warnings 
    44         warnings.warn("'%s' backend is deprecated. Use '%s' instead." %  
    45             (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning) 
    46         scheme = DEPRECATED_BACKENDS[scheme] 
    47     if scheme not in BACKENDS: 
    48         raise InvalidCacheBackendError, "%r is not a valid cache backend" % scheme 
    4939 
    5040    host = rest[2:] 
     
    5848        host = host[:-1] 
    5949 
    60     cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass') 
    61     return cache_class(host, params) 
     50    if scheme in BACKENDS: 
     51        module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']) 
     52    else: 
     53        module = __import__(scheme, {}, {}, ['']) 
     54    return getattr(module, 'CacheClass')(host, params) 
    6255 
    6356cache = get_cache(settings.CACHE_BACKEND)