aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat_scholar/web.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-10-27 14:33:09 -0700
committerBryan Newbold <bnewbold@archive.org>2021-10-27 18:25:58 -0700
commitb4d0bfb643842e6070a4ee36cfc52e2292e3b5ba (patch)
tree1988743c61f5c053148d66f6939ff32f398ae06e /fatcat_scholar/web.py
parent956e64f47f7d47f2539cd6575c25ec0b6a33e567 (diff)
downloadfatcat-scholar-b4d0bfb643842e6070a4ee36cfc52e2292e3b5ba.tar.gz
fatcat-scholar-b4d0bfb643842e6070a4ee36cfc52e2292e3b5ba.zip
make fmt (black 21.9b0)
Diffstat (limited to 'fatcat_scholar/web.py')
-rw-r--r--fatcat_scholar/web.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py
index e835c01..4e21ecd 100644
--- a/fatcat_scholar/web.py
+++ b/fatcat_scholar/web.py
@@ -79,7 +79,8 @@ class LangPrefix:
# first try to parse a language code from header
try:
accept_code = parse_accept_lang(
- request.headers.get("accept-language", ""), I18N_LANG_OPTIONS,
+ request.headers.get("accept-language", ""),
+ I18N_LANG_OPTIONS,
)
if accept_code:
self.code = accept_code
@@ -215,14 +216,18 @@ def load_i18n_templates() -> Any:
d = dict()
for lang_opt in I18N_LANG_OPTIONS:
translations = babel.support.Translations.load(
- dirname="fatcat_scholar/translations", locales=[lang_opt],
+ dirname="fatcat_scholar/translations",
+ locales=[lang_opt],
)
templates = Jinja2Templates(
- directory="fatcat_scholar/templates", extensions=["jinja2.ext.i18n"],
+ directory="fatcat_scholar/templates",
+ extensions=["jinja2.ext.i18n"],
)
templates.env.install_gettext_translations(translations, newstyle=True) # type: ignore
templates.env.install_gettext_callables( # type: ignore
- locale_gettext(translations), locale_ngettext(translations), newstyle=True,
+ locale_gettext(translations),
+ locale_ngettext(translations),
+ newstyle=True,
)
# remove a lot of whitespace in HTML output with these configs
templates.env.trim_blocks = True
@@ -375,7 +380,8 @@ def access_redirect_fallback(
if work_entity.redirect:
work_ident = work_entity.redirect
partial_releases = api_client.get_work_releases(
- ident=work_ident, hide="abstracts,references",
+ ident=work_ident,
+ hide="abstracts,references",
)
except fatcat_openapi_client.ApiException as ae:
raise HTTPException(
@@ -446,7 +452,10 @@ def access_redirect_wayback(
raw_original_url = "/".join(str(request.url).split("/")[7:])
# the quote() call is necessary because the URL is un-encoded in the path parameter
# see also: https://github.com/encode/starlette/commit/f997938916d20e955478f60406ef9d293236a16d
- original_url = urllib.parse.quote(raw_original_url, safe=":/%#?=@[]!$&'()*+,;",)
+ original_url = urllib.parse.quote(
+ raw_original_url,
+ safe=":/%#?=@[]!$&'()*+,;",
+ )
doc_dict = get_es_scholar_doc(f"work_{work_ident}")
if not doc_dict:
return access_redirect_fallback(
@@ -580,7 +589,10 @@ async def http_exception_handler(request: Request, exc: StarletteHTTPException)
resp: Dict[str, Any] = {"status_code": exc.status_code}
if exc.detail:
resp["detail"] = exc.detail
- return JSONResponse(status_code=exc.status_code, content=resp,)
+ return JSONResponse(
+ status_code=exc.status_code,
+ content=resp,
+ )
# configure middleware