# 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 FileParser(AbstractParser):
# 
#     """Specialized parser for generic report file(s).
# 
#     Define the special :func:`handle_file` function in order to process the generic report file.
# 
#     """
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*', first=True):
#         """Return a string of the content of the 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 or an error occurs when opening/reading.
#         :raises OSError: when an error occurs when opening/reading the report file.
# 
#         :return: data from the file.
#         :rtype: str
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % filename)
#         fullpath = fullpath[0]
#         data = ''
#         with open(fullpath, 'r') as f:
#             data = f.read()
#         return data


import re
from ptp.libptp import constants
from ptp.libptp.exceptions import NotSupportedVersionError
from ptp.libptp.parser import FileParser

:synopsis: Specialized :class:`ptp.libptp.parser.AbstractParser` classes for the tool Hoppy.

.. moduleauthor:: DoomTaper

"""




class HoppyParser(FileParser):
    """Hoppy specialized parser."""

    __tool__ = 'hoppy'
    __version__ = r'1\.[0-9]+(\.[0-9]+)?'

    _re_version = re.compile(r"\D{3} \S+ (\d\.\d+\.\d+) \S")
    _re_transaction = re.compile(r"(?<=We Sent:)\n.*?(\S+ /.*?)\n(?=\n\t\D{3} Parsed Response:)", re.S)
    _re_request = re.compile(r"(\S+ /.*?)\n(?=Server)", re.S)
    _re_response = re.compile(r"(?<=Responded:\n\n)(.*)", re.S)
    _re_response_status_code = re.compile(r"(?<=HTTP/\w.\w )(.*)")
    _re_response_parse = re.compile(r"(?P<headers>HTTP.*?)\n(?=\r\n)(?P<body>.*)", re.S)

    def __init__(self, pathname, filename='*.spider', **kwargs):
        """Initialize HoppyParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.

        """

# 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 FileParser(AbstractParser):
# 
#     """Specialized parser for generic report file(s).
# 
#     Define the special :func:`handle_file` function in order to process the generic report file.
# 
#     """
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*', first=True):
#         """Return a string of the content of the 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 or an error occurs when opening/reading.
#         :raises OSError: when an error occurs when opening/reading the report file.
# 
#         :return: data from the file.
#         :rtype: str
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % filename)
#         fullpath = fullpath[0]
#         data = ''
#         with open(fullpath, 'r') as f:
#             data = f.read()
#         return data


# Path: ptp/tools/hoppy/parser.py
import re
from ptp.libptp import constants
from ptp.libptp.exceptions import NotSupportedVersionError
from ptp.libptp.parser import FileParser


:synopsis: Specialized :class:`ptp.libptp.parser.AbstractParser` classes for the tool Hoppy.

.. moduleauthor:: DoomTaper

"""




class HoppyParser(FileParser):
    """Hoppy specialized parser."""

    __tool__ = 'hoppy'
    __version__ = r'1\.[0-9]+(\.[0-9]+)?'

    _re_version = re.compile(r"\D{3} \S+ (\d\.\d+\.\d+) \S")
    _re_transaction = re.compile(r"(?<=We Sent:)\n.*?(\S+ /.*?)\n(?=\n\t\D{3} Parsed Response:)", re.S)
    _re_request = re.compile(r"(\S+ /.*?)\n(?=Server)", re.S)
    _re_response = re.compile(r"(?<=Responded:\n\n)(.*)", re.S)
    _re_response_status_code = re.compile(r"(?<=HTTP/\w.\w )(.*)")
    _re_response_parse = re.compile(r"(?P<headers>HTTP.*?)\n(?=\r\n)(?P<body>.*)", re.S)

    def __init__(self, pathname, filename='*.spider', **kwargs):
        """Initialize HoppyParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.

        """

        FileParser.__init__(self, pathname, filename, **kwargs)