How to use in_expanded_range method in localstack

Best Python code snippet using localstack_python

container_client.py

Source:container_client.py Github

copy

Full Screen

...76 if self.contains(port):77 return78 bisected_host_port = None79 for from_range, to_range in self.mappings.items():80 if not self.in_expanded_range(port, from_range):81 continue82 if not self.in_expanded_range(mapped, to_range):83 continue84 from_range_len = from_range[1] - from_range[0]85 to_range_len = to_range[1] - to_range[0]86 is_uniform = from_range_len == to_range_len87 if is_uniform:88 self.expand_range(port, from_range)89 self.expand_range(mapped, to_range)90 else:91 if not self.in_range(mapped, to_range):92 continue93 # extending a 1 to 1 mapping to be many to 194 elif from_range_len == 1:95 self.expand_range(port, from_range)96 # splitting a uniform mapping97 else:98 bisected_port_index = mapped - to_range[0]99 bisected_host_port = from_range[0] + bisected_port_index100 self.bisect_range(mapped, to_range)101 self.bisect_range(bisected_host_port, from_range)102 break103 return104 protocol = str(protocol or "tcp").lower()105 if bisected_host_port is None:106 port_range = [port, port, protocol]107 elif bisected_host_port < port:108 port_range = [bisected_host_port, port, protocol]109 else:110 port_range = [port, bisected_host_port, protocol]111 self.mappings[HashableList(port_range)] = [mapped, mapped]112 def to_str(self) -> str:113 bind_address = f"{self.bind_host}:" if self.bind_host else ""114 def entry(k, v):115 protocol = "/%s" % k[2] if k[2] != "tcp" else ""116 if k[0] == k[1] and v[0] == v[1]:117 return "-p %s%s:%s%s" % (bind_address, k[0], v[0], protocol)118 if k[0] != k[1] and v[0] == v[1]:119 return "-p %s%s-%s:%s%s" % (bind_address, k[0], k[1], v[0], protocol)120 return "-p %s%s-%s:%s-%s%s" % (bind_address, k[0], k[1], v[0], v[1], protocol)121 return " ".join([entry(k, v) for k, v in self.mappings.items()])122 def to_list(self) -> List[str]: # TODO test123 bind_address = f"{self.bind_host}:" if self.bind_host else ""124 def entry(k, v):125 protocol = "/%s" % k[2] if k[2] != "tcp" else ""126 if k[0] == k[1] and v[0] == v[1]:127 return ["-p", f"{bind_address}{k[0]}:{v[0]}{protocol}"]128 return ["-p", f"{bind_address}{k[0]}-{k[1]}:{v[0]}-{v[1]}{protocol}"]129 return [item for k, v in self.mappings.items() for item in entry(k, v)]130 def to_dict(self) -> Dict[str, Union[Tuple[str, Union[int, List[int]]], int]]:131 bind_address = self.bind_host or ""132 def entry(k, v):133 protocol = "/%s" % k[2]134 if k[0] != k[1] and v[0] == v[1]:135 container_port = v[0]136 host_ports = list(range(k[0], k[1] + 1))137 return [138 (139 f"{container_port}{protocol}",140 (bind_address, host_ports) if bind_address else host_ports,141 )142 ]143 return [144 (145 f"{container_port}{protocol}",146 (bind_address, host_port) if bind_address else host_port,147 )148 for container_port, host_port in zip(range(v[0], v[1] + 1), range(k[0], k[1] + 1))149 ]150 items = [item for k, v in self.mappings.items() for item in entry(k, v)]151 return dict(items)152 def contains(self, port):153 for from_range, to_range in self.mappings.items():154 if self.in_range(port, from_range):155 return True156 def in_range(self, port, range):157 return port >= range[0] and port <= range[1]158 def in_expanded_range(self, port, range):159 return port >= range[0] - 1 and port <= range[1] + 1160 def expand_range(self, port, range):161 if self.in_range(port, range):162 return163 if port == range[0] - 1:164 range[0] = port165 elif port == range[1] + 1:166 range[1] = port167 else:168 raise Exception("Unable to add port %s to existing range %s" % (port, range))169 """Bisect a port range, at the provided port170 This is needed in some cases when adding a non-uniform host to port mapping171 adjacent to an existing port range172 """...

Full Screen

Full Screen

bootstrap.py

Source:bootstrap.py Github

copy

Full Screen

...245 raise Exception('Unable to add mapping for invalid port: %s' % port)246 if self.contains(port):247 return248 for from_range, to_range in self.mappings.items():249 if not self.in_expanded_range(port, from_range):250 continue251 if not self.in_expanded_range(mapped, to_range):252 continue253 self.expand_range(port, from_range)254 self.expand_range(mapped, to_range)255 return256 self.mappings[self.HashableList([port, port])] = [mapped, mapped]257 def to_str(self):258 def entry(k, v):259 if k[0] == k[1] and v[0] == v[1]:260 return '-p %s:%s' % (k[0], v[0])261 return '-p %s-%s:%s-%s' % (k[0], k[1], v[0], v[1])262 return ' '.join([entry(k, v) for k, v in self.mappings.items()])263 def contains(self, port):264 for from_range, to_range in self.mappings.items():265 if self.in_range(port, from_range):266 return True267 def in_range(self, port, range):268 return port >= range[0] and port <= range[1]269 def in_expanded_range(self, port, range):270 return port >= range[0] - 1 and port <= range[1] + 1271 def expand_range(self, port, range):272 if self.in_range(port, range):273 return274 if port == range[0] - 1:275 range[0] = port276 elif port == range[1] + 1:277 range[1] = port278 else:279 raise Exception('Unable to add port %s to existing range %s' % (port, range))280def get_docker_image_to_start():281 image_name = os.environ.get('IMAGE_NAME')282 if not image_name:283 image_name = constants.DOCKER_IMAGE_NAME...

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