def js(): bottle.response.content_type = 'application/javascript' lp = bottle.urljoin(bottle.request.url, bottle.url('/lp')) ct = bottle.urljoin(bottle.request.url, bottle.url('/ct')) return static.trackingjs % {'lp':lp, 'ct':ct}
def js(): bottle.response.content_type = 'application/javascript' lp = bottle.urljoin(bottle.request.url, bottle.url('/lp')) ct = bottle.urljoin(bottle.request.url, bottle.url('/ct')) return static.trackingjs % {'lp': lp, 'ct': ct}
def get_all(): """ redirects the call to the agent configuration service on /v1/agents/all """ location = urljoin(AGENT_CONFIG_SERVER, '/v1/agents/all') raise HTTPResponse("", status=302, Location=location)
def get_account(name): """ redirects the call to the agent configuration service on /v1/agents/<name>/copnfig for the given name return map_and_redirect('/v1/agents/%s/', name) """ #bidders_list = bidders.keys() #name = bidders_list[0] result = { 'resultCode' : 1, 'resultDescription' : 'down' } account_name = "" proxy_support = urllib2.ProxyHandler({}) opener = urllib2.build_opener(proxy_support) location = urljoin( AGENT_CONFIG_SERVER, '/v1/agents/%s/config' % bidders[name]['agent_conf_name']) logger.info('bringing up bidder config from: %s' % location) res = opener.open(location) try : data = res.read() logger.info('get_account :: config file: %s' % data) conf_json = json.loads(data) account_name = conf_json["account"][0] except : result['resultCode'] = 6 result['resultDescription'] = 'unable to get config file with unexpected error' raise HTTPResponse(body=json.dumps(result), status=500,Content_Type='application/json') raise HTTPResponse(account_name, status=200, Content_Type='text/plain')
def get_url(routename, **kwargs): ''' customized get_url to allow additional prefix args ''' redirect = kwargs.pop('redirect', False) scriptname = bottle.request.environ.get('SCRIPT_NAME', '').strip('/') + '/' location = app.router.build(routename, **kwargs).lstrip('/') url = bottle.urljoin(bottle.urljoin('/', scriptname), location) if prefix and not redirect: url = prefix + '?' + bottle.urlencode({'q': url}) append = '?' if '?' in url: append = '&' url += '{}_={}'.format(append, time.time()) return url
def get_redirect_response_object(url, code=None): if not code: code = 303 if bottle.request.get( "SERVER_PROTOCOL") == "HTTP/1.1" else 302 res = bottle.response.copy(cls=HTTPResponse) res.status = code res.body = "" res.set_header("Location", bottle.urljoin(bottle.request.url, url)) return res
def test(key,secret) : method = bottle.request.method url = bottle.urljoin(bottle.request.url,'/ajax') params = { 'oauth_version': "1.0", 'oauth_nonce': oauth2.generate_nonce(), 'oauth_timestamp': oauth2.generate_timestamp(), 'oauth_consumer_key':key } consumer = oauth2.Consumer(key=key,secret=secret) req = oauth2.Request(method=method, url=url, parameters=params) signature_method = oauth2.SignatureMethod_HMAC_SHA1() req.sign_request(signature_method, consumer, None) bottle.redirect(req.to_url())
def test(key, secret): method = bottle.request.method url = bottle.urljoin(bottle.request.url, '/ajax') params = { 'oauth_version': "1.0", 'oauth_nonce': oauth2.generate_nonce(), 'oauth_timestamp': oauth2.generate_timestamp(), 'oauth_consumer_key': key } consumer = oauth2.Consumer(key=key, secret=secret) req = oauth2.Request(method=method, url=url, parameters=params) signature_method = oauth2.SignatureMethod_HMAC_SHA1() req.sign_request(signature_method, consumer, None) bottle.redirect(req.to_url())
def get_config(name): """ redirects the call to the agent configuration service on /v1/agents/<name>/config for the given name return map_and_redirect('/v1/agents/%s/config', name) """ proxy_support = urllib2.ProxyHandler({}) opener = urllib2.build_opener(proxy_support) location = urljoin( AGENT_CONFIG_SERVER, '/v1/agents/%s/config' % bidders[name]['agent_conf_name']) logger.info('bringing up bidder config from: %s' % location) res = opener.open(location) data = res.read() raise HTTPResponse(data, status=200, Content_Type='application/json')
def map_and_redirect(uri, name): """ maps the name, sets the uri and raises a redirection otherwise returns the json result code """ try : # try to map the name to the internal config name location = urljoin( AGENT_CONFIG_SERVER, uri % bidders[name]['agent_conf_name']) except : return { 'resultCode' : 1, 'resultDescription' : 'unable to map %s' % name } raise HTTPResponse("", status=302, Location=location)
def map_and_redirect(uri, name): """ maps the name, sets the uri and raises a redirection otherwise returns the json result code """ try : # try to map the name to the internal config name location = urljoin( AGENT_CONFIG_SERVER, uri % bidders[name]['agent_conf_name']) except : return { 'resultCode' : 1, 'resultDescription' : 'unable to map %s' % name } raise HTTPResponse(body=json.dumps(result), status=404, Content_Type='application/json') raise HTTPResponse("", status=302, Location=location)