Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
import os | import os | ||||
import re | import re | ||||
from typing import Any, Dict, List, Optional | from typing import Any, Dict, List, Optional | ||||
import urllib.parse | |||||
from bs4 import BeautifulSoup | from bs4 import BeautifulSoup | ||||
from docutils.core import publish_parts | from docutils.core import publish_parts | ||||
import docutils.parsers.rst | import docutils.parsers.rst | ||||
import docutils.utils | import docutils.utils | ||||
from docutils.writers.html5_polyglot import HTMLTranslator, Writer | from docutils.writers.html5_polyglot import HTMLTranslator, Writer | ||||
from iso8601 import ParseError, parse_date | from iso8601 import ParseError, parse_date | ||||
from pkg_resources import get_distribution | from pkg_resources import get_distribution | ||||
▲ Show 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | Returns: | ||||
The prettified HTML document | The prettified HTML document | ||||
""" | """ | ||||
return BeautifulSoup(html, "lxml").prettify() | return BeautifulSoup(html, "lxml").prettify() | ||||
def _deposits_list_url( | def _deposits_list_url( | ||||
deposits_list_base_url: str, page_size: int, username: Optional[str] | deposits_list_base_url: str, page_size: int, username: Optional[str] | ||||
) -> str: | ) -> str: | ||||
deposits_list_url = f"{deposits_list_base_url}?page_size={page_size}" | params = {"page_size": str(page_size)} | ||||
if username is not None: | if username is not None: | ||||
deposits_list_url += f"&username={username}" | params["username"] = username | ||||
return deposits_list_url | return f"{deposits_list_base_url}?{urllib.parse.urlencode(params)}" | ||||
def get_deposits_list(username: Optional[str] = None) -> List[Dict[str, Any]]: | def get_deposits_list(username: Optional[str] = None) -> List[Dict[str, Any]]: | ||||
"""Return the list of software deposits using swh-deposit API | """Return the list of software deposits using swh-deposit API | ||||
""" | """ | ||||
config = get_config()["deposit"] | config = get_config()["deposit"] | ||||
deposits_list_base_url = config["private_api_url"] + "deposits" | deposits_list_base_url = config["private_api_url"] + "deposits" | ||||
deposits_list_auth = HTTPBasicAuth( | deposits_list_auth = HTTPBasicAuth( | ||||
Show All 32 Lines |