bottle-redis's People
bottle-redis's Issues
Plugin fails with decorated views ...
See discussion and solution to the bug in here: https://github.com/oz123/demo-bottle-sqlite-bug Don't let the sqlite in URL mislead you. Although, I first found this issue in SQLite plugin, the underlying reason is a wrong check for the keyword redis
, which is the same both plugins.
Travis integration
Make travis run this repository and the badge to readme file.
[email protected]
Hi,
I installed beaker_redis-1.0.0 from PyPI and container.py contains a critical error @line:36. I've already changed it for my usage as followed :
""" Beaker backend for redis.
"""
import logging
from pickle import dumps as pickle_dumps
from pickle import loads as pickle_loads
from redis import Redis
from beaker.container import NamespaceManager, Container
from beaker.util import verify_directory
log = logging.getLogger(name)
DEFAULT_TTL = 30 * 24 * 60 * 60 # 30 days
class RedisBackend(NamespaceManager):
""" Beaker backend for redis.
:param str dsn: host:port/db
(default: `localhost:6379/0`)
:param str hkey_prefix: name for redis hkey for store data
(default: `session`)
:param int ttl: ttl from last access
(default: `2592000` (30 days))
"""
def __init__(
self,
namespace,
dsn='localhost:6379/0',
data_dir=None,
lock_dir=None,
hkey_prefix='session',
ttl=DEFAULT_TTL,
**params):
NamespaceManager.__init__(self, namespace)
if lock_dir:
self.lock_dir = lock_dir
elif data_dir:
self.lock_dir = data_dir + "/container_tcd_lock"
else:
self.lock_dir = None
if self.lock_dir:
verify_directory(self.lock_dir)
host, port_db = dsn.split(':', 1)
port, db_num = (int(i) for i in port_db.split('/', 1))
self.db = Redis(host=host, port=port, db=db_num)
self.hkey = hkey = ':'.join((hkey_prefix, self.namespace))
self.ttl = int(ttl)
log.debug("session setuped: %s", hkey)
def __contains__(self, key):
return self.db.hexists(self.hkey, key)
def __getitem__(self, key):
data = self.db.hget(self.hkey, key)
if data is not None:
self.db.expire(self.hkey, self.ttl)
return pickle_loads(data)
else:
raise KeyError(key)
def __setitem__(self, key, value):
log.debug("session set key: %s %s %r", self.hkey, key, value)
self.db.hset(self.hkey, key, pickle_dumps(value))
self.db.expire(self.hkey, self.ttl)
def __delitem__(self, key):
log.debug("session del key: %s %s", self.hkey, key)
self.db.hdel(self.hkey, key)
self.db.expire(self.hkey, self.ttl)
def do_remove(self):
log.debug("session remove: %s", self.hkey)
self.db.delete(self.hkey)
def keys(self):
keys = self.db.hkeys(self.hkey)
self.db.expire(self.hkey, self.ttl)
return keys
class RedisContainer(Container):
namespace_manager = RedisBackend
Custom Decorators stopped working using apply
Using the latest version of bottle-redis available here, I'm encountering a strange case where custom decorators are not being called if the bottle-redis plugin is installed. This behaviour does not affect the version of bottle-redis available on pypi (v0.2.1), nor does it occur with using other plugins (tested with bottle-sqlite, bottle-session). Tested on Bottle v0.12.8, Python 2.7.8 on OSX 10.10.1.
Example code below. If you run the app and attempt to go to http://localhost:8888/test, the expected behaviour should be a redirection to http://localhost:8888/unauthorized, with debug output in the console showing "authorizing request". Instead, nothing is output from the decorator and you are met with an "authorized" message.
Note that the code does not use the decorator as is, but via the apply parameter on the route.get function. Again, all works fine with the previous version v0.2.1 on pypi
import bottle
import bottle_redis
import redis
import functools
app = bottle.Bottle()
redis_plugin = bottle_redis.RedisPlugin()
cp1 = redis.ConnectionPool(host='localhost', port=6379, db=1)
redis_plugin.redisdb = cp1
app.install(redis_plugin)
VALID_AUTH_ROLES = ('api','session','simple')
def authorizeRequest(authroles=None):
print "authorizing request"
if authroles not in VALID_AUTH_ROLES:
bottle.redirect('/unauthorized')
return True
def make_auth_decorator(authroles=None):
def auth_require(authroles=authroles):
def decorator(func):
@functools.wraps(func)
def wrapper(*a, **ka):
authorizeRequest(authroles=authroles)
f = func(*a, **ka)
return f
return wrapper
return decorator
return auth_require
authorize = make_auth_decorator()
@app.get('/unauthorized')
def do_fail(rdb):
return "authorization failed"
@app.get('/test', apply=[authorize(authroles='test')])
def test(rdb):
return "authorized"
app.run(host='localhost', port=8888, debug=True, reloader=True)
Tests are not included in the PyPI source distribution
decode_responses
Hi, it would be great if the plugin ctor could support decode_responses
in order to convert all byte-strings to unicode-strings automatically, which is very useful when using Python 3.x.
Maybe the ctor could be made even more flexible using *args
and **kwargs
, e.g.
def __init__(self, keyword="rdb", *args, **kwargs):
self.keyword = keyword
self.redisdb = redis.ConnectionPool(*args, **kwargs)
Fix README
I didn't read everything, but it has at least one reference to bottle-extras
repository.
pypi permission
@sc68cal add my user on pypi so I can generate future release
https://pypi.python.org/pypi/bottle-redis
Update to Bottle API v2
I am using bottle-redis with bottle 0.12.7 and i get this warning:
/Library/Python/2.7/site-packages/bottle.py:527: DeprecationWarning: Switch to Plugin API v2 and access the Route object directly.
context = self if api > 1 else self._context
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.