How to use _clone_map_without_rules method in localstack

Best Python code snippet using localstack_python

router.py

Source:router.py Github

copy

Full Screen

...28 """29 A Dispatcher that treats the matching endpoint as a callable and invokes it with the Request and request arguments.30 """31 return endpoint(request, args)32def _clone_map_without_rules(old: Map) -> Map:33 return Map(34 default_subdomain=old.default_subdomain,35 charset=old.charset,36 strict_slashes=old.strict_slashes,37 merge_slashes=old.merge_slashes,38 redirect_defaults=old.redirect_defaults,39 converters=old.converters,40 sort_parameters=old.sort_parameters,41 sort_key=old.sort_key,42 encoding_errors=old.encoding_errors,43 host_matching=old.host_matching,44 )45class Router(Generic[E]):46 """47 A Router is a wrapper around werkzeug's routing Map, that adds convenience methods and additional dispatching48 logic via the ``Dispatcher`` Protocol.49 """50 url_map: Map51 dispatcher: Dispatcher52 def __init__(53 self, dispatcher: Dispatcher = None, converters: Mapping[str, BaseConverter] = None54 ):55 self.url_map = Map(host_matching=True, strict_slashes=False, converters=converters)56 self.dispatcher = dispatcher or call_endpoint57 self._mutex = threading.RLock()58 def add(59 self,60 path: str,61 endpoint: E,62 host: Optional[str] = None,63 methods: Optional[Iterable[str]] = None,64 **kwargs,65 ) -> Rule:66 """67 Adds a new Rule to the URL Map.68 :param path: the path pattern to match69 :param endpoint: the endpoint to invoke70 :param host: an optional host matching pattern. if not pattern is given, the rule matches any host71 :param methods: the allowed HTTP verbs for this rule72 :param kwargs: any other argument that can be passed to ``werkzeug.routing.Rule``73 :return:74 """75 if host is None and self.url_map.host_matching:76 # this creates a "match any" rule, and will put the value of the host77 # into the variable "__host__"78 host = "<__host__>"79 # the typing for endpoint is a str, but the doc states it can be any value,80 # however then the redirection URL building will not work81 rule = Rule(path, endpoint=endpoint, methods=methods, host=host, **kwargs)82 self.add_rule(rule)83 return rule84 def add_rule(self, rule: RuleFactory):85 with self._mutex:86 self.url_map.add(rule)87 def remove_rule(self, rule: Rule):88 """89 Removes a Rule from the Router.90 **Caveat**: This is an expensive operation. Removing rules from a URL Map is intentionally not supported by91 werkzeug due to issues with thread safety, see https://github.com/pallets/werkzeug/issues/796, and because92 using a lock in ``match`` would be too expensive. However, some services that use Routers for routing93 internal resources need to be able to remove rules when those resources are removed. So to remove rules we94 create a new Map without that rule. This will not prevent the rules from dispatching until the Map has been95 completely constructed.96 :param rule: the Rule to remove that was previously returned by ``add``.97 """98 with self._mutex:99 old = self.url_map100 if rule not in old._rules:101 raise KeyError("no such rule")102 new = _clone_map_without_rules(old)103 for r in old.iter_rules():104 if r == rule:105 # this works even with copied rules because of the __eq__ implementation of Rule106 continue107 new.add(r.empty())108 self.url_map = new109 def dispatch(self, request: Request) -> Response:110 """111 Does the entire dispatching roundtrip, from matching the request to endpoints, and then invoking the endpoint112 using the configured dispatcher of the router. For more information on the matching behavior,113 see ``werkzeug.routing.MapAdapter.match()``.114 :param request: the HTTP request115 :return: the HTTP response116 """...

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