comparison MoinMoin/support/werkzeug/contrib/cache.py @ 6010:fc1f97a47c7e

upgrade bundled werkzeug to 0.8.3
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 05 Jan 2014 03:44:28 +0100
parents 8de563c487be
children 9f12f41504fc
comparison
equal deleted inserted replaced
6009:b48a69886ca4 6010:fc1f97a47c7e
469 :param default_timeout: the default timeout that is used if no timeout is 469 :param default_timeout: the default timeout that is used if no timeout is
470 specified on :meth:`~BaseCache.set`. 470 specified on :meth:`~BaseCache.set`.
471 :param key_prefix: A prefix that should be added to all keys. 471 :param key_prefix: A prefix that should be added to all keys.
472 """ 472 """
473 473
474 def __init__(self, host='localhost', port=6379, default_timeout=300, 474 def __init__(self, host='localhost', port=6379, password=None,
475 key_prefix=None): 475 default_timeout=300, key_prefix=None):
476 BaseCache.__init__(self, default_timeout) 476 BaseCache.__init__(self, default_timeout)
477 if isinstance(host, basestring): 477 if isinstance(host, basestring):
478 try: 478 try:
479 import redis 479 import redis
480 except ImportError: 480 except ImportError:
481 raise RuntimeError('no redis module found') 481 raise RuntimeError('no redis module found')
482 self._client = redis.Redis(host=host, port=port) 482 self._client = redis.Redis(host=host, port=port, password=password)
483 else: 483 else:
484 self._client = host 484 self._client = host
485 self.key_prefix = key_prefix or '' 485 self.key_prefix = key_prefix or ''
486 486
487 def dump_object(self, value): 487 def dump_object(self, value):
488 """Dumps an object into a string for redis. By default it serializes 488 """Dumps an object into a string for redis. By default it serializes
489 integers as regular string and pickle dumps everything else. 489 integers as regular string and pickle dumps everything else.
490 """ 490 """
491 if isinstance(value, (int, long)): 491 t = type(value)
492 if t is int or t is long:
492 return str(value) 493 return str(value)
493 return '!' + pickle.dumps(value) 494 return '!' + pickle.dumps(value)
494 495
495 def load_object(self, value): 496 def load_object(self, value):
496 """The reversal of :meth:`dump_object`. This might be callde with 497 """The reversal of :meth:`dump_object`. This might be callde with