• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python strutils.bytes_to_escaped_str函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mitmproxy.utils.strutils.bytes_to_escaped_str函数的典型用法代码示例。如果您正苦于以下问题:Python bytes_to_escaped_str函数的具体用法?Python bytes_to_escaped_str怎么用?Python bytes_to_escaped_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了bytes_to_escaped_str函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _echo_headers

 def _echo_headers(self, headers):
     for k, v in headers.fields:
         k = strutils.bytes_to_escaped_str(k)
         v = strutils.bytes_to_escaped_str(v)
         out = "{}: {}".format(
             click.style(k, fg="blue"),
             click.style(v)
         )
         self.echo(out, ident=4)
开发者ID:Yoginski,项目名称:mitmproxy,代码行数:9,代码来源:dumper.py


示例2: _echo_message

    def _echo_message(self, message):
        if self.flow_detail >= 2 and hasattr(message, "headers"):
            headers = "\r\n".join(
                "{}: {}".format(
                    click.style(
                        strutils.bytes_to_escaped_str(k), fg="blue", bold=True
                    ),
                    click.style(
                        strutils.bytes_to_escaped_str(v), fg="blue"
                    )
                )
                for k, v in message.headers.fields
            )
            self.echo(headers, ident=4)
        if self.flow_detail >= 3:
                _, lines, error = contentviews.get_message_content_view(
                    self.default_contentview,
                    message
                )
                if error:
                    ctx.log.debug(error)

                styles = dict(
                    highlight=dict(bold=True),
                    offset=dict(fg="blue"),
                    header=dict(fg="green", bold=True),
                    text=dict(fg="green")
                )

                def colorful(line):
                    yield u"    "  # we can already indent here
                    for (style, text) in line:
                        yield click.style(text, **styles.get(style, {}))

                if self.flow_detail == 3:
                    lines_to_echo = itertools.islice(lines, 70)
                else:
                    lines_to_echo = lines

                content = u"\r\n".join(
                    u"".join(colorful(line)) for line in lines_to_echo
                )
                if content:
                    self.echo("")
                    self.echo(content)

                if next(lines, None):
                    self.echo("(cut off)", ident=4, dim=True)

        if self.flow_detail >= 2:
            self.echo("")
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:51,代码来源:dumper.py


示例3: freeze

 def freeze(self, settings):
     f = self.parsed.freeze(settings).spec()
     return self.__class__(
         base.TokValueLiteral(
             strutils.bytes_to_escaped_str(f.encode(), escape_single_quotes=True)
         )
     )
开发者ID:cortesi,项目名称:mitmproxy,代码行数:7,代码来源:message.py


示例4: _handle_pong_received

 def _handle_pong_received(self, event, source_conn, other_conn, is_server):
     self.log(
         "Pong Received from {}".format("server" if is_server else "client"),
         "info",
         [strutils.bytes_to_escaped_str(bytes(event.payload))]
     )
     return True
开发者ID:jbremer,项目名称:mitmproxy,代码行数:7,代码来源:websocket.py


示例5: __init__

 def __init__(self, data: strbytes) -> None:
     self.data = data
     if isinstance(data, bytes):
         escaped = strutils.bytes_to_escaped_str(data)
     else:
         escaped = data.encode()
     w = urwid.Text(escaped, wrap="any")
     super().__init__(w)
开发者ID:adolia,项目名称:mitmproxy,代码行数:8,代码来源:col.py


示例6: __init__

 def __init__(self, data: typing.Any) -> None:
     self.data = data
     if isinstance(data, bytes):
         data = strutils.bytes_to_escaped_str(data)
     if not isinstance(data, str):
         data = repr(data)
     w = urwid.Text(data, wrap="any")
     super().__init__(w)
开发者ID:cortesi,项目名称:mitmproxy,代码行数:8,代码来源:col_viewany.py


示例7: log

 def log(self, settings):
     """
         A dictionary that should be logged if this message is served.
     """
     ret = {}
     for i in self.logattrs:
         v = getattr(self, i)
         # Careful not to log any VALUE specs without sanitizing them first.
         # We truncate at 1k.
         if hasattr(v, "values"):
             v = [x[:LOG_TRUNCATE] for x in v.values(settings)]
             v = strutils.bytes_to_escaped_str(b"".join(v))
         elif hasattr(v, "__len__"):
             v = v[:LOG_TRUNCATE]
             v = strutils.bytes_to_escaped_str(v)
         ret[i] = v
     ret["spec"] = self.spec()
     return ret
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:18,代码来源:message.py


示例8: tcp_message

 def tcp_message(self, f):
     super().tcp_message(f)
     message = f.messages[-1]
     direction = "->" if message.from_client else "<-"
     signals.add_log("{client} {direction} tcp {direction} {server}".format(
         client=repr(f.client_conn.address),
         server=repr(f.server_conn.address),
         direction=direction,
     ), "info")
     signals.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
开发者ID:nickraptis,项目名称:mitmproxy,代码行数:10,代码来源:master.py


示例9: tcp_message

 def tcp_message(self, f):
     message = f.messages[-1]
     direction = "->" if message.from_client else "<-"
     ctx.log.info("{client_host}:{client_port} {direction} tcp {direction} {server_host}:{server_port}".format(
         client_host=f.client_conn.address[0],
         client_port=f.client_conn.address[1],
         server_host=f.server_conn.address[0],
         server_port=f.server_conn.address[1],
         direction=direction,
     ))
     ctx.log.debug(strutils.bytes_to_escaped_str(message.content))
开发者ID:cortesi,项目名称:mitmproxy,代码行数:11,代码来源:consoleaddons.py


示例10: _handle_ping_received

 def _handle_ping_received(self, event, source_conn, other_conn, is_server):
     # PING is automatically answered with a PONG by wsproto
     self.connections[other_conn].ping()
     other_conn.send(self.connections[other_conn].bytes_to_send())
     source_conn.send(self.connections[source_conn].bytes_to_send())
     self.log(
         "Ping Received from {}".format("server" if is_server else "client"),
         "info",
         [strutils.bytes_to_escaped_str(bytes(event.payload))]
     )
     return True
开发者ID:jbremer,项目名称:mitmproxy,代码行数:11,代码来源:websocket.py


示例11: __repr__

 def __repr__(self):
     if self.alpn_proto_negotiated:
         alpn = "[ALPN: {}] ".format(
             strutils.bytes_to_escaped_str(self.alpn_proto_negotiated)
         )
     else:
         alpn = ""
     return "<ClientConnection: {ssl}{alpn}{address}>".format(
         ssl="[ssl] " if self.ssl_established else "",
         alpn=alpn,
         address=repr(self.address)
     )
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:12,代码来源:connections.py


示例12: tcp_message

def tcp_message(flow: tcp.TCPFlow):
    message = flow.messages[-1]
    old_content = message.content
    message.content = old_content.replace(b"foo", b"bar")

    ctx.log.info(
        "[tcp_message{}] from {} to {}:\n{}".format(
            " (modified)" if message.content != old_content else "",
            "client" if message.from_client else "server",
            "server" if message.from_client else "client",
            strutils.bytes_to_escaped_str(message.content))
    )
开发者ID:cortesi,项目名称:mitmproxy,代码行数:12,代码来源:tcp_message.py


示例13: tcp_message

def tcp_message(tcp_msg):
    modified_msg = tcp_msg.message.replace("foo", "bar")

    is_modified = False if modified_msg == tcp_msg.message else True
    tcp_msg.message = modified_msg

    print(
        "[tcp_message{}] from {} {} to {} {}:\r\n{}".format(
            " (modified)" if is_modified else "",
            "client" if tcp_msg.sender == tcp_msg.client_conn else "server",
            tcp_msg.sender.address,
            "server" if tcp_msg.receiver == tcp_msg.server_conn else "client",
            tcp_msg.receiver.address, strutils.bytes_to_escaped_str(tcp_msg.message))
    )
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:14,代码来源:tcp_message.py


示例14: httpie_command

def httpie_command(f: flow.Flow) -> str:
    raise_if_missing_request(f)
    request = f.request.copy()  # type: ignore
    data = "http %s " % request.method
    request.decode(strict=False)
    data += "%s" % request.url
    for k, v in request.headers.items(multi=True):
        data += " '%s:%s'" % (k, v)
    if request.content:
        data += " <<< '%s'" % strutils.bytes_to_escaped_str(
            request.content,
            escape_single_quotes=True
        )
    return data
开发者ID:cortesi,项目名称:mitmproxy,代码行数:14,代码来源:export.py


示例15: curl_command

def curl_command(f: flow.Flow) -> str:
    raise_if_missing_request(f)
    data = "curl "
    request = f.request.copy()  # type: ignore
    request.decode(strict=False)
    for k, v in request.headers.items(multi=True):
        data += "-H '%s:%s' " % (k, v)
    if request.method != "GET":
        data += "-X %s " % request.method
    data += "'%s'" % request.url
    if request.content:
        data += " --data-binary '%s'" % strutils.bytes_to_escaped_str(
            request.content,
            escape_single_quotes=True
        )
    return data
