Skip to content

Commit

Permalink
Python 3.7 compatibility issue fix (#12)
Browse files Browse the repository at this point in the history
Fixed python 3.7 compatibility
Removed Python 3.3 support as psycopg2 doesn't support it any more
Moved testing to xenial release to support python 3.7
  • Loading branch information
M1ha-Shvn authored Apr 19, 2019
1 parent d2da7c5 commit 3f332d3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
30 changes: 18 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
dist: trusty
dist: xenial
sudo: false
language: python
cache: pip

python:
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
Expand All @@ -28,16 +27,8 @@ matrix:
- python: 2.7
env: DJANGO=2.1

# Django 1.9+ doesn't support python 3.3
- python: 3.3
env: DJANGO=1.9
- python: 3.3
env: DJANGO=1.10
- python: 3.3
env: DJANGO=1.11
- python: 3.3
env: DJANGO=2.0
- python: 3.3
# Django 2.1 doesn't support python 3.4
- python: 3.4
env: DJANGO=2.1

# Django 1.7 doesn't support python 3.5+
Expand All @@ -48,6 +39,21 @@ matrix:
- python: 3.7
env: DJANGO=1.7

# python 3.6 has deprecated issue with django before 1.11
# https://stackoverflow.com/questions/41343263/provide-classcell-example-for-python-3-6-metaclass\
- python: 3.6
env: DJANGO=1.8
- python: 3.6
env: DJANGO=1.9
- python: 3.6
env: DJANGO=1.10
- python: 3.7
env: DJANGO=1.8
- python: 3.7
env: DJANGO=1.9
- python: 3.7
env: DJANGO=1.10

install:
- pip install -r requirements.txt
- pip install -q Django==$DJANGO
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Extended form fields to validate REST-request data via django.forms.

## Requirements
* Python 2.7 or Python 3.3+
* Python 2.7 or Python 3.4+
* Django >= 1.7
* pytz
* jsonschema
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ jsonschema
six
typing
psycopg2
typing
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='django-rest-form-fields',
version='1.2.7',
version='1.2.8',
packages=['django_rest_form_fields'],
package_dir={'': 'src'},
url='https://github.com/M1hacka/django-rest-form-fields',
Expand Down
7 changes: 6 additions & 1 deletion src/django_rest_form_fields/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
This file contains functions for different python and django version compatibility
"""
import datetime

import pytz
import re

from django.utils.timezone import make_aware, utc


Expand All @@ -18,3 +19,7 @@ def to_timestamp(dt): # type: (datetime.datetime) -> float
return dt.timestamp()
else:
return (dt - datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=pytz.utc)).total_seconds()


def get_pattern_type():
return re.Pattern if hasattr(re, 'Pattern') else re._pattern_type
6 changes: 3 additions & 3 deletions src/django_rest_form_fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from django.utils.timezone import make_aware, utc
from typing import Any, Optional, Union

from django_rest_form_fields.compatibility import to_timestamp
from django_rest_form_fields.exceptions import FileSizeError, FileTypeError
from .compatibility import to_timestamp, get_pattern_type
from .exceptions import FileSizeError, FileTypeError


class BaseField(forms.Field):
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self, *args, **kwargs):
self.regex = kwargs.pop('regex', None)
self.flags = kwargs.pop('flags', 0)

assert self.regex is None or isinstance(self.regex, (six.string_types, re._pattern_type)),\
assert self.regex is None or isinstance(self.regex, (six.string_types, get_pattern_type())),\
'regex must be string if given'
assert isinstance(self.flags, int), 'flags must be integer'

Expand Down

0 comments on commit 3f332d3

Please sign in to comment.