# Path: privacyscore/evaluation/description.py
# def describe_locations(server_type: str, locations: list) -> dict:
#     """Describe a list of locations."""
#     locations = [location for location in locations if location]
#     if not locations:
#         return {
#             'description': _('The locations of the %(server_type)s could not '
#                              'be detected.') % {'server_type': server_type},
#             'classification': Rating('neutral', influences_ranking=False),
#             'details_list': None
#         }
#     rating = Rating('good')
#     for country in locations:
#         if country not in GDPR_STATES:
#             rating = Rating('bad')
#     if len(locations) == 1:
#         return {
#             'description': _('All %(server_type)s are located in %(country)s.') % {
#                 'server_type': server_type,
#                 'country': locations[0],
#             }, 
#             'classification': rating,
#             'details_list': None
#         }
#     return {
#         'description': _('The %(server_type)s are located in %(countries)s.') % {
#             'server_type': server_type,
#             'countries': ', '.join(locations[:-1]) + ' and {}'.format(locations[-1])
#         },
#         'classification': rating,
#         'details_list': [(country,) for country in locations]
#     }
# 
# Path: privacyscore/evaluation/rating.py
# class Rating:
#     """
#     A rating.
# 
#     It can be critical, bad, warning, good or doubleplusgood.
#     """
#     # rating  : str
#     # influences_ranking  : bool
#     # devaluates_group : bool
# 
#     ORDERING = ['critical', 'bad', 'warning', 'neutral', 'good', 'doubleplusgood']
# 
#     def __init__(self, rating: str, influences_ranking: bool = True, devaluates_group: bool = False):
#         self.rating = rating
#         self.influences_ranking = influences_ranking
#         self.devaluates_group = devaluates_group
# 
#     def __str__(self) -> str:
#         return self.rating
# 
#     def __repr__(self) -> str:
#         return '<Rating {}>'.format(str(self))
# 
#     def __eq__(self, other) -> bool:
#         return self.rating == other.rating
# 
#     def __lt__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) < self.ORDERING.index(other.rating)
# 
#     def __le__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) <= self.ORDERING.index(other.rating)
# 
#     def __gt__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) > self.ORDERING.index(other.rating)
# 
#     def __ge__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) >= self.ORDERING.index(other.rating)


from collections import OrderedDict
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from privacyscore.evaluation.description import describe_locations
from privacyscore.evaluation.rating import Rating
CHECKS['privacy']['google_analytics_anonymizeIP_not_set'] = {
    'keys': {'google_analytics_anonymizeIP_not_set', 'google_analytics_present'},
    'rating': lambda **keys: {
        'description': _('Not checking if Google Analytics data is being anonymized, as the site does not use Google Analytics.'),
        'classification': Rating('neutral'),
        'details_list': None
    } if not keys["google_analytics_present"] else {
        'description': _('The site uses Google Analytics without the AnonymizeIP Privacy extension.'),
        'classification': Rating('bad'),
        'details_list': None
    } if keys['google_analytics_anonymizeIP_not_set'] else {
        'description': _('The site uses Google Analytics, however it instructs Google to store only anonymized IPs.'),
        'classification': Rating('good'),
        'details_list': None,
    },
    'missing': None,
}

# Check for the GeoIP of webservers
# Purely informational, no rating associated
CHECKS['privacy']['webserver_locations'] = {
    'keys': {'a_locations',},
    'rating': lambda **keys: describe_locations(
        _('web servers'), keys['a_locations']),
    'missing': None,
}
# Check for the GeoIP of mail servers, if any
# Purely informational, no rating associated
CHECKS['privacy']['mailserver_locations'] = {
    'keys': {'mx_locations',},

# Path: privacyscore/evaluation/description.py
# def describe_locations(server_type: str, locations: list) -> dict:
#     """Describe a list of locations."""
#     locations = [location for location in locations if location]
#     if not locations:
#         return {
#             'description': _('The locations of the %(server_type)s could not '
#                              'be detected.') % {'server_type': server_type},
#             'classification': Rating('neutral', influences_ranking=False),
#             'details_list': None
#         }
#     rating = Rating('good')
#     for country in locations:
#         if country not in GDPR_STATES:
#             rating = Rating('bad')
#     if len(locations) == 1:
#         return {
#             'description': _('All %(server_type)s are located in %(country)s.') % {
#                 'server_type': server_type,
#                 'country': locations[0],
#             }, 
#             'classification': rating,
#             'details_list': None
#         }
#     return {
#         'description': _('The %(server_type)s are located in %(countries)s.') % {
#             'server_type': server_type,
#             'countries': ', '.join(locations[:-1]) + ' and {}'.format(locations[-1])
#         },
#         'classification': rating,
#         'details_list': [(country,) for country in locations]
#     }
# 
# Path: privacyscore/evaluation/rating.py
# class Rating:
#     """
#     A rating.
# 
#     It can be critical, bad, warning, good or doubleplusgood.
#     """
#     # rating  : str
#     # influences_ranking  : bool
#     # devaluates_group : bool
# 
#     ORDERING = ['critical', 'bad', 'warning', 'neutral', 'good', 'doubleplusgood']
# 
#     def __init__(self, rating: str, influences_ranking: bool = True, devaluates_group: bool = False):
#         self.rating = rating
#         self.influences_ranking = influences_ranking
#         self.devaluates_group = devaluates_group
# 
#     def __str__(self) -> str:
#         return self.rating
# 
#     def __repr__(self) -> str:
#         return '<Rating {}>'.format(str(self))
# 
#     def __eq__(self, other) -> bool:
#         return self.rating == other.rating
# 
#     def __lt__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) < self.ORDERING.index(other.rating)
# 
#     def __le__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) <= self.ORDERING.index(other.rating)
# 
#     def __gt__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) > self.ORDERING.index(other.rating)
# 
#     def __ge__(self, other) -> bool:
#         return self.ORDERING.index(self.rating) >= self.ORDERING.index(other.rating)


# Path: privacyscore/evaluation/default_checks.py
from collections import OrderedDict
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from privacyscore.evaluation.description import describe_locations
from privacyscore.evaluation.rating import Rating

CHECKS['privacy']['google_analytics_anonymizeIP_not_set'] = {
    'keys': {'google_analytics_anonymizeIP_not_set', 'google_analytics_present'},
    'rating': lambda **keys: {
        'description': _('Not checking if Google Analytics data is being anonymized, as the site does not use Google Analytics.'),
        'classification': Rating('neutral'),
        'details_list': None
    } if not keys["google_analytics_present"] else {
        'description': _('The site uses Google Analytics without the AnonymizeIP Privacy extension.'),
        'classification': Rating('bad'),
        'details_list': None
    } if keys['google_analytics_anonymizeIP_not_set'] else {
        'description': _('The site uses Google Analytics, however it instructs Google to store only anonymized IPs.'),
        'classification': Rating('good'),
        'details_list': None,
    },
    'missing': None,
}

# Check for the GeoIP of webservers
# Purely informational, no rating associated
CHECKS['privacy']['webserver_locations'] = {
    'keys': {'a_locations',},
    'rating': lambda **keys: describe_locations(
        _('web servers'), keys['a_locations']),
    'missing': None,
}
# Check for the GeoIP of mail servers, if any
# Purely informational, no rating associated
CHECKS['privacy']['mailserver_locations'] = {
    'keys': {'mx_locations',},

    'rating': lambda **keys: describe_locations(