# Path: ptp/libptp/constants.py
# UNKNOWN = 0
# INFO = 1
# LOW = 2
# MEDIUM = 3
# HIGH = 4
# RANKING_SCALE = {HIGH: HIGH, MEDIUM: MEDIUM, LOW: LOW, INFO: INFO, UNKNOWN: UNKNOWN}
# 
# Path: ptp/libptp/exceptions.py
# class NotSupportedVersionError(PTPError):
#     """:mod:`ptp` error when the version of the tool is not supported."""
#     pass
# 
# Path: ptp/libptp/parser.py
# class XMLParser(AbstractParser):
# 
#     """Specialized parser for XML files.
# 
#     Define the special :func:`handle_file` function in order to process the XML report file.
# 
#     """
# 
#     #: str -- XMLParser only supports XML files.
#     __format__ = 'xml'
# 
#     def __init__(self, pathname='./', filename='*.xml', **kwargs):
#         """Initialize :class:`XMLParser`."""
#         AbstractParser.__init__(self, pathname, filename, **kwargs)
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*.xml', first=True):
#         """Return the root node of the XML file.
# 
#         :param str pathname: Path to the report directory.
#         :param str filename: Regex matching the report file.
#         :param bool first: Stop the search as soon as a file has been matched.
# 
#         :raises IOError: when the report file cannot be found.
#         :raises TypeError: when the report file has not the right extension.
#         :raises lxml.etree.XMLSyntaxError: when Lxml cannot parse the XML file.
# 
#         :return: handle on the root node element from the XML file.
#         :rtype: :class:`lxml.etree._Element`
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % os.path.join(pathname, filename))
#         fullpath = fullpath[0]
#         if not fullpath.endswith(cls.__format__):
#             raise TypeError("This parser only supports '%s' files" % cls.__format__)
#         return etree.parse(fullpath).getroot()
# 
# class JSONParser(AbstractParser):
# 
#     """Specialized parser for JSON files.
# 
#     Define the special :func:`handle_file` function in order to process the JSON report file.
# 
#     """
# 
#     #: str -- JSONParser only supports json files.
#     __format__ = 'json'
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*.json', first=True):
#         """Return the dict of the JSON file.
# 
#         :param str pathname: Path to the report directory.
#         :param str filename: Regex matching the report file.
#         :param bool first: Stop the search as soon as a file has been matched.
# 
#         :raises IOError: when the report file cannot be found.
#         :raises TypeError: when the report file has not the right extension.
#         :raises ValueError: when json cannot parse the JSON file.
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % filename)
#         fullpath = fullpath[0]
#         if not fullpath.endswith(cls.__format__):
#             raise TypeError("This parser only supports '%s' files" % cls.__format__)
#         with open(fullpath, 'r') as data:
#             return json.load(data)


