How to use the bottle.request 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 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 jqqqqqqqqqq / coolq-telegram-bot / cqhttp / __init__.py View on Github external
def _handle(self):
        if self._secret:
            # check signature
            if 'X-Signature' not in request.headers:
                if self.debug_mode:
                    logger.error('401: X-Signature not in headers')
                abort(401)

            sec = self._secret
            if isinstance(sec, str):
                sec = sec.encode('utf-8')
            sig = hmac.new(sec, request.body.read(), 'sha1').hexdigest()
            if request.headers['X-Signature'] != 'sha1=' + sig:
                if self.debug_mode:
                    logger.error('403: X-Signature not match')
                abort(403)

        post_type = request.json.get('post_type')
        if post_type not in ('message', 'event', 'request'):
            if self.debug_mode:
github coders4help / lagesonum / lagesonum / bottle_app.py View on Github external
usr_hash = get_fingerprint(request)

    result_num = []
    result_nonuniq = []
    result_failed = []

    # TODO make place variable, depending on current request
    q = Place.select().where(Place.place == 'LAGESO')
    lageso = q.get() if q.count() == 1 else None

    if not numbers:
        result_num.append(_('novalidnumbers'))
    else:
        authed_user = None
        s = request.environ.get('beaker.session')
        username, ignore = request.auth or (None, None)
        try:
            authed_user = User.get(User.username == (s.get('user', username) if s else None))
        except User.DoesNotExist:
            pass

        for num in numbers:
            if is_valid_number(num):
                try:
                    n = Number.create(number=num.upper(), time=timestamp, place=lageso, fingerprint=usr_hash, user=authed_user)
                except IntegrityError:
                    try:
                        n = Number.get(Number.number == num.upper())
                    except DoesNotExist:
                        result_failed.append(num)
                    else:
                        result_nonuniq.append(n.number)
github microsoftgraph / python-sample-auth / sample_requests.py View on Github external
def authorized():
    """Handler for the application's Redirect Uri."""
    if bottle.request.query.state != MSGRAPH.auth_state:
        raise Exception('state returned to redirect URL does not match!')
    MSGRAPH.fetch_token(config.AUTHORITY_URL + config.TOKEN_ENDPOINT,
                        client_secret=config.CLIENT_SECRET,
                        authorization_response=bottle.request.url)
    return bottle.redirect('/graphcall')
github SciSharp / BotSharp / BotSharp.MachineLearning / SpaCy / server.py View on Github external
@route('/tokenizer', method = 'GET')
def tokenize():
    return spacy_tokenize(request.query.text)
github USMediaConsulting / agent_gateway / agentgw / agent_gateway.py View on Github external
if name in bidders :
        result['resultCode'] = 1
        result['resultDescription'] = 'agent already started'    
        raise HTTPResponse(body=json.dumps(result), status=500, 
                Content_Type='application/json')
    else :
        bidder = {}

    # save the executable name and external name
    bidder['bidder_name'] = name
    bidder['executable'] = request.query['executable']  
    # save the params
    escape = lambda x : '"%s"' % x
    bidder['params'] = {
         k:escape(v) for k,v in request.query.iteritems() 
            if k not in ('executable', ) 
    }
    
    # create a file with the json configuration
    conf_file_name = os.path.join(
        bidders_config_base_path, '%s.conf.json' % name)    
    try :
        conf_file = open(conf_file_name, 'w')
        conf_file.write(json.dumps(request.json))
        conf_file.close()
    except :
        result['resultCode'] = 6
        result['resultDescription'] = 'unable to create config file'
        raise HTTPResponse(body=json.dumps(result), status=500, 
                Content_Type='application/json')
github sjjf / md_server / mdserver / server.py View on Github external
def gen_hostname(self):
        client_ip = bottle.request.get('REMOTE_ADDR')
        logger.debug("Getting hostname for %s", client_ip)
        config = bottle.request.app.config
        db = Database(config['mdserver.db_file'])
        entry = db.query('mds_ipv4', client_ip)
        if entry is None:
            logger.info("Failed to find MAC for %s in database",
                        client_ip)
            abort(401, "Unknown client")
        return entry['domain_name']
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
"Can't delete bundle %s because it appears in multiple worksheets "
                "(--force to override):\n  %s"
                % (uuid, '\n  '.join(worksheet.simple_str() for worksheet in worksheets))
            )

    # Delete the actual bundle
    if not dry_run:
        if data_only:
            # Just remove references to the data hashes
            local.model.remove_data_hash_references(relevant_uuids)
        else:
            # Actually delete the bundle
            local.model.delete_bundles(relevant_uuids)

        # Update user statistics
        local.model.update_user_disk_used(request.user.user_id)

    # Delete the data.
    for uuid in relevant_uuids:
        # check first is needs to be deleted
        bundle_location = local.bundle_store.get_bundle_location(uuid)
        if os.path.lexists(bundle_location):
            local.bundle_store.cleanup(uuid, dry_run)

    return relevant_uuids
github cuckoosandbox / cuckoo / utils / api.py View on Github external
def tasks_create_file():
    response = {"error" : False}

    data = request.files.file
    package = request.forms.get("package")
    timeout = request.forms.get("timeout")
    priority = request.forms.get("priority", 1)
    options = request.forms.get("options")
    machine = request.forms.get("machine")
    platform = request.forms.get("platform")
    custom = request.forms.get("custom")

    temp_file_path = store_temp_file(data.file.read(), data.filename)
    db = Database()
    task_id = db.add_path(file_path=temp_file_path,
                          package=package,
                          timeout=timeout,
                          priority=priority,
                          options=options,
                          machine=machine,
github Othernet-Project / librarian / librarian / librarian_logs / dashboard_plugin.py View on Github external
def get_context(self):
        logpath = request.app.config['logging.output']
        with open(logpath, 'rt') as log:
            logs = iter_lines(list(log)[-100:])
        return dict(logs=logs)