Best Python code snippet using localstack_python
dumper.py
Source:dumper.py
...41 text = indent(ident, text)42 click.secho(text, file=self.outfp, **style)43 if self.outfp:44 self.outfp.flush()45 def _echo_headers(self, headers):46 for k, v in headers.fields:47 k = strutils.bytes_to_escaped_str(k)48 v = strutils.bytes_to_escaped_str(v)49 out = "{}: {}".format(50 click.style(k, fg="blue"),51 click.style(v)52 )53 self.echo(out, ident=4)54 def _echo_message(self, message):55 _, lines, error = contentviews.get_message_content_view(56 self.default_contentview,57 message58 )59 if error:60 ctx.log.debug(error)61 if self.flow_detail == 3:62 lines_to_echo = itertools.islice(lines, 70)63 else:64 lines_to_echo = lines65 styles = dict(66 highlight=dict(bold=True),67 offset=dict(fg="blue"),68 header=dict(fg="green", bold=True),69 text=dict(fg="green")70 )71 content = u"\r\n".join(72 u"".join(colorful(line, styles)) for line in lines_to_echo73 )74 if content:75 self.echo("")76 self.echo(content)77 if next(lines, None):78 self.echo("(cut off)", ident=4, dim=True)79 if self.flow_detail >= 2:80 self.echo("")81 def _echo_request_line(self, flow):82 if flow.client_conn:83 client = click.style(84 strutils.escape_control_characters(85 repr(flow.client_conn.address)86 )87 )88 elif flow.request.is_replay:89 client = click.style("[replay]", fg="yellow", bold=True)90 else:91 client = ""92 pushed = ' PUSH_PROMISE' if 'h2-pushed-stream' in flow.metadata else ''93 method = flow.request.method + pushed94 method_color = dict(95 GET="green",96 DELETE="red"97 ).get(method.upper(), "magenta")98 method = click.style(99 strutils.escape_control_characters(method),100 fg=method_color,101 bold=True102 )103 if self.showhost:104 url = flow.request.pretty_url105 else:106 url = flow.request.url107 url = click.style(strutils.escape_control_characters(url), bold=True)108 http_version = ""109 if flow.request.http_version not in ("HTTP/1.1", "HTTP/1.0"):110 # We hide "normal" HTTP 1.111 http_version = " " + flow.request.http_version112 line = "{client}: {method} {url}{http_version}".format(113 client=client,114 method=method,115 url=url,116 http_version=http_version117 )118 self.echo(line)119 def _echo_response_line(self, flow):120 if flow.response.is_replay:121 replay = click.style("[replay] ", fg="yellow", bold=True)122 else:123 replay = ""124 code = flow.response.status_code125 code_color = None126 if 200 <= code < 300:127 code_color = "green"128 elif 300 <= code < 400:129 code_color = "magenta"130 elif 400 <= code < 600:131 code_color = "red"132 code = click.style(133 str(code),134 fg=code_color,135 bold=True,136 blink=(code == 418)137 )138 reason = click.style(139 strutils.escape_control_characters(flow.response.reason),140 fg=code_color,141 bold=True142 )143 if flow.response.raw_content is None:144 size = "(content missing)"145 else:146 size = human.pretty_size(len(flow.response.raw_content))147 size = click.style(size, bold=True)148 arrows = click.style(" <<", bold=True)149 if self.flow_detail == 1:150 # This aligns the HTTP response code with the HTTP request method:151 # 127.0.0.1:59519: GET http://example.com/152 # << 304 Not Modified 0b153 arrows = " " * (len(repr(flow.client_conn.address)) - 2) + arrows154 line = "{replay}{arrows} {code} {reason} {size}".format(155 replay=replay,156 arrows=arrows,157 code=code,158 reason=reason,159 size=size160 )161 self.echo(line)162 def echo_flow(self, f):163 if f.request:164 self._echo_request_line(f)165 if self.flow_detail >= 2:166 self._echo_headers(f.request.headers)167 if self.flow_detail >= 3:168 self._echo_message(f.request)169 if f.response:170 self._echo_response_line(f)171 if self.flow_detail >= 2:172 self._echo_headers(f.response.headers)173 if self.flow_detail >= 3:174 self._echo_message(f.response)175 if f.error:176 msg = strutils.escape_control_characters(f.error.msg)177 self.echo(" << {}".format(msg), bold=True, fg="red")178 def match(self, f):179 if self.flow_detail == 0:180 return False181 if not self.filter:182 return True183 elif flowfilter.match(self.filter, f):184 return True185 return False186 def response(self, f):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!