How to use bottle - 10 common examples

To help you get started, we’ve selected a few bottle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pakerfeldt / remotestick-server / bottle.py View on Github external
if download:
        header['Content-Disposition'] = 'attachment; filename="%s"' % download

    stats = os.stat(filename)
    lm = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(stats.st_mtime))
    header['Last-Modified'] = lm
    ims = request.environ.get('HTTP_IF_MODIFIED_SINCE')
    if ims:
        ims = ims.split(";")[0].strip() # IE sends "; length=146"
        ims = parse_date(ims)
        if ims is not None and ims >= int(stats.st_mtime):
            header['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
            return HTTPResponse(status=304, header=header)
    header['Content-Length'] = stats.st_size
    if request.method == 'HEAD':
        return HTTPResponse('', header=header)
    else:
        return HTTPResponse(open(filename, 'rb'), header=header)
github infothrill / python-dyndnsc / tests / tests.py View on Github external
def nicupdate():
    arg_hostname = request.query.hostname
    arg_myip = request.query.myip
    assert len(arg_hostname) > 0
    assert len(arg_myip) > 0
    #assert arg_hash in sample_data
    response.content_type = 'text/plain; charset=utf-8'
    return str("good %s" % arg_myip)
github sahildua2305 / expand-url / bottle / test2.py View on Github external
def expand(url = ""):
    url = request.query.get('url', '')
    if url == "":
        return {"success" : False,
            "start_url" : url,
            "final_url" : "",
            "url_list" : []
            }
    url_list = expandURL(url)
    return {"success" : True,
            "start_url" : url,
            "final_url" : url_list[-1],
            "url_list" : url_list
            }
github FedericoCeratto / bottle-cork / tests / test_functional_decorated.py View on Github external
assert 'beaker.session.id' not in self._app.cookies, "Unexpected cookie found"

        self.assert_redirect('/admin', '/sorry_page')

        self.assert_200('/user_is_anonymous', 'True')
        assert 'beaker.session.id' not in self._app.cookies, "Unexpected cookie found"

        post = {'username': 'admin', 'password': 'admin'}
        self.assert_redirect('/login', '/', post=post)
        assert 'beaker.session.id' in self._app.cookies, "Cookie not found"

        self.assert_200('/my_role', 'admin')
        assert 'beaker.session.id' in self._app.cookies, "Cookie not found"

        import bottle
        session = bottle.request.environ.get('beaker.session')
        print("Session from func. test", repr(session))

        self.assert_200('/login', 'Please insert your credentials')


        p = self._app.get('/admin')
        assert 'Welcome' in p.body, repr(p)

        p = self._app.get('/my_role', status=200)
        assert p.status == '200 OK'
        assert p.body == 'admin', "Sta"

        print("Login performed")
github citiususc / stac / api / services.py View on Github external
@route('/friedman///', method=["POST", "OPTIONS"])
@headers
@ranking
def friedman(alpha=0.05, post_hoc="bonferroni_dunn_test", control=None):
    values = clean_missing_values(request.json)
    statistic, p_value, rankings, ranking_cmp = npt.friedman_test(*values.values())
    rankings, names = map(list, zip(*sorted(zip(rankings, values.keys()), key=lambda t: t[0])))
    ranks = {key: ranking_cmp[i] for i,key in enumerate(values.keys())}
    if post_hoc.split('_')[-1] == "test":
        comparisons, z_values, _, adj_p_values = getattr(npt, post_hoc)(ranks, control)
    else:
        comparisons, z_values, _, adj_p_values = getattr(npt, post_hoc)(ranks)
    return statistic, p_value, rankings, names, comparisons, z_values, adj_p_values
github feisuzhu / thbattle / src / services / events.py View on Github external
def speaker():
    idx = {
        k.split('_')[-1]: k for k in request.cookies
        if k.startswith(options.discuz_cookiepre)
    }

    if not ('auth' in idx and 'saltkey' in idx):
        response.status = 403
        return

    auth = unquote(request.get_cookie(idx['auth']))
    saltkey = unquote(request.get_cookie(idx['saltkey']))
    uid, pwd = Account.decode_cookie(auth, saltkey)
    user = Account.find(uid)
    if not user:
        return 'false'

    if user.jiecao < 0:
        return 'false'

    message = request.forms.get('message').decode('utf-8', 'ignore')
    username = user.username.decode('utf-8', 'ignore')

    interconnect.publish('speaker', [username, message])

    return 'true'
github Jwink3101 / NBweb / NBweb / main.py View on Github external
if not item['rootbasename'].endswith('/'):
            item['rootbasename'] += '/'
        item['rootname'] = item['rootbasename'] 
        item['meta_title'] = os.path.split(parts.rootdirname)[-1]

        db.close()
        return fill_template(item,show_path=True,isdir=True)
    else:
        refresh = float( request.query.get('refresh',default=-1) )
        
        force = request.query.get('forcereload','false').lower() == 'true'
        item = parse_path(systemname,db,force=force)

        # drafts. Must be logged in as an edit_user
        if item['draft'] and not is_edit_user:
            abort(401)

        item['crossref'] = cross_ref(item,db)
        
        db.close()
        return fill_template(item,show_path=True,refresh=refresh)
github morpheus65535 / oscarr / oscarr.py View on Github external
settings_sonarr_ssl = 'False'
    else:
        settings_sonarr_ssl = 'True'
    settings_sonarr_apikey = request.forms.get('settings_sonarr_apikey')
    c.execute("UPDATE table_settings_sonarr SET ip = ?, port = ?, base_url = ?, ssl = ?, apikey = ?, enabled = ?", (settings_sonarr_ip, settings_sonarr_port, settings_sonarr_baseurl, settings_sonarr_ssl, settings_sonarr_apikey, settings_sonarr_enabled))

    settings_radarr_enabled = request.forms.get('settings_radarr_enabled')
    settings_radarr_ip = request.forms.get('settings_radarr_ip')
    settings_radarr_port = request.forms.get('settings_radarr_port')
    settings_radarr_baseurl = request.forms.get('settings_radarr_baseurl')
    settings_radarr_ssl = request.forms.get('settings_radarr_ssl')
    if settings_radarr_ssl is None:
        settings_radarr_ssl = 'False'
    else:
        settings_radarr_ssl = 'True'
    settings_radarr_apikey = request.forms.get('settings_radarr_apikey')
    c.execute("UPDATE table_settings_radarr SET ip = ?, port = ?, base_url = ?, ssl = ?, apikey = ?, enabled = ?", (settings_radarr_ip, settings_radarr_port, settings_radarr_baseurl, settings_radarr_ssl, settings_radarr_apikey, settings_radarr_enabled))

    settings_bazarr_enabled = request.forms.get('settings_bazarr_enabled')
    settings_bazarr_ip = request.forms.get('settings_bazarr_ip')
    settings_bazarr_port = request.forms.get('settings_bazarr_port')
    settings_bazarr_baseurl = request.forms.get('settings_bazarr_baseurl')
    c.execute("UPDATE table_settings_bazarr SET ip = ?, port = ?, base_url = ?, enabled = ?", (settings_bazarr_ip, settings_bazarr_port, settings_bazarr_baseurl, settings_bazarr_enabled))

    conn.commit()
    c.close()

    logging.info('Settings saved succesfully.')
    
    redirect(ref)
github sametmax / 0bin / zerobin / cmd.py View on Github external
settings.HOST = host or settings.HOST
    settings.PORT = port or settings.PORT
    settings.USER = user or settings.USER
    settings.GROUP = group or settings.GROUP
    settings.PASTE_ID_LENGTH = paste_id_length or settings.PASTE_ID_LENGTH

    try:
        _, app = get_app(debug, settings_file, compressed_static, settings=settings)
    except SettingsValidationError as err:
        print('Configuration error: %s' % err.message, file=sys.stderr)
        sys.exit(1)

    thread.start_new_thread(drop_privileges, (settings.USER, settings.GROUP))

    if settings.DEBUG:
        run(app, host=settings.HOST, port=settings.PORT, reloader=True,
            server="cherrypy")
    else:
        run(app, host=settings.HOST, port=settings.PORT, server="cherrypy")
github kubeless / runtimes / stable / python / kubeless.py View on Github external
def metrics():
    bottle.response.content_type = prom.CONTENT_TYPE_LATEST
    return prom.generate_latest(prom.REGISTRY)