-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,013 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import re | ||
from urllib.parse import quote, unquote | ||
from src.models.wikimedia.enums import WikimediaDomain | ||
from src import MissingInformationError | ||
from src.models.v2.job import JobV2 | ||
from typing import List | ||
|
||
|
||
class FetchRefsJobV2(JobV2): | ||
"""job that supports FetchRefsV2 endpoint""" | ||
|
||
# using marshmallow to describe parameters | ||
|
||
which_wiki: str = "" | ||
pages: List[str] = [] | ||
wikitext: str = "" | ||
|
||
wiki_domain: WikimediaDomain = WikimediaDomain.wikipedia | ||
wiki_lang: str = "" | ||
|
||
wiki_id: str = "" | ||
wiki_page_title: str = "" | ||
wiki_revision: str = "" | ||
|
||
# @property | ||
# def quoted_title(self): | ||
# if not self.wiki_page_title: | ||
# raise MissingInformationError("self.wiki_page_title is empty") | ||
# return quote(self.wiki_page_title, safe="") | ||
|
||
|
||
def validate_fields(self): | ||
""" | ||
parameter checking done here... | ||
must have at "pages" or "wikitext" defined | ||
""" | ||
|
||
from src import app | ||
|
||
# app.logger.error('fetchrefs validate_fields: Fake Error') | ||
# raise MissingInformationError( | ||
# f'fetchrefs validate_fields: Fake Error' | ||
# ) | ||
|
||
if not self.wikitext: | ||
if not self.pages: | ||
raise MissingInformationError( | ||
f"pages or wikitext parameter must be specified" | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from marshmallow import fields, pre_load, post_load | ||
|
||
from src.models.v2.job.fetchrefs_job_v2 import FetchRefsJobV2 | ||
from src.models.v2.schema import BaseSchemaV2 | ||
|
||
|
||
class FetchRefsSchemaV2(BaseSchemaV2): | ||
# Defines expected parameters for endpoint | ||
# - default parameters are defined in BaseSchemaV2 | ||
|
||
which_wiki = fields.Str(default="enwiki") | ||
pages = fields.List(fields.String(), required=False) # either pages or wikitext must be defined | ||
wikitext = fields.Str(required=False) # if provided, overrides pages array | ||
|
||
@pre_load | ||
# NB: pre_load is a marshmallow directive; | ||
def process_input(self, data, **kwargs): | ||
""" | ||
transform comma separated pages into a List | ||
""" | ||
from src import app | ||
app.logger.debug(f"==> FetchRefsSchemaV2::(@pre_load)process_input: data:{data}") | ||
|
||
request_method = self.context.get('request_method', None) | ||
# if request_method: | ||
# print(f"Request method received: {request_method}") | ||
|
||
app.logger.debug(f"==> FetchRefsSchemaV2::(@pre_load)process_input: request_method:{request_method}") | ||
|
||
|
||
mutable_data = dict(data) # Convert ImmutableMultiDict to a mutable dict | ||
if 'pages' in mutable_data and isinstance(mutable_data['pages'], str): | ||
mutable_data['pages'] = mutable_data['pages'].split('|') | ||
return mutable_data | ||
|
||
# noinspection PyUnusedLocal | ||
@post_load | ||
# NB: post_load is a marshmallow directive; | ||
# this function is run after loading request args | ||
# it basically pulls the request object value into a Job object | ||
# | ||
# **kwargs is needed here despite what the validator claims | ||
def return_job_object(self, data, **kwargs) -> FetchRefsJobV2: # type: ignore # dead: disable | ||
"""Return Job object""" | ||
from src import app | ||
app.logger.debug("==> FetchRefsSchemaV2::@post_load:return_job_object") | ||
app.logger.debug(f"return_job_object data: {data}") | ||
|
||
job = FetchRefsJobV2(**data) | ||
job.validate_fields() | ||
|
||
# NB here is where we can modify job field values before returning if we want | ||
|
||
return job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.