Python bottle.request.url() Examples
The following are 17
code examples of bottle.request.url().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bottle.request
, or try the search function
.
Example #1
Source File: server_mgr_mon_base_plugin.py From contrail-server-manager with Apache License 2.0 | 6 votes |
def copy_ssh_keys_to_servers(self, ip, port, payload, sm_args=None): servers = self._serverDb.get_server({"id": str(payload["id"])}, detail=True) server = servers[0] success = self.copy_ssh_keys_to_server(str(server["ip_address"]), str(server["id"])) self._smgr_log.log(self._smgr_log.DEBUG, "COPY-KEY: Host: " + server["id"] + " /Status: " + str(success)) if success and self._provision_immediately_after_reimage == True: gevent.spawn(self.gevent_puppet_agent_action, server, self._serverDb, sm_args, "start") if success and self.inventory_config_set: try: url = "http://%s:%s/run_inventory" % (ip, port) payload = json.dumps(payload) headers = {'content-type': 'application/json'} resp = requests.post(url, headers=headers, timeout=5, data=payload) return resp.text except Exception as e: self._smgr_log.log("error", "Error running inventory on " + str(payload) + " : " + str(e)) return None
Example #2
Source File: bottle3.py From pyFileFixity with MIT License | 6 votes |
def handle(self, url, method): """ Execute the handler bound to the specified url and method and return its output. If catchall is true, exceptions are catched and returned as HTTPError(500) objects. """ if not self.serve: return HTTPError(503, "Server stopped") handler, args = self.match_url(url, method) if not handler: return HTTPError(404, "Not found:" + url) try: return handler(**args) except HTTPResponse as e: return e except Exception as e: if isinstance(e, (KeyboardInterrupt, SystemExit, MemoryError))\ or not self.catchall: raise return HTTPError(500, 'Unhandled exception', e, format_exc(10))
Example #3
Source File: bottle3.py From pyFileFixity with MIT License | 5 votes |
def url(routename, **kargs): return app().get_url(routename, **kargs)
Example #4
Source File: server_mgr_mon_base_plugin.py From contrail-server-manager with Apache License 2.0 | 5 votes |
def get_sandesh_url(self, ip, introspect_port, uve_name, server_id=None): if server_id: url = "http://%s:%s/Snh_SandeshUVECacheReq?tname=%s&key=%s" % \ (str(ip), str(introspect_port), uve_name, server_id) else: url = "http://%s:%s/Snh_SandeshUVECacheReq?x=%s" % \ (str(ip), str(introspect_port), uve_name) return url
Example #5
Source File: shockpot.py From shockpot with GNU Lesser General Public License v2.1 | 5 votes |
def get_request_record(): headers = [[name, value,] for name, value in request.headers.items()] is_shellshock_check = is_shellshock(headers) command, data = None, None if is_shellshock_check: command, data = perform_commands(headers) if public_ip: dest_host = public_ip else: dest_host = urlparse.urlparse(request.url).netloc.split(':',1)[0] return { 'method': request.method, 'url': request.url, 'path': request.path, 'query_string': request.query_string, 'headers': headers, 'source_ip': request.environ.get('REMOTE_ADDR'), 'dest_port': request.environ.get('SERVER_PORT'), 'dest_host': dest_host, 'is_shellshock': is_shellshock_check, 'command': command, 'command_data': data, 'timestamp': str(datetime.datetime.now()) }
Example #6
Source File: web.py From mailur with GNU General Public License v3.0 | 5 votes |
def proxy_by_nginx(url): url = '/.proxy?url=%s' % url response.set_header('X-Accel-Redirect', url) return ''
Example #7
Source File: web.py From mailur with GNU General Public License v3.0 | 5 votes |
def redirect(url, code=None): if not code: code = 303 if request.get('SERVER_PROTOCOL') == 'HTTP/1.1' else 302 response.status = code response.body = '' response.set_header('Location', urllib.parse.urljoin(request.url, url)) return response
Example #8
Source File: web.py From mailur with GNU General Public License v3.0 | 5 votes |
def proxy(): url = request.query.get('url') if not url: return abort(400) return proxy_by_nginx(url)
Example #9
Source File: web.py From mailur with GNU General Public License v3.0 | 5 votes |
def avatars(): hashes = set(request.query['hashes'].split(',')) size = request.query.get('size', 20) default = request.query.get('default', 'identicon') cls = request.query.get('cls', '.pic-%s') response.content_type = 'text/css' return '\n'.join(( '%s {background-image: url(data:image/gif;base64,%s);}' % ((cls % h), i.decode()) ) for h, i in fetch_avatars(hashes, size, default))
Example #10
Source File: api.py From ray with MIT License | 5 votes |
def dispatch(url): """ This class is the beginning of all entrypoints in the Ray API. Here, each url will be redirect to the right handler """ url = bottle_req.path log.info('request: %s', bottle_req.url) if url[-1] == '/': url = url[:-1] response_code = 200 try: processed = process(url, bottle_req, bottle_resp) try: from_func, http_status = processed[0], processed[1] bottle_resp.status = http_status return from_func except: return processed except exceptions.RayException as e: log.exception('ray exception: ') response_code = e.http_code except: log.exception('exception:') raise bottle_resp.status = response_code
Example #11
Source File: bottle3.py From pyFileFixity with MIT License | 5 votes |
def redirect(url, code=303): """ Aborts execution and causes a 303 redirect """ scriptname = request.environ.get('SCRIPT_NAME', '').rstrip('/') + '/' location = urljoin(request.url, urljoin(scriptname, url)) raise HTTPResponse("", status=code, header=dict(Location=location))
Example #12
Source File: bottle2.py From pyFileFixity with MIT License | 5 votes |
def url(routename, **kargs): return app().get_url(routename, **kargs)
Example #13
Source File: bottle2.py From pyFileFixity with MIT License | 5 votes |
def redirect(url, code=303): """ Aborts execution and causes a 303 redirect """ scriptname = request.environ.get('SCRIPT_NAME', '').rstrip('/') + '/' location = urljoin(request.url, urljoin(scriptname, url)) raise HTTPResponse("", status=code, header=dict(Location=location))
Example #14
Source File: bottle2.py From pyFileFixity with MIT License | 5 votes |
def url(self): """ Full URL as requested by the client (computed). This value is constructed out of different environment variables and includes scheme, host, port, scriptname, path and query string. """ scheme = self.environ.get('wsgi.url_scheme', 'http') host = self.environ.get('HTTP_X_FORWARDED_HOST', self.environ.get('HTTP_HOST', None)) if not host: host = self.environ.get('SERVER_NAME') port = self.environ.get('SERVER_PORT', '80') if scheme + port not in ('https443', 'http80'): host += ':' + port parts = (scheme, host, urlquote(self.fullpath), self.query_string, '') return urlunsplit(parts)
Example #15
Source File: bottle2.py From pyFileFixity with MIT License | 5 votes |
def handle(self, url, method): """ Execute the handler bound to the specified url and method and return its output. If catchall is true, exceptions are catched and returned as HTTPError(500) objects. """ if not self.serve: return HTTPError(503, "Server stopped") handler, args = self.match_url(url, method) if not handler: return HTTPError(404, "Not found:" + url) try: return handler(**args) except HTTPResponse, e: return e
Example #16
Source File: api.py From ray with MIT License | 5 votes |
def __handle_action(url): # url e.g: /api/user/123/action arg = None if len(url.split('/')) >= 5: # indicate that has an id between endpoint and action_name arg = http.param_at(url, -2) return Action(url, arg, bottle_req).process_action()
Example #17
Source File: server_mgr_mon_base_plugin.py From contrail-server-manager with Apache License 2.0 | 4 votes |
def validate_rest_api_args(self, request, rev_tags_dict): ret_data = {"msg": None, "type_msg": None} match_keys = list(['id', 'cluster_id', 'tag', 'where']) print_match_keys = list(['server_id', 'cluster_id', 'tag', 'where']) self._smgr_log.log(self._smgr_log.DEBUG, "Validating bottle arguments.") ret_data['status'] = 1 query_args = parse_qs(urlparse(request.url).query, keep_blank_values=True) if len(query_args) == 0: ret_data["type"] = ["all"] ret_data["status"] = True ret_data["match_key"] = None ret_data["match_value"] = None elif len(query_args) >= 1: select_value_list = None if "select" in query_args: select_value_list = query_args.get("select", None)[0] select_value_list = str(select_value_list).split(',') self._smgr_log.log(self._smgr_log.DEBUG, "Select value list=" + str(select_value_list)) query_args.pop("select") if not select_value_list: ret_data["type"] = ["all"] else: ret_data["type"] = select_value_list match_key = match_value = None if query_args: match_key, match_value = query_args.popitem() if match_key and match_key not in match_keys: ret_data["status"] = False ret_data["msg"] = "Wrong Match Key Specified. " + "Choose one of the following keys: " + \ str(['--{0}'.format(key) for key in print_match_keys]).strip('[]') self._smgr_log.log(self._smgr_log.ERROR, "Wrong Match Key") elif match_key and (match_value is None or match_value[0] == ''): ret_data["status"] = False self._smgr_log.log(self._smgr_log.ERROR, "No macth value given") ret_data["msg"] = "No Match Value Specified.\n" else: ret_data["status"] = True if match_key: ret_data["match_key"] = str(match_key) else: ret_data["match_key"] = None if match_value: ret_data["match_value"] = str(match_value[0]) else: ret_data["match_value"] = None return ret_data