Skip to content

Commit

Permalink
Update module imports
Browse files Browse the repository at this point in the history
Use immediate modules within the package, and import from the package level for integration tests.

For now, ignore `pickle` security warning.
  • Loading branch information
ColeDCrawford committed May 16, 2024
1 parent 85bac2a commit 9e6aca1
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 10 deletions.
69 changes: 65 additions & 4 deletions edtf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
from edtf.convert import (
from edtf.natlang import text_to_edtf
from edtf.parser import (
UA,
Consecutives,
Date,
DateAndTime,
EarlierConsecutives,
EDTFObject,
EDTFParseException,
ExponentialYear,
Interval,
LaterConsecutives,
Level1Interval,
Level2Interval,
Level2Season,
LongYear,
MultipleDates,
OneOfASet,
PartialUncertainOrApproximate,
PartialUnspecified,
Season,
UncertainOrApproximate,
Unspecified,
UnspecifiedIntervalSection,
parse_edtf,
)

from .convert import (
dt_to_struct_time,
jd_to_struct_time,
old_specs_to_new_specs_expression,
Expand All @@ -7,6 +34,40 @@
struct_time_to_jd,
trim_struct_time,
)
from edtf.natlang import text_to_edtf
from edtf.parser.grammar import parse_edtf
from edtf.parser.parser_classes import *

# public
__all__ = [
"dt_to_struct_time",
"jd_to_struct_time",
"old_specs_to_new_specs_expression",
"struct_time_to_date",
"struct_time_to_datetime",
"struct_time_to_jd",
"trim_struct_time",
"text_to_edtf",
"parse_edtf",
# parser_exceptions
"EDTFParseException",
# parser_classes
"EDTFObject",
"Date",
"DateAndTime",
"Interval",
"UA",
"UncertainOrApproximate",
"UnspecifiedIntervalSection",
"Unspecified",
"Level1Interval",
"LongYear",
"Season",
"PartialUncertainOrApproximate",
"PartialUnspecified",
"Consecutives",
"EarlierConsecutives",
"LaterConsecutives",
"OneOfASet",
"MultipleDates",
"Level2Interval",
"Level2Season",
"ExponentialYear",
]
2 changes: 1 addition & 1 deletion edtf/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def from_db_value(self, value, expression, connection):

try:
# Try to unpickle if the value was pickled
return pickle.loads(value)
return pickle.loads(value) # noqa S301
except (pickle.PickleError, TypeError):
# If it fails because it's not pickled data, try parsing as EDTF
return parse_edtf(value, fail_silently=True)
Expand Down
2 changes: 2 additions & 0 deletions edtf/natlang/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .en import text_to_edtf

__all__ = ["text_to_edtf"]
53 changes: 51 additions & 2 deletions edtf/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
from edtf.parser.grammar import parse_edtf
from edtf.parser.parser_classes import *
from .edtf_exceptions import EDTFParseException
from .grammar import parse_edtf
from .parser_classes import (
UA,
Consecutives,
Date,
DateAndTime,
EarlierConsecutives,
EDTFObject,
ExponentialYear,
Interval,
LaterConsecutives,
Level1Interval,
Level2Interval,
Level2Season,
LongYear,
MultipleDates,
OneOfASet,
PartialUncertainOrApproximate,
PartialUnspecified,
Season,
UncertainOrApproximate,
Unspecified,
UnspecifiedIntervalSection,
)

__all__ = [
"parse_edtf",
"EDTFParseException",
"EDTFObject",
"Date",
"DateAndTime",
"Interval",
"UA",
"UncertainOrApproximate",
"Unspecified",
"UnspecifiedIntervalSection",
"Level1Interval",
"LongYear",
"Season",
"PartialUncertainOrApproximate",
"PartialUnspecified",
"Consecutives",
"EarlierConsecutives",
"LaterConsecutives",
"OneOfASet",
"MultipleDates",
"Level2Interval",
"Level2Season",
"ExponentialYear",
]
5 changes: 2 additions & 3 deletions edtf_django_tests/edtf_integration/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.test import TestCase

from edtf.convert import struct_time_to_jd
from edtf.parser import EDTFObject
from edtf.parser.grammar import parse_edtf as parse
from edtf import EDTFObject, struct_time_to_jd
from edtf import parse_edtf as parse

from .models import TestEvent

Expand Down

0 comments on commit 9e6aca1

Please sign in to comment.