Skip to content

Commit

Permalink
Move CachedLimiterSession to utils
Browse files Browse the repository at this point in the history
Signed-off-by: Henri Rosten <[email protected]>
  • Loading branch information
henrirosten committed Dec 4, 2023
1 parent 7dfa8aa commit c7575b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
13 changes: 12 additions & 1 deletion src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

# pylint: disable=invalid-name
# pylint: disable=invalid-name, abstract-method

""" sbomnix utils """

Expand All @@ -19,6 +19,10 @@
from colorlog import ColoredFormatter, default_log_colors
import pandas as pd

from requests import Session
from requests_cache import CacheMixin
from requests_ratelimiter import LimiterMixin

###############################################################################

LOG_SPAM = logging.DEBUG - 1
Expand Down Expand Up @@ -280,6 +284,13 @@ def check_positive(val):
return intval


class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
"""
Session class with caching and rate-limiting
https://requests-cache.readthedocs.io/en/stable/user_guide/compatibility.html
"""


################################################################################

set_log_verbosity(1)
Expand Down
12 changes: 2 additions & 10 deletions src/repology/repology_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

# pylint: disable=invalid-name, import-error, unexpected-keyword-arg,
# pylint: disable=abstract-method, too-few-public-methods, too-many-statements
# pylint: disable=too-few-public-methods, too-many-statements
# pylint: disable=too-many-instance-attributes, too-many-locals,

""" Command-line interface to repology.org """
Expand All @@ -16,9 +16,6 @@
import re
import urllib.parse
from argparse import ArgumentParser, ArgumentTypeError, SUPPRESS
from requests import Session
from requests_cache import CacheMixin
from requests_ratelimiter import LimiterMixin
from bs4 import BeautifulSoup
import numpy as np
import pandas as pd
Expand All @@ -32,6 +29,7 @@
df_regex_filter,
nix_to_repology_pkg_name,
parse_version,
CachedLimiterSession,
)

###############################################################################
Expand Down Expand Up @@ -104,12 +102,6 @@ def getargs(args=None):
################################################################################


class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
"""Session class with caching and rate-limiting"""

# See: https://requests-cache.readthedocs.io/en/stable/user_guide/compatibility.html


class Repology:
"""Query and parse Repology package data"""

Expand Down
12 changes: 2 additions & 10 deletions src/repology/repology_cve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# SPDX-License-Identifier: Apache-2.0

# pylint: disable=invalid-name abstract-method too-many-locals
# pylint: disable=invalid-name too-many-locals

""" Command-line interface to query CVE info from repology.org """

Expand All @@ -13,9 +13,6 @@
import re
import urllib.parse
from argparse import ArgumentParser, ArgumentTypeError
from requests import Session
from requests_cache import CacheMixin
from requests_ratelimiter import LimiterMixin
from bs4 import BeautifulSoup
import numpy as np
import pandas as pd
Expand All @@ -27,6 +24,7 @@
set_log_verbosity,
df_to_csv_file,
parse_version,
CachedLimiterSession,
)

###############################################################################
Expand Down Expand Up @@ -60,12 +58,6 @@ def getargs():
################################################################################


class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
"""Session class with caching and rate-limiting"""

# See: https://requests-cache.readthedocs.io/en/stable/user_guide/compatibility.html


def _parse_cve_resp(resp, pkg_name, pkg_version):
soup = BeautifulSoup(resp.text, "html.parser")
tables = soup.find_all("table")
Expand Down
10 changes: 2 additions & 8 deletions src/vulnxscan/vulnxscan_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

# pylint: disable=invalid-name, import-error, too-many-arguments
# pylint: disable=singleton-comparison, abstract-method
# pylint: disable=singleton-comparison
# pylint: disable=too-many-return-statements

"""
Expand All @@ -25,9 +25,6 @@
from tempfile import NamedTemporaryFile
from shutil import which

from requests import Session
from requests_cache import CacheMixin
from requests_ratelimiter import LimiterMixin
import pandas as pd
import numpy as np

Expand All @@ -49,6 +46,7 @@
nix_to_repology_pkg_name,
parse_version,
version_distance,
CachedLimiterSession,
)

###############################################################################
Expand Down Expand Up @@ -393,10 +391,6 @@ def report(self, args, sbom_csv):
# Triage


class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
"""Session class with caching and rate-limiting"""


_repology_cve_dfs = {}
_repology_cli_dfs = {}
# Rate-limited and cached session. For github api rate limits, see:
Expand Down

0 comments on commit c7575b5

Please sign in to comment.