lint: annotated dumpgenerator.api

pull/475/head
Misty 1 year ago
parent 2154ead2be
commit 62ace721aa

@ -1,3 +1,4 @@
from typing import *
import re
import time
from urllib.parse import urlparse, urlunparse, urljoin
@ -9,7 +10,7 @@ from .get_json import getJSON
from wikiteam3.utils import getUserAgent
def checkAPI(api=None, session=None):
def checkAPI(api="", session: requests.Session=None):
"""Checking API availability"""
global cj
# handle redirects
@ -29,9 +30,9 @@ def checkAPI(api=None, session=None):
print(
"MediaWiki API URL not found or giving error: HTTP %d" % r.status_code
)
return False
return None
if "MediaWiki API is not enabled for this site." in r.text:
return False
return None
try:
result = getJSON(r)
index = None
@ -48,11 +49,11 @@ def checkAPI(api=None, session=None):
except ValueError:
print(repr(r.text))
print("MediaWiki API returned data we could not parse")
return False
return False
return None
return None
def mwGetAPIAndIndex(url="", session=None):
def mwGetAPIAndIndex(url="", session: requests.Session=None):
"""Returns the MediaWiki API and Index.php"""
api = ""
@ -111,7 +112,7 @@ def mwGetAPIAndIndex(url="", session=None):
return api, index
def checkRetryAPI(api=None, apiclient=False, session=None):
def checkRetryAPI(api="", apiclient=False, session: requests.Session=None):
"""Call checkAPI and mwclient if necessary"""
check = None
try:

@ -1,4 +1,7 @@
def getJSON(request):
import requests
def getJSON(request: requests.Response):
"""Strip Unicode BOM"""
if request.text.startswith("\ufeff"):
request.encoding = "utf-8-sig"

@ -1,7 +1,9 @@
import re
import requests
def checkIndex(index=None, cookies=None, session=None):
def checkIndex(index="", cookies="", session: requests.Session=None):
"""Checking index.php availability"""
r = session.post(url=index, data={"title": "Special:Version"}, timeout=30)
if r.status_code >= 400:

@ -5,7 +5,7 @@ import requests
from wikiteam3.utils import getUserAgent
def getWikiEngine(url="", session=None) -> str:
def getWikiEngine(url="", session: requests.Session=None) -> str:
"""Returns the wiki engine of a URL, if known"""
if not session:

Loading…
Cancel
Save