"""

    The Report class will be the summarize of the complete report provided by
    pentesting tools.

"""


from libptp import constants


class AbstractReport(object):
    """Abstract representation of a report provided by a pentesting tool.

        + vulns: List of Info instances

    This class will be extended for each pentesting tool. That way, each tool
    will add its own parser.

    """

    RANKING_SCALE = constants.RANKING_SCALE

    def __init__(self, vulns=None):
        """Self-explanatory."""
        self.ranking_scale = self.RANKING_SCALE
        self.vulns = vulns

    def _lowest_ranking(self):
        """From the ranking scale, retrieve the lowest ranking id possible."""
        return min([value for value in self.ranking_scale.values()])

    def _highest_ranking(self):
        """From the ranking scale, retrieve the lowest ranking id possible."""
        return max([value for value in self.ranking_scale.values()])

    def get_highest_ranking(self, path_to_report=None):
        """Return the highest ranking of the report."""
        # Be sure that the parsing already happened.
        if self.vulns is None:
            if path_to_report is None:
                raise ValueError('A path to the report SHOULD be specified.')
            self.parser(path_to_report)
        highest_possible_ranking = self._highest_ranking()
        # Default highest ranking set to the lowest possible value.
        highest_ranking = self._lowest_ranking()
        for vuln in self.vulns:
            if self.ranking_scale[vuln.ranking] < self.ranking_scale[highest_ranking]:
                highest_ranking = vuln.ranking
            # If the current highest_ranking is already the highest possible
            # one, we can stop the loop.
            if self.ranking_scale[highest_ranking] == highest_possible_ranking:
                break
        return highest_ranking

    def from_file(self, pathname):
        """Read the content of a report from its file and parse it."""
        with open(pathname, 'r') as f:
            raw_data = f.read()
        self.raw_data = raw_data
        self.parser(self.raw_data)

    def from_stream(self, data):
        """Read the content of a report for its data and parse it."""
        self.raw_data = data
        self.parser(self.raw_data)

    def parser(self, data):
        """Abstract parser that will parse the report of a tool."""
        raise NotImplementedError('The parser MUST be define for each tool.')

@@ -120,16 +120,9 @@
 bptp
- import 
+.
 cons
@@ -126,16 +126,37 @@
 onstants
+ import RANKING_SCALE
 %0A%0A%0Aclass
@@ -417,53 +417,8 @@
 %22%22%0A%0A
-    RANKING_SCALE = constants.RANKING_SCALE%0A%0A
     
@@ -485,56 +485,8 @@
 %22%22%22%0A
-        self.ranking_scale = self.RANKING_SCALE%0A
     
@@ -658,34 +658,29 @@
 alue in 
-self.ranking_scale
+RANKING_SCALE
 .values(
@@ -834,34 +834,29 @@
 alue in 
-self.ranking_scale
+RANKING_SCALE
 .values(
@@ -1440,61 +1440,51 @@
  if 
-self.ranking_scale%5Bvuln.ranking%5D %3C self.ranking_scale
+RANKING_SCALE%5Bvuln.ranking%5D %3C RANKING_SCALE
 %5Bhig
@@ -1682,26 +1682,21 @@
  if 
-self.ranking_scale
+RANKING_SCALE
 %5Bhig

Use the unified ranking scale when finding the highest severity.