Skip to content

replace ciso8601 by iso8601 #40

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"morecantile>=3.1,<4.0",
"geojson-pydantic>=0.4.3",
"pygeofilter>=0.2.0,<0.3.0",
"ciso8601~=2.2.0",
"iso8601~=1.0.2",
"starlette-cramjam>=0.3,<0.4",
"importlib_resources>=1.1.0; python_version < '3.9'",
"typing_extensions; python_version < '3.9.2'",
Expand Down
39 changes: 0 additions & 39 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tipg/dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from buildpg import asyncpg, clauses
from buildpg import funcs as pg_funcs
from buildpg import logic, render
from ciso8601 import parse_rfc3339
from morecantile import Tile, TileMatrixSet
from pydantic import BaseModel, Field, root_validator
from pygeofilter.ast import AstType
Expand All @@ -24,6 +23,7 @@
from tipg.filter.filters import bbox_to_wkt
from tipg.model import Extent
from tipg.settings import TableSettings, TileSettings
from tipg.utils import parse_rfc3339

tile_settings = TileSettings()

Expand Down
2 changes: 1 addition & 1 deletion tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import jinja2
import orjson
from ciso8601 import parse_rfc3339
from morecantile import TileMatrixSet
from morecantile import tms as default_tms
from morecantile.defaults import TileMatrixSets
Expand All @@ -45,6 +44,7 @@
from tipg.resources.enums import MediaType
from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse
from tipg.settings import TileSettings
from tipg.utils import parse_rfc3339

from fastapi import APIRouter, Depends, Path, Query
from fastapi.responses import ORJSONResponse
Expand Down
57 changes: 57 additions & 0 deletions tipg/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""tipg.utils."""

import re
from datetime import datetime

from iso8601 import parse_date

RFC33339_PATTERN = r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?(Z|([-+])(\d\d):(\d\d))$"


def parse_rfc3339(s: str) -> datetime:
"""Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`.

Uses :meth:`iso8601.parse_date` under the hood.

Args:
s (str) : The string to convert to :class:`datetime.datetime`.
Returns:
str: The datetime represented by the ISO8601 (RFC 3339) formatted string.
Raises:
ValueError: If the string is not a valid RFC 3339 string.

code from https://github.com/stac-utils/stac-fastapi/blob/3edb62ec91a1eacfbfae8a12646b0422943c34ec/stac_fastapi/types/stac_fastapi/types/rfc3339.py#L9-L35

MIT License

Copyright (c) 2020 Arturo AI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

"""
# Uppercase the string
s = s.upper()

# Match against RFC3339 regex.
result = re.match(RFC33339_PATTERN, s)
if not result:
raise ValueError("Invalid RFC3339 datetime.")

# Parse with pyiso8601
return parse_date(s)