import bottle_session from bottle.ext import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() engine = create_engine('sqlite:///database.db', echo=True) app = Bottle() plugin = sqlalchemy.Plugin( engine, Base.metadata, keyword='db', create=True, commit=True, use_kwargs=False ) plugin_session = bottle_session.SessionPlugin(cookie_lifetime=120) app.install(plugin_session) app.install(plugin) from app.controllers import default from app.models import tables
import os import bottle import bottle_session try: import urlparse except: from urllib import parse as urlparse import random import redis import string app = bottle.app() session_plugin = bottle_session.SessionPlugin(cookie_lifetime=bottle_session.MAX_TTL) #redis_url = os.environ.get('REDIS_URL','http://:foobared@localhost:6379') #parsed_url = urlparse.urlparse(redis_url) #connection_pool = redis.ConnectionPool(host=parsed_url.hostname, port=parsed_url.port, password=parsed_url.password) #session_plugin.connection_pool = connection_pool app.install(session_plugin) @bottle.route('/') def get_main_page(session): csrf = ''.join(random.choice(string.ascii_uppercase+string.ascii_lowercase+string.digits) for x in range(32)) session['csrf'] = csrf if session.get('name') is None:
from sqlalchemy.orm import sessionmaker from bottlereact import BottleReact from bottle.ext import beaker Base = declarative_base() engine = create_engine( 'postgresql+psycopg2://stefan:test@localhost:5432/mindmapper_development', echo=True) db_plugin = sqlalchemy.Plugin( engine, # SQLAlchemy engine created with create_engine function. Base.metadata, # SQLAlchemy metadata, required only if create=True. keyword= 'db', # Keyword used to inject session database in a route (default 'db'). create= True, # If it is true, execute `metadata.create_all(engine)` when plugin is applied (default False). commit= True, # If it is true, plugin commit changes after route is executed (default True). use_kwargs= False # If it is true and keyword is not defined, plugin uses **kwargs argument to inject session database (default False). ) Session = sessionmaker(bind=engine) app = application = bottle.Bottle() app.install(db_plugin) app.install(bottle_session.SessionPlugin( cookie_lifetime=31540000)) # 1 year in seconds br = BottleReact(app, prod=False)
conn.commit() return {'success': True} else: return {'success': False, 'error': 'Wrong authentication'} if __name__ == '__main__': try: GPIO.setmode(GPIO.BCM) GPIO.setup(int(config.get('opener_pin')), GPIO.OUT) p = Process(target=opener) p.start() web_server = bottle.app() web_server.install(bottle_session.SessionPlugin(cookie_lifetime=600)) if config.get('debug'): bottle.debug() bottle.run(app=web_server, host=config.get('local_host'), port=config.get('local_port', 80), reloader=True) else: bottle.run(server='paste', app=web_server, host=config.get('local_host'), port=config.get('local_port', 80)) finally: GPIO.output(int(config.get('opener_pin')), GPIO.LOW) GPIO.cleanup()
import bottle from bottle import route, SimpleTemplate, run, template, request, response, error, static_file import mysql.connector import db import bottle_session import threading, time import re #session app = bottle.app() plugin = bottle_session.SessionPlugin(cookie_lifetime=600) app.install(plugin) @route('/css/<name>') def server_static(name): return static_file(name, root='/var/bottle/css') @route('/favicon.ico') def favicon(): pass @route('/') def index(): return template('/var/bottle/template/index') @route('/user', method='get') def index(session):
import bottle_session from bottle import run, post, request, response, get, route, static_file, SimpleTemplate, redirect, app from bottle.ext import sqlite import json, os, time, sqlite3 import subprocess32 as subprocess # install session plugin app().install(bottle_session.SessionPlugin(cookie_lifetime=600)) conn = sqlite3.connect('submissions.db') c = conn.cursor() c.execute( 'CREATE TABLE IF NOT EXISTS submits (name text, suite text, filename text, result text)' ) c.execute( 'CREATE TABLE IF NOT EXISTS failure_message (submit_id integer, message text)' ) c.execute( 'CREATE TABLE IF NOT EXISTS sub_stats (submit_id integer, method text, path_edges_found integer, path_edges_missed integer, path_edges_extra integer, path_edges_dupes integer, leaks_found integer, leaks_missed integer, leaks_extra integer)' ) conn.commit() conn.close() with open('demo.tpl') as f: tpl = SimpleTemplate(f.read()) with open('submits.tpl') as f: submits_tpl = SimpleTemplate(f.read()) with open('submit.tpl') as f: submit_tpl = SimpleTemplate(f.read())
# Runs the Apache web server # Listens for connections on a port & IP address # MODULES from bottle import route, run, template, static_file, request, get, post import bottle import bottle_session import MySQLdb import re import hashlib import uuid # PLUGINS app = bottle.app() plugin = bottle_session.SessionPlugin(cookie_lifetime=600, host='0.0.0.0', port=8080, keyword='session') app.install(plugin) # METHODS # Create a normalized, searchable index def generate_search_index(text): search_index = [] for word in text.upper().split( ' '): # Capitalize all words and split on spaces word = indexRegex.sub( '', word ) # Remove all characters not specified in indexRegex (any non-alphabetical characters) if len(word) > 2: # Do not index any words with less than 3 characters if word not in search_index: # Do not index duplicate words
app = Bottle() app.config.load_config('settings.conf') # print('Inicializando da conexão com mongo') # mongo = Database().connect() print('Inicialização, SQLAlchemy com a função create_engine') engine = create_engine('sqlite:///database.db', echo=True) print('Configutando template de aplicação') # TEMPLATE_PATH.insert(0, 'templates') views = functools.partial(jinja2_view, template_lookup=['templates']) print('Inicializando plugin Bottle Session') # plugin_session = bottle_session.SessionPlugin(cookie_lifetime=120, host='localhost', password='******') plugin_session = bottle_session.SessionPlugin(cookie_lifetime=120, host='192.168.99.100', password='******') app.install(plugin_session) print('Inicializando serviço de mensagem flash') app.install(message_plugin) print('Inicializando plugin SQLAlchemy') plugin_sqlalchemy = sqlalchemy.Plugin( engine, Base.metadata, keyword='db', create=True, commit=True, use_kwargs=False ) app.install(plugin_sqlalchemy)
def run_server(): # setup the plugins plugin = bottle_session.SessionPlugin(cookie_lifetime=None) install(plugin) run(host="localhost", port=9000, debug=True)
from r_contractors import r_contractors from r_devis import r_devis from r_docs import r_docs from utils import * def read_config(confname): with open(confname) as json_data_file: data = json.load(json_data_file) return (data) app = bottle.app() bottle.request.MEMFILE_MAX = 32 * 1024 * 1024 plugin = bottle_session.SessionPlugin(cookie_lifetime=3600 * 24 * 7) app.install(plugin) config = read_config("config.json") print config my, cursor = db.connect(config['mysql']['host'], config['mysql']['user'], config['mysql']['pass'], config['mysql']['db']) r_api(app, config, db, my, cursor) r_login(app, config, db, my, cursor) r_deal(app, config, db, my, cursor) r_contractors(app, config, db, my, cursor) r_devis(app, config, db, my, cursor) r_docs(app, config, db, my, cursor) @app.route('/', name='index')