How to use add_route_endpoint method in localstack

Best Python code snippet using localstack_python

router.py

Source:router.py Github

copy

Full Screen

...125 # however then the redirection URL building will not work126 rule = Rule(path, endpoint=endpoint, methods=methods, host=host, **kwargs)127 self.add_rule(rule)128 return rule129 def add_route_endpoint(self, fn: _RouteEndpoint) -> Rule:130 """131 Adds a RouteEndpoint (typically a function decorated with ``@route``) as a rule to the router.132 :param fn: the RouteEndpoint function133 :return: the rule that was added134 """135 attr: _RuleAttributes = fn.rule_attributes136 return self.add(path=attr.path, endpoint=fn, host=attr.host, **attr.kwargs)137 def add_route_endpoints(self, obj: object) -> List[Rule]:138 """139 Scans the given object for members that can be used as a `RouteEndpoint` and adds them to the router.140 :param obj: the object to scan141 :return: the rules that were added142 """143 rules = []144 members = inspect.getmembers(obj)145 for _, member in members:146 if hasattr(member, "rule_attributes"):147 rules.append(self.add_route_endpoint(member))148 return rules149 def add_rule(self, rule: RuleFactory):150 with self._mutex:151 self.url_map.add(rule)152 def remove_rule(self, rule: Rule):153 """154 Removes a Rule from the Router.155 **Caveat**: This is an expensive operation. Removing rules from a URL Map is intentionally not supported by156 werkzeug due to issues with thread safety, see https://github.com/pallets/werkzeug/issues/796, and because157 using a lock in ``match`` would be too expensive. However, some services that use Routers for routing158 internal resources need to be able to remove rules when those resources are removed. So to remove rules we159 create a new Map without that rule. This will not prevent the rules from dispatching until the Map has been160 completely constructed.161 :param rule: the Rule to remove that was previously returned by ``add``.162 """163 with self._mutex:164 old = self.url_map165 if rule not in old._rules:166 raise KeyError("no such rule")167 new = _clone_map_without_rules(old)168 for r in old.iter_rules():169 if r == rule:170 # this works even with copied rules because of the __eq__ implementation of Rule171 continue172 new.add(r.empty())173 self.url_map = new174 def dispatch(self, request: Request) -> Response:175 """176 Does the entire dispatching roundtrip, from matching the request to endpoints, and then invoking the endpoint177 using the configured dispatcher of the router. For more information on the matching behavior,178 see ``werkzeug.routing.MapAdapter.match()``.179 :param request: the HTTP request180 :return: the HTTP response181 """182 matcher = self.url_map.bind(server_name=request.host)183 handler, args = matcher.match(184 request.path, method=request.method, query_args=to_str(request.query_string)185 )186 args.pop("__host__", None)187 return self.dispatcher(request, handler, args)188 def route(189 self,190 path: str,191 host: Optional[str] = None,192 methods: Optional[Iterable[str]] = None,193 **kwargs,194 ) -> Callable[[E], _RouteEndpoint]:195 """196 Returns a ``route`` decorator and immediately adds it to the router instance. This effectively mimics flask's197 ``@app.route``.198 :param path: the path pattern to match199 :param host: an optional host matching pattern. if not pattern is given, the rule matches any host200 :param methods: the allowed HTTP verbs for this rule201 :param kwargs: any other argument that can be passed to ``werkzeug.routing.Rule``202 :return: the function endpoint wrapped as a ``_RouteEndpoint``203 """204 def wrapper(fn):205 r = route(path, host, methods, **kwargs)206 fn = r(fn)207 self.add_route_endpoint(fn)208 return fn209 return wrapper210class RegexConverter(BaseConverter):211 def __init__(self, map: "Map", *args: Any, **kwargs: Any) -> None:212 super().__init__(map, *args, **kwargs)...

Full Screen

Full Screen

query_api.py

Source:query_api.py Github

copy

Full Screen

...64 """65 Registers the query API handlers into the given router. There are three routes, one for each SQS_ENDPOINT_STRATEGY.66 :param router: the router to add the handlers into.67 """68 router.add_route_endpoint(path_strategy_handler)69 router.add_route_endpoint(domain_strategy_handler)70 router.add_route_endpoint(legacy_handler)71class UnknownOperationException(Exception):72 pass73class InvalidAction(CommonServiceException):74 def __init__(self, action: str):75 super().__init__(76 "InvalidAction",77 f"The action {action} is not valid for this endpoint.",78 400,79 sender_fault=True,80 )81class BotoException(CommonServiceException):82 def __init__(self, boto_response):83 error = boto_response["Error"]84 super().__init__(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful