<commit_before>from __future__ import absolute_import

from .base import Filter
from six.moves.urllib.parse import urlparse
from sentry.utils.data_filters import FilterStatKeys

LOCAL_IPS = frozenset(['127.0.0.1', '::1'])
LOCAL_DOMAINS = frozenset(['127.0.0.1', 'localhost'])


class LocalhostFilter(Filter):
    id = FilterStatKeys.LOCALHOST
    name = 'Filter out events coming from localhost'
    description = 'This applies to to both IPv4 (``127.0.0.1``) and IPv6 (``::1``) addresses.'

    def get_ip_address(self, data):
        try:
            return data['sentry.interfaces.User']['ip_address']
        except KeyError:
            return ''

    def get_url(self, data):
        try:
            return data['sentry.interfaces.Http']['url'] or ''
        except KeyError:
            return ''

    def get_domain(self, data):
        return urlparse(self.get_url(data)).hostname

    def test(self, data):
        return self.get_ip_address(data) in LOCAL_IPS or self.get_domain(data) in LOCAL_DOMAINS<commit_msg>Remove duplicate word<commit_after>from __future__ import absolute_import

from .base import Filter
from six.moves.urllib.parse import urlparse
from sentry.utils.data_filters import FilterStatKeys

LOCAL_IPS = frozenset(['127.0.0.1', '::1'])
LOCAL_DOMAINS = frozenset(['127.0.0.1', 'localhost'])


class LocalhostFilter(Filter):
    id = FilterStatKeys.LOCALHOST
    name = 'Filter out events coming from localhost'
    description = 'This applies to both IPv4 (``127.0.0.1``) and IPv6 (``::1``) addresses.'

    def get_ip_address(self, data):
        try:
            return data['sentry.interfaces.User']['ip_address']
        except KeyError:
            return ''

    def get_url(self, data):
        try:
            return data['sentry.interfaces.Http']['url'] or ''
        except KeyError:
            return ''

    def get_domain(self, data):
        return urlparse(self.get_url(data)).hostname

    def test(self, data):
        return self.get_ip_address(data) in LOCAL_IPS or self.get_domain(data) in LOCAL_DOMAINS
{'fraction_non_alphanumeric': 0.12068126520681265, 'fraction_numerical': 0.02141119221411192, 'mean_word_length': 3.195918367346939, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2340265', 'n_tokens_mistral': 662, 'n_tokens_neox': 635, 'n_words': 160}