utils.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:BPRC 作者: bradwood 项目源码 文件源码
def printbody(step,*,file, id,http_part, colourful):
    if http_part == 'response':
        try:
            printoutput = json.dumps(step.response.body,indent=4, sort_keys=True)
            isJsonPayload = True
        except JSONDecodeError as e: # if it doesn't parse as JSON, set it as raw output
            printoutput = step.response.body
            colourful = False # and if it is not JSON, turn off colourful output.
            isJsonPayload = False
    else: ## http_part == request:
        try:
            printoutput = json.dumps(step.request.body,indent=4, sort_keys=True)
            isJsonPayload = True
        except JSONDecodeError as e: # if it doesn't parse as JSON, set it as raw output
            printoutput = step.request.body
            colourful = False # and if it is not JSON, turn off colourful output.
            isJsonPayload = False


    if colourful and isJsonPayload:
        print(highlight(printoutput,lexers.JsonLexer(),formatters.TerminalFormatter()),file=file)
    else: #not JSON payload, and therefore, not colourful either
        print(printoutput,file=file)



# define regex patterns.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号