Welcome to bop’s documentation!¶
bop - parses results from Boa’s less than helpful text output
-
bop.
parse
(lines[, weighted=True])¶ Given an iterator that yields lines (like a file object), returns the parsed results. The results may be returned as a list if there are no discernible string keys; results are returned as a (possibly nested) dictionary otherwise.
If
weighted
isTrue
, indicates that the values are affixed with a comma-separate weight, like so:licenses[] = GNU General Public License version 2.0 (GPLv2), 78
You must explicitly set
weighted=True
to parse this kind of data. Weighted data is always returned as a dictionary, with the “identifier” as the keys, and the weight as the values.Parameters: Returns: parsed Boa output
Return type:
-
bop.
parseiter
(lines[, keys=None[, weight=None[, values=None[, on_error='raise']]]])¶ Given an line iterator (like a file object), yields Result object per each parsed result.
Parameters: - lines – An iterator that yields lines as strings, such as
a
file
object. - schema (tuple) – If provided, specifies the types of each index,
respectively. Each “type” can actually be any
callable. Typically, you would want to provide a
tuple of
(str,)
to generate several string keys. - weight (type) – If provided, it means that each value has a
weight. Typically, this weight is often provided
as an integer or floating point number, so
weight
should be provided asint
orfloat
, respectively. This can actually be any callable – not just a type. - values (type) – If provided, specifies the type of the values. Assumed to be strings by default. Actually, this can be any callable.
- on_error (string) – If provided, specifies what to do when parsing
encounters an error of some sort.
'raise'
(the default) throws the exception, as is.'ignore'
silently discards the value.'quarantine'
returns a tuple of the exception and the offending line(s) as a string.
Returns: an iterator that yields one result per iteration
- lines – An iterator that yields lines as strings, such as
a