solitude.common module¶
-
class
solitude.common.
FileMessage
¶ Bases:
tuple
message (error, warning) related to a text file
-
column
¶ column number, optional
-
line
¶ line number, optional
-
message
¶ the message string
-
type
¶ a string indicating the message type
-
unitname
¶ source unit name or file name
-
-
solitude.common.
file_message_format
(m: solitude.common.structures.FileMessage)[source]¶ Format a FileMessage object to string
-
class
solitude.common.
TransactionInfo
¶ Bases:
tuple
Transaction information
-
address
¶ contract instance address
-
contractname
¶ contract name
-
fnargs
¶ function arguments as tuple
-
function
¶ function name
-
receipt
¶ full web3 receipt
-
txargs
¶ transaction arguments as dictionary (‘gas’, ‘gasprice’, ‘value’)
-
txhash
¶ Alias for field number 6
-
unitname
¶ source unit name
-
-
solitude.common.
hex_repr
(b: bytes, pad: Optional[int] = None, prefix=True)[source]¶ Get hex string representation of a byte array
Parameters: - b – byte array
- pad – pad to fixed number of characters
- prefix – prefix with ‘0x’
-
solitude.common.
get_resource_path
(resource_name: str)[source]¶ Get location of a solitude resource file in the filesystem
Parameters: resource_name – name of the resource Returns: resource file path
-
solitude.common.
get_global_config
()[source]¶ Get the solitude global configuration, containing global settings of the solitude framework.
Returns: the solitude global config
-
solitude.common.
update_global_config
(config: dict)[source]¶ Update the solitude global configuration from a dictionary
Parameters: config – dictionary containing the values to replace
-
solitude.common.
copy_from_url
(url: str, destination, decode=False)[source]¶ Copy file from URL to file-like
Parameters: - url – source URL (see
open_url()
) - destination – destination writable file-like
- decode – interpret the stream as utf-8 text and convert it to string
- url – source URL (see
-
solitude.common.
read_from_url
(url: str, decode=False)[source]¶ Read file from URL to a byte array or string
Parameters: - url – source URL (see
open_url()
) - decode – interpret the stream as utf-8 text and convert it to string
Returns: a byte array (bytes) if decode is False, otherwise a string (str)
- url – source URL (see
-
solitude.common.
open_url
(url: str, decode=False)[source]¶ Open URL and return readable file-like
The URL can have one of the following schemas
- https://{hostname}/{path} - HTTPS url
- http://{hostname}/{path} - HTTP url
- resource://{name} - solitude resource, by name
- file://{path} file on the filesystem, by path
Parameters: - url – source URL
- decode – interpret the stream as utf-8 text and convert it to string
Returns: a file-like object, binary if decode is False, otherwise text
-
solitude.common.
read_config_file
(url: str) → dict[source]¶ Read a solitude configuration from YAML or JSON.
Parameters: url – URL or path of configuration; if url ends with ‘.yaml’, the configuration file is interpreted as YAML, otherwise it is assumed to be JSON. Returns: configuration dictionary
-
solitude.common.
read_yaml_or_json
(url: str) → dict[source]¶ Read a YAML or JSON document.
Parameters: url – URL or path; if url ends with ‘.yaml’, the document is interpreted as YAML, otherwise it is assumed to be JSON. Returns: a dictionary with the document contents.
-
solitude.common.
make_default_config
() → dict[source]¶ Create a default solitude configuration.
Returns: a configuration dictionary
-
class
solitude.common.
ContractObjectList
[source]¶ Bases:
object
A collection of compiled contracts
-
add_contract
(unitname: str, contractname: str, contract: dict)[source]¶ Add a contract, uniquely identified by (unitname, contractname).
Parameters: - unitname – source unit containing the contract
- contractname – name of the contract
- contract – contract data dictionary, as produced by the compiler module
-
add_directory
(path: str) → None[source]¶ Add all contracts from a directory.
Parameters: path – path of the directory containing the contracts data.
-
contracts
¶ All contracts, as a dictionary of (unitname, contractname) -> data
-
find
(suffix: Optional[str], contractname: str) → List[Tuple[str, str]][source]¶ Find contracts by unitname suffix and full contractname.
Example: (“erc20/ERC20.sol”, “ERC20”) matches (“/home/user/contracts/erc20/ERC20.sol”, “ERC20”).
Parameters: - suffix – suffix to match the contract source unit name, or None; if it is None, any unit name is matched.
- contractname – full name of the contract
-
save_directory
(path: str) → None[source]¶ Save all contracts to a directory.
Parameters: path – path of destination directory; the directory must exist.
-
select
(selector: str) → dict[source]¶ Find a single contract matching the contract selector string.
The selector string is a string in either of the following forms:
- “{suffix}:{contractname}”: source unit name suffix and contract name,
- separated by ‘:’. Example: “erc20/ERC20.sol:ERC20” matches contract named “ERC20” in source unit “/home/user/contracts/erc20/ERC20.sol”.
- “{contractname}”: only the contract name. Example: “ERC20” matches
- contract named “ERC20”.
If the selector matches multiple contract, this function will raise an exception of type ValueError.
Parameters: selector – contract selector
-
-
class
solitude.common.
ContractSourceList
[source]¶ Bases:
object
A collection of contract sources
-
add_directory
(path: str, ext_filter: Optional[List[str]] = ['.sol']) → None[source]¶ Add all sources from a directory.
Parameters: - path – directory path
- ext_filter – list of allowed extensions for the source file names, including the ‘.’ character (e.g. [“.sol”]), or None for any extension
-
add_files
(sources: List[str]) → None[source]¶ Add list of files to the list of sources.
Parameters: sources – list of file paths
-
add_string
(unitname: str, source: str) → None[source]¶ Add a source string to the list of sources
Parameters: - unitname – a name for the provided source unit
- source – source code text
-
file_sources
¶ All added file sources as list of paths
-
text_sources
¶ All added source strings as dictionary of unitname -> source.
-
-
solitude.common.
path_to_unitname
(path: str) → str[source]¶ Create a source unit name from a path
Parameters: path – source file path Returns: the corresponding normalized source unit name
-
class
solitude.common.
Dump
(filename: str = None, fileobj=None, prefix: str = None)[source]¶ Bases:
object
-
FLUSH
= 1000¶
-