开发者ID:cortesi,项目名称:mitmproxy,代码行数:16,代码来源:export.py


示例16: curl_command

def curl_command(f: flow.Flow) -> str:
    if not hasattr(f, "request"):
        raise exceptions.CommandError("Can't export flow with no request.")
    data = "curl "
    request = f.request.copy()  # type: ignore
    request.decode(strict=False)
    for k, v in request.headers.items(multi=True):
        data += "-H '%s:%s' " % (k, v)
    if request.method != "GET":
        data += "-X %s " % request.method
    data += "'%s'" % request.url
    if request.content:
        data += " --data-binary '%s'" % strutils.bytes_to_escaped_str(
            request.content,
            escape_single_quotes=True
        )
    return data
开发者ID:StevenVanAcker,项目名称:mitmproxy,代码行数:17,代码来源:export.py


示例17: __repr__

    def __repr__(self):
        if self.tls_established:
            tls = "[{}] ".format(self.tls_version)
        else:
            tls = ""

        if self.alpn_proto_negotiated:
            alpn = "[ALPN: {}] ".format(
                strutils.bytes_to_escaped_str(self.alpn_proto_negotiated)
            )
        else:
            alpn = ""

        return "<ClientConnection: {tls}{alpn}{address}>".format(
            tls=tls,
            alpn=alpn,
            address=human.format_address(self.address),
        )
开发者ID:cortesi,项目名称:mitmproxy,代码行数:18,代码来源:connections.py


示例18: __repr__

    def __repr__(self):
        if self.ssl_established:
            tls = "[{}] ".format(self.tls_version)
        else:
            tls = ""

        if self.alpn_proto_negotiated:
            alpn = "[ALPN: {}] ".format(
                strutils.bytes_to_escaped_str(self.alpn_proto_negotiated)
            )
        else:
            alpn = ""

        return "<ClientConnection: {tls}{alpn}{host}:{port}>".format(
            tls=tls,
            alpn=alpn,
            host=self.address[0],
            port=self.address[1],
        )
开发者ID:s4chin,项目名称:mitmproxy,代码行数:19,代码来源:connections.py


示例19: _handle_frame

    def _handle_frame(self, frame, source_conn, other_conn, is_server):
        sender = "server" if is_server else "client"
        self.log(
            "WebSockets Frame received from {}".format(sender),
            "debug",
            [repr(frame)]
        )

        if frame.header.opcode & 0x8 == 0:
            self.log(
                "{direction} websocket {direction} {server}".format(
                    server=repr(self.server_conn.address),
                    direction="<-" if is_server else "->",
                ),
                "info",
                strutils.bytes_to_escaped_str(frame.payload, keep_spacing=True).splitlines()
            )
            # forward the data frame to the other side
            other_conn.send(bytes(frame))
        elif frame.header.opcode in (websockets.OPCODE.PING, websockets.OPCODE.PONG):
            # just forward the ping/pong to the other side
            other_conn.send(bytes(frame))
        elif frame.header.opcode == websockets.OPCODE.CLOSE:
            code = '(status code missing)'
            msg = None
            reason = '(message missing)'
            if len(frame.payload) >= 2:
                code, = struct.unpack('!H', frame.payload[:2])
                msg = websockets.CLOSE_REASON.get_name(code, default='unknown status code')
            if len(frame.payload) > 2:
                reason = frame.payload[2:]
            self.log("WebSockets connection closed by {}: {} {}, {}".format(sender, code, msg, reason), "info")

            other_conn.send(bytes(frame))
            # close the connection
            return False
        else:
            self.log("Unknown WebSockets frame received from {}".format(sender), "info", [repr(frame)])
            # unknown frame - just forward it
            other_conn.send(bytes(frame))

        # continue the connection
        return True
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:43,代码来源:websockets.py


示例20: websocket_message

 def websocket_message(self, f):
     message = f.messages[-1]
     ctx.log.info(f.message_info(message))
     ctx.log.debug(message.content if isinstance(message.content, str) else strutils.bytes_to_escaped_str(message.content))
开发者ID:cortesi,项目名称:mitmproxy,代码行数:4,代码来源:consoleaddons.py



注:本文中的mitmproxy.utils.strutils.bytes_to_escaped_str函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shortcuts.render_to_response函数代码示例发布时间:2022-05-27
下一篇:
Python tutils.tresp函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap