Skip to content
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

use non-deprecated way of changing JSON encoder #36

Merged
merged 1 commit into from
Dec 24, 2022
Merged
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
11 changes: 7 additions & 4 deletions galactory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
# (c) 2022 Brian Scholer (@briantist)

import logging
import typing as t

from datetime import datetime
from flask import Flask, request
from flask.json import JSONEncoder
from flask.json.provider import DefaultJSONProvider
from configargparse import ArgParser, ArgumentError, Action
from artifactory import ArtifactoryPath

from .api import bp as api
from .download import bp as download
from .health import bp as health

class DateTimeIsoFormatJSONEncoder(JSONEncoder):
def default(self, o):

class DateTimeIsoFormatJSONProvider(DefaultJSONProvider):
@staticmethod
def default(o: t.Any) -> t.Any:
if isinstance(o, datetime):
return o.isoformat()

Expand All @@ -23,7 +26,7 @@ def default(self, o):

def create_app(**config):
app = Flask(__name__)
app.json_encoder = DateTimeIsoFormatJSONEncoder
app.json = DateTimeIsoFormatJSONProvider(app)
app.config.update(**config)
app.register_blueprint(health)
app.register_blueprint(api)
Expand Down