How to use the bottle.request.environ.get function in bottle

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 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 coders4help / lagesonum / lagesonum / bottle_app.py View on Github external
@hook('before_request')
def _check_locale():
    """ Determine locale from request if non set """
    if not request.environ.get('LOCALE'):
        accept_language = request.get_header('Accept-Language')
        if not accept_language:
            return

        accepted = []
        for language in accept_language.split(','):
            if language.split(';')[0] == language:
                accepted.append(language.strip())
            else:
                accepted.append(language.split(";")[0].strip())
        # fine tuning order of locale_q_pair according to q-value necessary?!

        lang = Locale.negotiate(accepted, [l[0] for l in LANGS])
        if lang:
            request.environ['LOCALE'] = str(lang)
github openstack / keystone / keystone / identity.py View on Github external
def get_normalized_request_content(model):
    """initialize a model from json/xml contents of request body"""

    ctype = request.environ.get("CONTENT_TYPE")
    if ctype == "application/xml":
        ret = model.from_xml(request.body.read())
    elif ctype == "application/json":
        ret = model.from_json(request.body.read())
    else:
        raise fault.IDMFault("I don't understand the content type ", code=415)
    return ret
github facebook / openbmc / meta-facebook / meta-wedge / recipes-wedge / rest-api / files / rest.py View on Github external
def log_after_request():
    try:
        length = bottle.response.content_length
    except:
        try:
            length = len(bottle.response.body)
        except:
            length = 0

    logging.info('{} - - [{}] "{} {} {}" {} {}'.format(
                  bottle.request.environ.get('REMOTE_ADDR'),
                  datetime.datetime.now().strftime('%d/%b/%Y %H:%M:%S'),
                  bottle.request.environ.get('REQUEST_METHOD'),
                  bottle.request.environ.get('REQUEST_URI'),
                  bottle.request.environ.get('SERVER_PROTOCOL'),
                  bottle.response.status_code,
                  length))
github yadudoc / cloud_kotta / web2 / publish.py View on Github external
@route('/publish/', method='GET', name="publish_job")
def publish_job(jobid):
    session = bottle.request.environ.get('beaker.session')
    require_login(session)
    print session["username"]

    prefill = None
    print "In publish =============================="
    pairs = web_server.get_job_info(request, jobid);
    user  = filter(lambda x: x[0] == 'username', pairs)

    # Check if you own the job.
    # If you do not own the job you get an error message.
    if user[0][1] == session["username"]:
        print "Username matches"
    else:
        return template('./views/error.tpl',
                        error_str="You are not the owner of this job :{0} \nInsufficient permissions to publish job".format(jobid),
                        session=session)
github MoritzGruber / instabot / dashbaord / dashbaord.py View on Github external
@route('/', method='POST')
def index():
    if request.environ.get('REMOTE_ADDR') in bots.keys():
        print "updating " + request.environ.get('REMOTE_ADDR')
        bots[request.environ.get('REMOTE_ADDR')].currtime = time.time()
    else:
        print "creating " + request.environ.get('REMOTE_ADDR')
        for line in request.body:
            jsondata = json.loads(line)
        bots[request.environ.get('REMOTE_ADDR')] = Bot(ip=request.environ.get('REMOTE_ADDR'), currtime=time.time(),
                                                       username=jsondata['username'], topic=jsondata['topic'])
github facebook / openbmc / meta-facebook / meta-wedge / recipes-wedge / rest-api / files / rest.py View on Github external
def log_after_request():
    try:
        length = bottle.response.content_length
    except:
        try:
            length = len(bottle.response.body)
        except:
            length = 0

    logging.info('{} - - [{}] "{} {} {}" {} {}'.format(
                  bottle.request.environ.get('REMOTE_ADDR'),
                  datetime.datetime.now().strftime('%d/%b/%Y %H:%M:%S'),
                  bottle.request.environ.get('REQUEST_METHOD'),
                  bottle.request.environ.get('REQUEST_URI'),
                  bottle.request.environ.get('SERVER_PROTOCOL'),
                  bottle.response.status_code,
                  length))
github fxtxkktv / lnmVPN / tools / Network.py View on Github external
def deliface(id):
    s = request.environ.get('beaker.session')
    sql = " DELETE FROM netiface WHERE id=%s "
    sql2 = " select ifacename FROM netiface WHERE id=%s "
    ifacename = readDb(sql2,(id,))
    result = writeDb(sql,(id,))
    if result == True :
       writeNIconf(action='uptconf')
       cmds.servboot('networks',action='uptconf')
       writeUTMconf(action='uptconf')
       msg = {'color':'green','message':u'删除成功'}
       cmds.gettuplerst('ip addr flush dev %s' % ifacename[0].get('ifacename'))
       #如果是PPP类型接口,停用ADSL
       cmds.gettuplerst('ip link set %s down' % ifacename[0].get('ifacename'))
       cmds.gettuplerst('ps aux|grep -e \'xdsl.*%s\'|grep -v grep|awk \'{print $2}\' |xargs -i kill -9 {}' % id)
       #恢复绑定
       sql2 = "update sysattr set status='1' where attr=%s"
       writeDb(sql2,(ifacename[0].get('ifacename'),))
github harvard-lil / perma / services / docker / webrecorder / contentcontroller.py View on Github external
recording = kwargs.get('recording')
                patch_recording = kwargs.get('patch_recording')

                if recording and ra_rec == recording.my_id:
                    ra_recording = recording
                elif patch_recording and ra_rec == patch_recording.my_id:
                    ra_recording = patch_recording

        url = cdx.get('url')
        referrer = request.environ.get('HTTP_REFERER')

        if not referrer:
            referrer = url
        elif ('wsgiprox.proxy_host' not in request.environ and
            request.environ.get('HTTP_HOST') in referrer):
            referrer = url

        self.dyn_stats.update_dyn_stats(url, kwargs, referrer, source, ra_recording)
github pyload / pyload-webui / pyload_webui / webui / utils.py View on Github external
def set_session(request, user):
    ses = request.environ.get('beaker.session')
    ses['uid'] = user.uid
    ses.save()
    return ses