<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re
from django.core.urlresolvers import reverse
from django.db import models
from django.utils import timezone
from . import ip_utils as ipu
from .geoip import get_geoip, NO_COUNTRY


TYPE_LOCATION = 'location'
TYPE_RANGE = 'range'


geoip = get_geoip()


class IPGroupManager(models.Manager):
    def get_queryset(self):
        qs = super(IPGroupManager, self).get_queryset()
        if self.model.TYPE is not None:
            return qs.filter(type=self.model.TYPE)
        return qs


class IPGroup(models.Model):
    TYPE_CHOICES = ((TYPE_LOCATION, 'Location based'),
                    (TYPE_RANGE, 'Range based'))
    TYPE = None

    name = models.CharField(max_length=100)
    description = models.TextField(null=True, blank=True)
    type = models.CharField(max_length=10, default=TYPE_RANGE, choices=TYPE_CHOICES)

    class Meta:
        verbose_name = 'IP Group'

    objects = IPGroupManager()

    def __init__(self, *args, **kwargs):
        super(IPGroup, self).__init__(*args, **kwargs)
        self.load()

    def load(self):
        pass

    def save(self, *args, **kwargs):
        self.type = self.TYPE
        super(IPGroup, self).save(*args, **kwargs)

    def __str__(self):
        return self.name

    __unicode__ = __str__


def typed_ip_group(ip_group):
    obj = None
    if ip_group.type == TYPE_RANGE:
        obj = RangeBasedIPGroup(pk=ip_group.pk)
    elif ip_group.type == TYPE_LOCATION:<commit_msg>Enforcing correct IPGroup.type only for IPGroup subclasses.<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re
from django.core.urlresolvers import reverse
from django.db import models
from django.utils import timezone
from . import ip_utils as ipu
from .geoip import get_geoip, NO_COUNTRY


TYPE_LOCATION = 'location'
TYPE_RANGE = 'range'


geoip = get_geoip()


class IPGroupManager(models.Manager):
    def get_queryset(self):
        qs = super(IPGroupManager, self).get_queryset()
        if self.model.TYPE is not None:
            return qs.filter(type=self.model.TYPE)
        return qs


class IPGroup(models.Model):
    TYPE_CHOICES = ((TYPE_LOCATION, 'Location based'),
                    (TYPE_RANGE, 'Range based'))
    TYPE = None

    name = models.CharField(max_length=100)
    description = models.TextField(null=True, blank=True)
    type = models.CharField(max_length=10, default=TYPE_RANGE, choices=TYPE_CHOICES)

    class Meta:
        verbose_name = 'IP Group'

    objects = IPGroupManager()

    def __init__(self, *args, **kwargs):
        super(IPGroup, self).__init__(*args, **kwargs)
        self.load()

    def load(self):
        pass

    def save(self, *args, **kwargs):
        if self.TYPE is not None:
            self.type = self.TYPE
        super(IPGroup, self).save(*args, **kwargs)

    def __str__(self):
        return self.name

    __unicode__ = __str__


def typed_ip_group(ip_group):
    obj = None
    if ip_group.type == TYPE_RANGE:
        obj = RangeBasedIPGroup(pk=ip_group.pk)
    elif ip_group.type == TYPE_LOCATION:
{'fraction_non_alphanumeric': 0.10657306955966815, 'fraction_numerical': 0.0038289725590299937, 'mean_word_length': 3.0767230169050714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5859911', 'n_tokens_mistral': 1026, 'n_tokens_neox': 986, 'n_words': 246}