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.
评论列表
文章目录