Basic Parsers¶
synopsis: | Define the basic parser classes that will parse the data from the report file. |
---|
AbstractParser¶
-
class
ptp.libptp.parser.
AbstractParser
(pathname='./', filename='*', light=False, first=True)[source]¶ Abstract representation of a parser.
Note
This class will be extended for each pentesting tool. That way, each tool will add its own parsing specificities.
-
__init__
(pathname='./', filename='*', light=False, first=True)[source]¶ Initialize
AbstractParser
.Parameters:
-
static
_recursive_find
(pathname='./', file_regex='*', first=True)[source]¶ Retrieve the full path to the report file(s).
Parameters: Returns: A list of path to the matched files that have been found.
Return type: list
Note
The search occurs starting from pathname as the root directory.
-
classmethod
check_version
(metadata, key='version')[source]¶ Checks the version in the metadata against the supported one(s).
Parameters: Returns: True if it can parse the report, False otherwise.
Return type:
-
classmethod
handle_file
(pathname='./', filename='*', first=True)[source]¶ Process the report file.
Parameters: Raises: NotImplementedError
because this is an abstract method.
-
classmethod
is_mine
()[source]¶ Check if it can handle the report file.
Raises: NotImplementedError
because this is an abstract method.
-
parse_metadata
()[source]¶ Parse the metadata of a report.
Raises: NotImplementedError because this is an abstract method.
-
parse_report
()[source]¶ Parse the results of a report file.
Raises: NotImplementedError because this is an abstract method.
-
vulns
= None¶ list
– List of dict of the results found in the report.
-
XMLParser¶
-
class
ptp.libptp.parser.
XMLParser
(pathname='./', filename='*.xml', **kwargs)[source]¶ Specialized parser for XML files.
Define the special
handle_file()
function in order to process the XML report file.-
classmethod
handle_file
(pathname='./', filename='*.xml', first=True)[source]¶ Return the root node of the XML file.
Parameters: Raises: - IOError – when the report file cannot be found.
- TypeError – when the report file has not the right extension.
- lxml.etree.XMLSyntaxError – when Lxml cannot parse the XML file.
Returns: handle on the root node element from the XML file.
Return type: lxml.etree._Element
-
classmethod
FileParser¶
-
class
ptp.libptp.parser.
FileParser
(pathname='./', filename='*', light=False, first=True)[source]¶ Specialized parser for generic report file(s).
Define the special
handle_file()
function in order to process the generic report file.-
classmethod
handle_file
(pathname='./', filename='*', first=True)[source]¶ Return a string of the content of the file.
Parameters: Raises: - IOError – when the report file cannot be found or an error occurs when opening/reading.
- OSError – when an error occurs when opening/reading the report file.
Returns: data from the file.
Return type:
-
classmethod
LineParser¶
-
class
ptp.libptp.parser.
LineParser
(pathname='./', filename='*', light=False, first=True)[source]¶ Specialized parser for generic report files.
Define the special
handle_file()
function in order to process the generic report file.Note
Contrary to
FileParser
, this class reads the file line by line and return alist
, instead of astr
.-
classmethod
handle_file
(pathname='./', filename='*', skip_empty=True, first=True)[source]¶ Return a list of the lines of the file.
Parameters: Raises: - IOError – when the report file cannot be found or an error occurs when opening/reading.
- OSError – when an error occurs when opening/reading the report file.
Returns: all the data from the file, line by line.
Return type: list
-
classmethod