mythx_cli.formatter package

mythx_cli.formatter.base

This module contains the base formatter interface.

class mythx_cli.formatter.base.BaseFormatter[source]

Bases: abc.ABC

The base formatter interface for printing various response types.

static format_analysis_list(obj: mythx_models.response.analysis_list.AnalysisListResponse) → str[source]

Format an analysis list response.

static format_analysis_status(resp: mythx_models.response.analysis_status.AnalysisStatusResponse) → str[source]

Format an analysis status response.

static format_detected_issues(issues_list: List[Tuple[mythx_models.response.detected_issues.DetectedIssuesResponse, Optional[mythx_models.response.analysis_input.AnalysisInputResponse]]]) → str[source]

Format an issue report response.

static format_version(obj: mythx_models.response.version.VersionResponse) → str[source]

Format a version response.

report_requires_input = False

mythx_cli.formatter.json

This module contains the compressed and pretty-printing JSON formatters.

class mythx_cli.formatter.json.JSONFormatter[source]

Bases: mythx_cli.formatter.base.BaseFormatter

The JSON formatter.

It returns string-encoded JSON objects and does not require the analysis input to generate payloads.

static format_analysis_list(resp: mythx_models.response.analysis_list.AnalysisListResponse) → str[source]

Format an analysis list response as compressed JSON.

static format_analysis_status(resp: mythx_models.response.analysis_status.AnalysisStatusResponse) → str[source]

Format an analysis status response as compressed JSON.

static format_detected_issues(issues_list: List[Tuple[mythx_models.response.detected_issues.DetectedIssuesResponse, Optional[mythx_models.response.analysis_input.AnalysisInputResponse]]]) → str[source]

Format an issue report response as compressed JSON.

static format_group_list(resp: mythx_models.response.group_list.GroupListResponse) → str[source]

Format a group list response as compressed JSON.

static format_group_status(resp: mythx_models.response.group_status.GroupStatusResponse) → str[source]

Format a group status response as compressed JSON.

static format_version(resp: mythx_models.response.version.VersionResponse) → str[source]

Format a version response as compressed JSON.

report_requires_input = False
class mythx_cli.formatter.json.PrettyJSONFormatter[source]

Bases: mythx_cli.formatter.base.BaseFormatter

The pretty-printing JSON formatter.

It works exactly as the JSON formatter, with the difference that the string-encoded JSON object is indented with two spaces for each level, and the keys are sorted in alphabetical order.

static format_analysis_list(obj: mythx_models.response.analysis_list.AnalysisListResponse) → str[source]

Format an analysis list response as pretty-printed JSON.

static format_analysis_status(obj: mythx_models.response.analysis_status.AnalysisStatusResponse) → str[source]

Format an analysis status response as pretty-printed JSON.

static format_detected_issues(issues_list: List[Tuple[mythx_models.response.detected_issues.DetectedIssuesResponse, Optional[mythx_models.response.analysis_input.AnalysisInputResponse]]]) → str[source]

Format an issue report response as pretty-printed JSON.

static format_group_list(resp: mythx_models.response.group_list.GroupListResponse) → str[source]

Format a group list response as pretty-printed JSON.

static format_group_status(resp: mythx_models.response.group_status.GroupStatusResponse) → str[source]

Format a group status response as pretty-printed JSON.

static format_version(obj: mythx_models.response.version.VersionResponse) → str[source]

Format a version response as pretty-printed JSON.

report_requires_input = False

mythx_cli.formatter.simple_stdout

This module contains a simple text formatter class printing a subset of the response data.

class mythx_cli.formatter.simple_stdout.SimpleFormatter[source]

Bases: mythx_cli.formatter.base.BaseFormatter

The simple text formatter.

This formatter generates simplified text output. It also displays the source locations of issues by line in the Solidity source code if given. Therefore, this formatter requires the analysis input to be given.

static format_analysis_list(resp: mythx_models.response.analysis_list.AnalysisListResponse) → str[source]

Format an analysis list response to a simple text representation.

static format_analysis_status(resp: mythx_models.response.analysis_status.AnalysisStatusResponse) → str[source]

Format an analysis status response to a simple text representation.

static format_detected_issues(issues_list: List[Tuple[mythx_models.response.detected_issues.DetectedIssuesResponse, Optional[mythx_models.response.analysis_input.AnalysisInputResponse]]]) → str[source]

Format an issue report to a simple text representation.

static format_group_list(resp: mythx_models.response.group_list.GroupListResponse) → str[source]

Format an analysis group response to a simple text representation.

static format_group_status(resp: mythx_models.response.group_status.GroupStatusResponse) → str[source]

Format a group status response to a simple text representation.

static format_version(resp: mythx_models.response.version.VersionResponse) → str[source]

Format a version response to a simple text representation.

report_requires_input = True

mythx_cli.formatter.tabular

This module contains a tabular data formatter class printing a subset of the response data.

class mythx_cli.formatter.tabular.TabularFormatter[source]

Bases: mythx_cli.formatter.base.BaseFormatter

The tabular formatter.

This formatter displays an ASCII table. It is enabled by default and requires the analysis input data to display each issue’s line number in the source file. It might break on very large field sizes as cell-internal line breaks are not supported by the tabulate library yet.

static format_analysis_list(resp: mythx_models.response.analysis_list.AnalysisListResponse) → str[source]

Format an analysis list response to a tabular representation.

static format_analysis_status(resp: mythx_models.response.analysis_status.AnalysisStatusResponse) → str[source]

Format an analysis status response to a tabular representation.

static format_detected_issues(issues_list: List[Tuple[mythx_models.response.detected_issues.DetectedIssuesResponse, Optional[mythx_models.response.analysis_input.AnalysisInputResponse]]]) → str[source]

Format an issue report to a tabular representation.

static format_group_list(resp: mythx_models.response.group_list.GroupListResponse) → str[source]

Format an analysis group response to a tabular representation.

static format_group_status(resp: mythx_models.response.group_status.GroupStatusResponse) → str[source]

Format a group status response to a tabular representation.

static format_version(resp: mythx_models.response.version.VersionResponse) → str[source]

Format a version response to a tabular representation.

report_requires_input = True

mythx_cli.formatter.util

Utility functions for handling API requests and responses.

mythx_cli.formatter.util.filter_report(resp: mythx_models.response.detected_issues.DetectedIssuesResponse, min_severity: str = None, swc_blacklist: Union[str, List[str]] = None, swc_whitelist: Union[str, List[str]] = None) → mythx_models.response.detected_issues.DetectedIssuesResponse[source]

Filter issues based on an SWC blacklist and minimum severity.

This will remove issues of a specific SWC ID or with a too low severity from the issue reports of the passed DetectedIssuesResponse object. The SWC blacklist can be a list of strings in the format “SWC-000” or a comma-separated string. “SWC” is case-insensitive and normalized. The SWC whitelist works in a similar way, just including selected SWCs into the resulting response object.

Parameters:
  • resp – The issue report of an analysis job
  • min_severity – Ignore SWC IDs below the designated level
  • swc_blacklist – A comma-separated list of SWC IDs to ignore
  • swc_whitelist – A comma-separated list of SWC IDs to include
Returns:

The filtered issue report

Generate a MythX dashboard link for an analysis job.

This method will generate a link to an analysis job on the official MythX dashboard production setup. Custom deployment locations are currently not supported by this function (but available at mythx.io). :param uuid: The analysis job’s UUID :return: The analysis job’s dashboard link

mythx_cli.formatter.util.get_source_location_by_offset(source: str, offset: int) → int[source]

Retrieve the Solidity source code location based on the source map offset.

Parameters:
  • source – The Solidity source to analyze
  • offset – The source map’s offset
Returns:

The offset’s source line number equivalent

mythx_cli.formatter.util.normalize_swc_list(swc_list: Union[str, List[str], None]) → List[str][source]

Normalize a list of SWC IDs.

This method normalizes a list of SWC ID definitions, making SWC-101, swc-101, and 101 equivalent. :param swc_list: The list of SWC IDs as strings :return: The normalized SWC ID list as SWC-XXX

mythx_cli.formatter.util.set_ci_failure() → None[source]

Based on the current context, set the return code to 1.

This method sets the return code to 1. It is called by the respective subcommands (analyze and report) in case a severe issue has been found (as specified by the user) if the CI flag is passed. This will make the MythX CLI fail when running on a CI server. If no context is available, this function assumes that it is running outside a CLI scenario (e.g. a test setup) and will not do anything.