import re
from lxml.etree import XMLSyntaxError
from ptp.libptp import constants
from ptp.libptp.exceptions import NotSupportedVersionError
from ptp.libptp.parser import XMLParser, JSONParser
        :return: `True` if it supports the report, `False` otherwise.
        :rtype: :class:`bool`

        """
        try:
            stream = cls.handle_file(pathname, filename, first=first)
        except (TypeError, ValueError):
            return False
        if 'version' in stream:
            version = stream['version']
        else:
            return False
        if not re.findall(cls.__version__, version, re.IGNORECASE):
            return False
        return True

    def parse_metadata(self):
        """Parse the metadata of the report.

        :raises: :class:`NotSupportedVersionError` -- if it does not support the version of this report.
        :return: The metadata of the report.
        :rtype: dict

        """
        # Find the version of Arachni.
        version = self.stream['version']
        # Reconstruct the metadata
        # TODO: Retrieve the other metadata likes the date, etc.
        self.metadata = {'version': version}
        if not self.check_version(self.metadata):

# Path: ptp/libptp/constants.py
# UNKNOWN = 0
# INFO = 1
# LOW = 2
# MEDIUM = 3
# HIGH = 4
# RANKING_SCALE = {HIGH: HIGH, MEDIUM: MEDIUM, LOW: LOW, INFO: INFO, UNKNOWN: UNKNOWN}
# 
# Path: ptp/libptp/exceptions.py
# class NotSupportedVersionError(PTPError):
#     """:mod:`ptp` error when the version of the tool is not supported."""
#     pass
# 
# Path: ptp/libptp/parser.py
# class XMLParser(AbstractParser):
# 
#     """Specialized parser for XML files.
# 
#     Define the special :func:`handle_file` function in order to process the XML report file.
# 
#     """
# 
#     #: str -- XMLParser only supports XML files.
#     __format__ = 'xml'
# 
#     def __init__(self, pathname='./', filename='*.xml', **kwargs):
#         """Initialize :class:`XMLParser`."""
#         AbstractParser.__init__(self, pathname, filename, **kwargs)
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*.xml', first=True):
#         """Return the root node of the XML file.
# 
#         :param str pathname: Path to the report directory.
#         :param str filename: Regex matching the report file.
#         :param bool first: Stop the search as soon as a file has been matched.
# 
#         :raises IOError: when the report file cannot be found.
#         :raises TypeError: when the report file has not the right extension.
#         :raises lxml.etree.XMLSyntaxError: when Lxml cannot parse the XML file.
# 
#         :return: handle on the root node element from the XML file.
#         :rtype: :class:`lxml.etree._Element`
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % os.path.join(pathname, filename))
#         fullpath = fullpath[0]
#         if not fullpath.endswith(cls.__format__):
#             raise TypeError("This parser only supports '%s' files" % cls.__format__)
#         return etree.parse(fullpath).getroot()
# 
# class JSONParser(AbstractParser):
# 
#     """Specialized parser for JSON files.
# 
#     Define the special :func:`handle_file` function in order to process the JSON report file.
# 
#     """
# 
#     #: str -- JSONParser only supports json files.
#     __format__ = 'json'
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*.json', first=True):
#         """Return the dict of the JSON file.
# 
#         :param str pathname: Path to the report directory.
#         :param str filename: Regex matching the report file.
#         :param bool first: Stop the search as soon as a file has been matched.
# 
#         :raises IOError: when the report file cannot be found.
#         :raises TypeError: when the report file has not the right extension.
#         :raises ValueError: when json cannot parse the JSON file.
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % filename)
#         fullpath = fullpath[0]
#         if not fullpath.endswith(cls.__format__):
#             raise TypeError("This parser only supports '%s' files" % cls.__format__)
#         with open(fullpath, 'r') as data:
#             return json.load(data)


# Path: ptp/tools/arachni/parser.py
import re
from lxml.etree import XMLSyntaxError
from ptp.libptp import constants
from ptp.libptp.exceptions import NotSupportedVersionError
from ptp.libptp.parser import XMLParser, JSONParser

        :return: `True` if it supports the report, `False` otherwise.
        :rtype: :class:`bool`

        """
        try:
            stream = cls.handle_file(pathname, filename, first=first)
        except (TypeError, ValueError):
            return False
        if 'version' in stream:
            version = stream['version']
        else:
            return False
        if not re.findall(cls.__version__, version, re.IGNORECASE):
            return False
        return True

    def parse_metadata(self):
        """Parse the metadata of the report.

        :raises: :class:`NotSupportedVersionError` -- if it does not support the version of this report.
        :return: The metadata of the report.
        :rtype: dict

        """
        # Find the version of Arachni.
        version = self.stream['version']
        # Reconstruct the metadata
        # TODO: Retrieve the other metadata likes the date, etc.
        self.metadata = {'version': version}
        if not self.check_version(self.metadata):

            raise NotSupportedVersionError('PTP does NOT support this version of Arachni.')