bottlepy / bottle-sqlite Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Currently, the foreign key enforcement in SQLite is disabled by default, would it be possible to add an option that enable it automatically?
$ sqlite3
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> pragma foreign_keys;
0
This plugin was created just as an example, so it does not have tests.
People are using it, it is time to make it stable.
I didn't read everything, but it has at least one reference to bottle-extras
repository.
I am using bottle v0.12.8 with bottle-sqlite and whenever I start the server I get a warrning:
/usr/local/lib/python2.7/dist-packages/bottle.py:527: DeprecationWarning: Switch to Plugin API v2 and access the Route object directly.
context = self if api > 1 else self._context
Hello,
I have a problem with this version of bottle-sqlite.
Here is the log :
> ./jereve.py
Bottle v0.13-dev server starting up (using WSGIRefServer())...
Listening on http://192.168.1.142:8080/
Hit Ctrl-C to quit.
Traceback (most recent call last):
File "/srv/http/jereve/bottle.py", line 850, in _handle
return route.call(**args)
File "/srv/http/jereve/bottle.py", line 194, in __get__
value = obj.__dict__[self.func.__name__] = self.func(obj)
File "/srv/http/jereve/bottle.py", line 491, in call
return self._make_callback()
File "/srv/http/jereve/bottle.py", line 518, in _make_callback
callback = plugin.apply(callback, self)
File "/srv/http/jereve/bottle_sqlite.py", line 66, in apply
conf = context['config'].get('sqlite') or {}
TypeError: 'Route' object is not subscriptable
192.168.1.41 - - [26/Mar/2014 22:23:49] "GET / HTTP/1.1" 500 1618
The test script (bottle-sqlite as single bottle-sqlite.py file in the same folder) :
> cat jereve.py
#!/usr/bin/python3
import os
import sys
# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))
# Add the current directory to the sys.path to be able to import bottle etc...
sys.path.append(os.path.dirname(__file__))
# using "bottle" web framework
from bottle import get, install, template, run
import bottle_sqlite
plugin = bottle_sqlite.Plugin(dbfile='user_list.db')
install(plugin)
@get('/')
def index():
return template('index', texts='text');
run(host='192.168.1.142', port=8080, debug=True, reloader=True)
bottle version : last from git
bottle-sqlite version : last from git, just modified to work with python 3 (here is the modified version (lines 89, 92 and 94) : https://github.com/Mageti/bottle-sqlite/blob/master/bottle_sqlite.py)
python version : 3.2.3
OS : Debian 7 i686
Hi, could you please upload the latest version of sources to PyPI (https://pypi.python.org/pypi/bottle-sqlite)?
It would be also great, if you could create the release here on GitHub.
If you implement a decorator like:
@app.route('/secret/:item')
@valid_user()
def secret(item, db):
...
The valid_user()
plugin will throw an error like
Traceback (most recent call last):
File "/home/oznt/Software/bottlesession/bottle.py", line 998, in _handle
out = route.call(**args)
File "/home/oznt/Software/bottlesession/bottle.py", line 1999, in wrapper
rv = callback(*a, **ka)
File "/home/oznt/Software/bottlesession/bottlesession.py", line 48, in check_auth
return handler(*a, **ka)
TypeError: secret() missing 1 required positional argument: 'db'
Which hides the fact that the check for the keyword db
is failing, although, the callable does have
the keyword db
.
The reason the check fails, is because _callback is no longer the original function. this is solved in python3.3 with
inspect.signature(callable, *, follow_wrapped=True)
In earlier versions of python you would have to use functools.wraps
your original function and check if the callback has the attribute __wrapped__
. This will only work for 1 level, if you do :
@app.route('/secret/:item')
@valid_user()
@has_permission()
def secret(item,db):
...
you would have to check for callback.__wrapped__.__wrapped__
, or for each level of decoration add one __wrapped__
.
The solution is to replace the check from:
argspec = inspect.getargspec(_callback)
To
params = inspect.signature(_callback).parameters
if keyword not in params:
return callback
For some time, the sqlite module for Python3 has supported retrieving datetime fields from sqlite as datetime.datetime
python objects.
If I do a call via a function direct to the database using the native sqlite module I am returned datetime.datetime
objects.
If I do a call to the same function as part of a bottle view via bottle-sqlite, I'm returned strings in the format %Y-%m-%d %H:%M:%S
.
It would be ideal if this module returned python datetime()
rather than str()
. This issue means that I currently have to have two near-identical functions - one that handles the string type and the other that handles the correct type.
Hi guys!
Thank you very much for creating and sharing this project. I'm really excited about the possibilities.
I got the basics working, however I ran into a problem trying to connect to an sqlite3 database. I suspect my problem revolves around improper scope, naming, or something like that.
By the way, I really appreciate that you guys wrote the basic tutorial leaving out stuff like app.@route
, etc. and introduce that later on. Personally I find the OO stuff just confusing, and unnecessarily complex for a small project.
Anyway, when trying to implement the sqlite plugin, the examples given all revolve around OO type naming. I tried to convert it, even looked at different examples, including the source, but I still could not get it to work. I keep getting variations of the error in the title.
I first tried this way (minimal example):
# app.py
from bottle import install, request, route, run, static_file, template
from bottle_sqlite import SQLitePlugin
install(SQLitePlugin(dbfile='database.sqlite3'))
Then I try this way:
# app.py
from bottle import install, request, route, run, static_file, template
from bottle.ext import sqlite
install(sqlite.Plugin(dbfile='database.sqlite3'))
But when I launch my app.py
I just keep getting variation of:
from: too many arguments
from: too many arguments
./app.py: line 4: syntax error near unexpected token `SQLitePlugin'
./app.py: line 4: `install(SQLitePlugin(dbfile='database.sqlite3'))'
The homepage link on PyPi currently leads to a 404 (http://bottlepy.org/docs/dev/plugins/sqlite.html)
I like the concept of this plugin, but I found I had to roll my own because I needed a way to get a database connection object (with all of the same settings) in function that do not originate as the route. For example, I had something along the lines of
@route('/special')
def special():
do_something_special()
return main()
@route('/')
def main(db):
content = do_main_stuff_with_db()
return content
That is just one example. Another one would be if there is something with the DB in the background (say, in a thread that checks the DB occasionally)
Just thought I would suggest this.
Thanks!
Make travis run this repository and the badge to readme file.
In bottle_sqlite.py, apply() makes use of the route context. It appears (http://bottlepy.org/docs/dev/plugindev.html#route-context) that config, callback, etc. are all attributes - it's not a dictionary as it seems it's being used in apply(). Indeed, If I change, e.g.,
conf = context.['config'].get('sqlite') or {}
to
conf = context.config.get('sqlite') or {}
then it "works". As written, I get: "TypeError: 'Route' object has no attribute 'getitem'"
Perhaps this was an older handling of the route context? I'd be happy to make the code alterations in a pull request, if that would be helpful, but I thought I'd raise the issue, first, in case backward-compatibility was an issue. We could check the type and decide from there. Or we could ask bottle to support this backwards.
Thoughts?
the difference is in python2 support
btw, there is a third, quite different version bundled with bottle see bottlepy/bottle#969
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.