mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
remove dependency on pytz (#8984)
* remove pytz
* Revert "remove pytz"
This reverts commit 393609dfaa
.
* remove pytz, more subtly
This commit is contained in:
parent
03e2ecc9a5
commit
376a5cbbba
|
@ -29,7 +29,11 @@ from django.utils.encoding import is_protected_type, smart_str
|
|||
from django.utils.formats import localize_input, sanitize_separators
|
||||
from django.utils.ipv6 import clean_ipv6_address
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from pytz.exceptions import InvalidTimeError
|
||||
|
||||
try:
|
||||
import pytz
|
||||
except ImportError:
|
||||
pytz = None
|
||||
|
||||
from rest_framework import ISO_8601
|
||||
from rest_framework.exceptions import ErrorDetail, ValidationError
|
||||
|
@ -1148,8 +1152,10 @@ class DateTimeField(Field):
|
|||
if not valid_datetime(dt):
|
||||
self.fail('make_aware', timezone=field_timezone)
|
||||
return dt
|
||||
except InvalidTimeError:
|
||||
except Exception as e:
|
||||
if pytz and isinstance(e, pytz.exceptions.InvalidTimeError):
|
||||
self.fail('make_aware', timezone=field_timezone)
|
||||
raise e
|
||||
elif (field_timezone is None) and timezone.is_aware(value):
|
||||
return timezone.make_naive(value, datetime.timezone.utc)
|
||||
return value
|
||||
|
|
2
setup.py
2
setup.py
|
@ -83,7 +83,7 @@ setup(
|
|||
author_email='tom@tomchristie.com', # SEE NOTE BELOW (*)
|
||||
packages=find_packages(exclude=['tests*']),
|
||||
include_package_data=True,
|
||||
install_requires=["django>=3.0", "pytz", 'backports.zoneinfo;python_version<"3.9"'],
|
||||
install_requires=["django>=3.0", 'backports.zoneinfo;python_version<"3.9"'],
|
||||
python_requires=">=3.6",
|
||||
zip_safe=False,
|
||||
classifiers=[
|
||||
|
|
|
@ -9,7 +9,12 @@ from enum import auto
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import pytz
|
||||
|
||||
try:
|
||||
import pytz
|
||||
except ImportError:
|
||||
pytz = None
|
||||
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.db.models import IntegerChoices, TextChoices
|
||||
from django.http import QueryDict
|
||||
|
@ -1604,6 +1609,7 @@ class TestPytzNaiveDayLightSavingTimeTimeZoneDateTimeField(FieldValues):
|
|||
}
|
||||
outputs = {}
|
||||
|
||||
if pytz:
|
||||
class MockTimezone(pytz.BaseTzInfo):
|
||||
@staticmethod
|
||||
def localize(value, is_dst):
|
||||
|
|
Loading…
Reference in New Issue
Block a user