from net_map.cvss_metrics import CVSSMetrics
from ext.serialization import JsonSerializableObject


class Vulnerability(JsonSerializableObject):

    def __init__(self, cve_id=None, summary='', date=None, cvss_metrics=None, is_patched=False):
        self.cve_id = cve_id
        self.summary = summary
        self.date = date
        self.cvss_metrics = cvss_metrics
        self.is_patched = is_patched

    def serialize_value(self, name, value):
        return super(Vulnerability, self).serialize_value(name, value)

    def parse_dict(self, name, value):
        if name == 'cvss_metrics':
            return CVSSMetrics().from_dict(value)
        return value

    def __eq__(self, other):
        return self.cve_id == other.cve_id

    def __hash__(self):
        return hash((self.cve_id, ))

    def __unicode__(self):
        return "cve_id: %s" % (self.cve_id, )

    def __str__(self):
        return unicode(self).encode('utf-8')

    __repr__ = __str__
from net_map.cvss_metrics import CVSSMetrics
from ext.serialization import JsonSerializableObject


class Vulnerability(JsonSerializableObject):

    def __init__(self, cve_id=None, summary='', date=None, cvss_metrics=None, is_patched=False):
        self.cve_id = cve_id
        self.summary = summary
        self.date = date
        self.cvss_metrics = cvss_metrics
        self.is_patched = is_patched

    def serialize_value(self, name, value):
        return super(Vulnerability, self).serialize_value(name, value)

    def parse_dict(self, name, value):
        if name == 'cvss_metrics':
            return CVSSMetrics().from_dict(value)
        return value

    def __eq__(self, other):
        return self.cve_id == other.cve_id

    def __hash__(self):
        return hash((self.cve_id, ))

    def __unicode__(self):
        return "cve_id: %s" % (self.cve_id, )

    def __str__(self):
        return unicode(self).encode('utf-8')

    __repr__ = __str__