Skip to content

drop Python2 support #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions netfields/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@
from django.db.backends.postgresql.base import is_psycopg3
except ImportError:
is_psycopg3 = False

if VERSION[0] <= 2:
from django.utils.six import with_metaclass, text_type
else:
from six import with_metaclass, text_type
8 changes: 4 additions & 4 deletions netfields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from netaddr import EUI
from netaddr.core import AddrFormatError

from netfields.compat import DatabaseWrapper, is_psycopg3, with_metaclass, text_type
from netfields.compat import DatabaseWrapper, is_psycopg3
from netfields.forms import (
InetAddressFormField,
NoPrefixInetAddressFormField,
Expand Down Expand Up @@ -202,7 +202,7 @@ def get_prep_value(self, value):
if not value:
return None

return text_type(self.to_python(value))
return str(self.to_python(value))

def get_db_prep_value(self, value, connection, prepared=False):
# Django <= 1.8, ArrayField does not pass model to the base_field so we have to check for existance
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_prep_value(self, value):
if not value:
return None

return text_type(self.to_python(value))
return str(self.to_python(value))

def get_db_prep_value(self, value, connection, prepared=False):
# Django <= 1.8, ArrayField does not pass model to the base_field, so we have to check for existence
Expand All @@ -266,4 +266,4 @@ def get_db_prep_value(self, value, connection, prepared=False):
def formfield(self, **kwargs):
defaults = {'form_class': MACAddress8FormField}
defaults.update(kwargs)
return super(MACAddress8Field, self).formfield(**defaults)
return super(MACAddress8Field, self).formfield(**defaults)
11 changes: 5 additions & 6 deletions netfields/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django import forms
from django.core.exceptions import ValidationError

from netfields.compat import text_type
from netfields.mac import mac_unix_common, mac_eui64


Expand All @@ -24,7 +23,7 @@ def to_python(self, value):
if isinstance(value, _IPAddressBase):
return value

if isinstance(value, text_type):
if isinstance(value, str):
value = value.strip()

try:
Expand All @@ -49,7 +48,7 @@ def to_python(self, value):
if isinstance(value, _IPAddressBase):
return value

if isinstance(value, text_type):
if isinstance(value, str):
value = value.strip()

try:
Expand All @@ -75,7 +74,7 @@ def to_python(self, value):
if isinstance(value, _BaseNetwork):
network = value

if isinstance(value, text_type):
if isinstance(value, str):
value = value.strip()

try:
Expand Down Expand Up @@ -103,7 +102,7 @@ def to_python(self, value):
if isinstance(value, EUI):
return value

if isinstance(value, text_type):
if isinstance(value, str):
value = value.strip()

try:
Expand Down Expand Up @@ -132,7 +131,7 @@ def to_python(self, value):
if isinstance(value, EUI):
return value

if isinstance(value, text_type):
if isinstance(value, str):
value = value.strip()

try:
Expand Down
11 changes: 4 additions & 7 deletions netfields/rest_framework.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from __future__ import absolute_import

from ipaddress import ip_address, ip_interface, ip_network

from netaddr import EUI
from netaddr.core import AddrFormatError
from rest_framework import serializers

from netfields.compat import text_type
from netfields.mac import mac_unix_common, mac_eui64
from netfields import fields

Expand All @@ -23,7 +20,7 @@ def __init__(self, store_prefix=True, *args, **kwargs):
def to_representation(self, value):
if value is None:
return value
return text_type(value)
return str(value)

def to_internal_value(self, data):
if data is None:
Expand All @@ -46,7 +43,7 @@ class CidrAddressField(serializers.Field):
def to_representation(self, value):
if value is None:
return value
return text_type(value)
return str(value)

def to_internal_value(self, data):
if data is None:
Expand All @@ -67,7 +64,7 @@ class MACAddressField(serializers.Field):
def to_representation(self, value):
if value is None:
return value
return text_type(value)
return str(value)

def to_internal_value(self, data):
if data is None:
Expand All @@ -86,7 +83,7 @@ class MACAddress8Field(serializers.Field):
def to_representation(self, value):
if value is None:
return value
return text_type(value)
return str(value)

def to_internal_value(self, data):
if data is None:
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from distutils.core import setup

import os
import sys


def get_long_description():
path = os.path.join(os.path.dirname(__file__), 'README.rst')
Expand All @@ -15,12 +13,8 @@ def get_long_description():
requirements = [
'netaddr',
'django>=1.8',
'six',
]

if sys.version_info.major == 2:
requirements.append('ipaddress')

setup(
name='django-netfields',
version='1.3.2',
Expand All @@ -44,6 +38,7 @@ def get_long_description():
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Utilities',
],
)
1 change: 0 additions & 1 deletion test/tests/test_form_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from ipaddress import ip_address, ip_interface, ip_network
from netaddr import EUI

Expand Down
1 change: 0 additions & 1 deletion test/tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from django import VERSION
from ipaddress import ip_interface, ip_network
from netaddr import EUI
Expand Down
8 changes: 1 addition & 7 deletions test/tests/test_rest_framework_fields.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from __future__ import absolute_import, unicode_literals

from rest_framework import serializers
import sys

if sys.version_info.major == 2:
import unittest2 as unittest
else:
import unittest
import unittest

from netfields import rest_framework as fields

Expand Down
1 change: 0 additions & 1 deletion test/tests/test_sql_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import warnings
import django
from django import VERSION
Expand Down