Skip to content

Commit fda5f88

Browse files
author
James Oakley
committed
Cleanup. Support Python 3
1 parent d336496 commit fda5f88

File tree

5 files changed

+137
-158
lines changed

5 files changed

+137
-158
lines changed

Diff for: .gitignore

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
*.pyc
2-
.tox/
2+
*.egg
3+
*.egg-info
4+
.*
35
MANIFEST
46
build/
57
dist/
6-
*.egg-info/
7-
.eric?project/
8-
.issues/
9-
*.e4p
8+
*.json

Diff for: netfields/fields.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from netaddr import IPAddress, IPNetwork, EUI
22
from netaddr.core import AddrFormatError
33

4-
from django import VERSION
4+
from django import VERSION as DJANGO_VERSION
55
from django.db import models
66
from django.core.exceptions import ValidationError
7+
from django.utils.six import with_metaclass
78

89
from netfields.managers import NET_OPERATORS, NET_TEXT_OPERATORS
910
from netfields.forms import InetAddressFormField, CidrAddressFormField, MACAddressFormField
@@ -65,18 +66,17 @@ def formfield(self, **kwargs):
6566
defaults.update(kwargs)
6667
return super(_NetAddressField, self).formfield(**defaults)
6768

68-
if VERSION[:2] >= (1, 7):
69+
if DJANGO_VERSION[:2] >= (1, 7):
6970
def deconstruct(self):
7071
name, path, args, kwargs = super(_NetAddressField, self).deconstruct()
7172
if self.max_length is not None:
7273
kwargs['max_length'] = self.max_length
7374
return name, path, args, kwargs
7475

7576

76-
class InetAddressField(_NetAddressField):
77+
class InetAddressField(with_metaclass(models.SubfieldBase, _NetAddressField)):
7778
description = "PostgreSQL INET field"
7879
max_length = 39
79-
__metaclass__ = models.SubfieldBase
8080

8181
def db_type(self, connection):
8282
return 'inet'
@@ -88,10 +88,9 @@ def form_class(self):
8888
return InetAddressFormField
8989

9090

91-
class CidrAddressField(_NetAddressField):
91+
class CidrAddressField(with_metaclass(models.SubfieldBase, _NetAddressField)):
9292
description = "PostgreSQL CIDR field"
9393
max_length = 43
94-
__metaclass__ = models.SubfieldBase
9594

9695
def db_type(self, connection):
9796
return 'cidr'
@@ -129,7 +128,7 @@ def formfield(self, **kwargs):
129128
defaults.update(kwargs)
130129
return super(MACAddressField, self).formfield(**defaults)
131130

132-
if VERSION[:2] < (1, 7):
131+
if DJANGO_VERSION[:2] < (1, 7):
133132
try:
134133
from south.modelsinspector import add_introspection_rules
135134
add_introspection_rules([], [

Diff for: netfields/managers.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from netaddr import IPNetwork
22

3-
from django import VERSION
3+
from django import VERSION as DJANGO_VERSION
44
from django.db import models, connection
55
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper
66
from django.db.models.fields import DateTimeField
@@ -10,6 +10,12 @@
1010

1111
import datetime
1212

13+
try:
14+
basestring
15+
except NameError:
16+
basestring = (str, bytes)
17+
18+
1319
NET_OPERATORS = DatabaseWrapper.operators.copy()
1420

1521
for operator in ['contains', 'startswith', 'endswith']:
@@ -32,14 +38,11 @@ class NetQuery(sql.Query):
3238

3339

3440
class NetWhere(sql.where.WhereNode):
35-
36-
3741
def _prepare_data(self, data):
3842
"""
3943
Special form of WhereNode._prepare_data() that does not automatically consume the
4044
__iter__ method of IPNetwork objects. This is used in Django >= 1.6
4145
"""
42-
4346
if not isinstance(data, (list, tuple)):
4447
return data
4548
obj, lookup_type, value = data
@@ -65,7 +68,7 @@ def _prepare_data(self, data):
6568
return (obj, lookup_type, value_annotation, value)
6669

6770

68-
if VERSION[:2] < (1, 6):
71+
if DJANGO_VERSION[:2] < (1, 6):
6972
def add(self, data, connector):
7073
"""
7174
Special form of WhereNode.add() that does not automatically consume the
@@ -100,7 +103,7 @@ def add(self, data, connector):
100103
tree.Node.add(self,
101104
(obj, lookup_type, value_annotation, value), connector)
102105

103-
if VERSION[:2] < (1, 7):
106+
if DJANGO_VERSION[:2] < (1, 7):
104107
def make_atom(self, child, qn, conn):
105108
lvalue, lookup_type, value_annot, params_or_value = child
106109

@@ -163,7 +166,7 @@ def get_queryset(self):
163166
q = NetQuery(self.model, NetWhere)
164167
return query.QuerySet(self.model, q)
165168

166-
if VERSION[:2] < (1, 6):
169+
if DJANGO_VERSION[:2] < (1, 6):
167170
def get_query_set(self):
168171
q = NetQuery(self.model, NetWhere)
169172
return query.QuerySet(self.model, q)

0 commit comments

Comments
 (0)