<commit_before>try:
    unicode
except NameError:
    unicode = str

from copy import deepcopy
import datetime
try:
    from urlparse import urljoin
except ImportError:
    from urllib.parse import urljoin

from django.contrib.auth.models import User
from django.contrib.gis.db import models
from django.contrib.gis.geos import fromstr as geos_geom_from_string
from django.core import urlresolvers
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import utc

import dateutil.parser
import hashlib
from jsonfield import JSONField
from lxml import etree
from lxml.builder import E
import requests
import pytz

from open511.converter import json_struct_to_xml, geojson_to_gml, geom_to_xml_element
from open511.utils.schedule import Schedule
from open511.utils.serialization import XML_LANG, NSMAP, make_link

from open511_server.conf import settings
from open511_server.fields import XMLField
from open511_server.utils import is_hex
from open511_server.utils.optimization import get_cached_object, memoize_method
from open511_server.utils.postgis import gml_to_ewkt
from open511_server.utils.xmlmodel import XMLModelMixin


def _now():
    return datetime.datetime.now(utc).replace(microsecond=0)  # microseconds == overkill

class _Open511Model(models.Model):

    created = models.DateTimeField(default=_now, db_index=True)
    updated = models.DateTimeField(default=_now, db_index=True)

    @property
    def url(self):
        if getattr(self, 'external_url', None):
            return self.external_url
        return self.get_absolute_url()

    @property
    def full_url(self):
        url = self.url
        if url.startswith('/'):
            return settings.OPEN511_BASE_URL + url
        return url

    def save(self, *args, **kwargs):
        self.updated = _now()
        return super(_Open511Model, self).save(*args, **kwargs)

    class Meta(object):
        abstract = True


class JurisdictionManager(models.GeoManager):

    def get_or_create_from_url(self, url):
        try:
            return self.get(external_url=url)
        except ObjectDoesNotExist:
            id = filter(None, url.split('/'))[-1]
            try:
                return self.get(id=id)
            except ObjectDoesNotExist:
                pass<commit_msg>py3k: stop using filter()<commit_after>try:
    unicode
except NameError:
    unicode = str

from copy import deepcopy
import datetime
try:
    from urlparse import urljoin
except ImportError:
    from urllib.parse import urljoin

from django.contrib.auth.models import User
from django.contrib.gis.db import models
from django.contrib.gis.geos import fromstr as geos_geom_from_string
from django.core import urlresolvers
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import utc

import dateutil.parser
import hashlib
from jsonfield import JSONField
from lxml import etree
from lxml.builder import E
import requests
import pytz

from open511.converter import json_struct_to_xml, geojson_to_gml, geom_to_xml_element
from open511.utils.schedule import Schedule
from open511.utils.serialization import XML_LANG, NSMAP, make_link

from open511_server.conf import settings
from open511_server.fields import XMLField
from open511_server.utils import is_hex
from open511_server.utils.optimization import get_cached_object, memoize_method
from open511_server.utils.postgis import gml_to_ewkt
from open511_server.utils.xmlmodel import XMLModelMixin


def _now():
    return datetime.datetime.now(utc).replace(microsecond=0)  # microseconds == overkill

class _Open511Model(models.Model):

    created = models.DateTimeField(default=_now, db_index=True)
    updated = models.DateTimeField(default=_now, db_index=True)

    @property
    def url(self):
        if getattr(self, 'external_url', None):
            return self.external_url
        return self.get_absolute_url()

    @property
    def full_url(self):
        url = self.url
        if url.startswith('/'):
            return settings.OPEN511_BASE_URL + url
        return url

    def save(self, *args, **kwargs):
        self.updated = _now()
        return super(_Open511Model, self).save(*args, **kwargs)

    class Meta(object):
        abstract = True


class JurisdictionManager(models.GeoManager):

    def get_or_create_from_url(self, url):
        try:
            return self.get(external_url=url)
        except ObjectDoesNotExist:
            id = [bit for bit in url.split('/') if bit][-1]
            try:
                return self.get(id=id)
            except ObjectDoesNotExist:
                pass
{'fraction_non_alphanumeric': 0.07012565869477097, 'fraction_numerical': 0.016011349817592217, 'mean_word_length': 3.722488038277512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '1969915', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1427, 'n_words': 395}