Utils¶
- class TypesDict¶
For dot.notation access to dictionary attributes
- check_command_status(xml)¶
Check gmp response
Look into the gmp response and check for the status in the root element
- Parameters:
xml (str) – XML-Source
- Returns:
True if valid, otherwise False
- Return type:
bool
- deprecated(_func_or_cls=None, *, since=None, reason=None)¶
A decorator to mark functions, classes and methods as deprecated
- Parameters:
since (str | None) – An optional version since the referenced item is deprecated.
reason (str | None) – An optional reason why the references item is deprecated.
Examples
from gvm.utils import deprecated @deprecated def my_function(*args, **kwargs): ... @deprecated("The function is obsolete. Please use my_func instead.") def my_function(*args, **kwargs): ... @deprecated( since="1.2.3", reason="The function is obsolete. Please use my_func instead." ) def my_function(*args, **kwargs): ... @deprecated(reason="The class will be removed in version 3.4.5") class Foo: ... class Foo: @deprecated(since="2.3.4") def bar(self, *args, **kwargs): ...
- to_dotted_types_dict(types)¶
Create a dictionary accessible via dot notation
XML¶
- Element¶
alias of
_Element
- class XmlCommand¶
Class to create XML commands
- __init__(name)¶
Create a new XML command
- Parameters:
name (str) – The name of the root element of the command.
- add_filter(filter_string, filter_id)¶
Add a filter to the command.
- Parameters:
filter_string (str | None) – The filter string to be added.
filter_id (str | UUID | None) – The filter ID to be added.
- class XmlCommandElement¶
Base class for XML commands
It’s used to create XML command requests for the XML based protocols.
- __init__(element)¶
- append_xml_str(xml_text)¶
Append a xml element in string format.
- set_attribute(name, value)¶
Set an attribute on the element.
- Parameters:
name (str) – Name of the attribute
value (str) – Value of the attribute
- set_attributes(attrs)¶
Set several attributes at once.
- Parameters:
attrs (dict[str, str]) – Attributes to be set on the element
- set_text(text)¶
Set the text of the element.
- Parameters:
text (str | None) – Text to be set on the element. None to remove the text.
- to_bytes()¶
Convert the XML element to a bytes object
- to_string(*, encoding='utf-8')¶
Convert the XML element to a string
- Parameters:
encoding (str) – The encoding to use for the string. Default is ‘utf-8’.
- parse_xml(xml)¶
Parse an XML string and return the root element
Raises an XmlError if the XML is invalid.
- pretty_print(xml, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)¶
Prints beautiful XML-Code
This function gets a string containing the xml, an object of List[lxml.etree.Element] or directly a lxml element.
Print it with good readable format.
- Parameters:
xml (str, List[lxml.etree.Element] or lxml.etree.Element) – xml as string, List[lxml.etree.Element] or directly a lxml element.
file (TextIO | IOBase) – A IOBase type. Can be a File, StringIO, …