1717from cvss .exceptions import CVSS3MalformedError
1818from cvss .exceptions import CVSS4MalformedError
1919from packageurl import PackageURL
20- from univers .version_constraint import VersionConstraint , validate_comparators
20+ from univers .version_constraint import VersionConstraint
21+ from univers .version_constraint import validate_comparators
2122from univers .version_range import RANGE_CLASS_BY_SCHEMES
2223from univers .versions import InvalidVersion
2324from univers .versions import SemverVersion
@@ -119,7 +120,7 @@ def parse_advisory_data_v3(
119120 )
120121 except Exception as e :
121122 logger .error (
122- f"Invalid Commit Data: repo_url:{ repo_url !r} - commit_hash: { commit_hash } for OSV id: { advisory_id } "
123+ f"Invalid Commit Data: repo_url:{ repo_url !r} - commit_hash: { commit_hash } error: { e } for OSV id: { advisory_id } "
123124 )
124125 continue
125126 for patch_obj in patch_objs :
@@ -183,7 +184,8 @@ def parse_advisory_data_v3(
183184 weaknesses = weaknesses ,
184185 patches = patches ,
185186 url = advisory_url ,
186- original_advisory_text = advisory_text or json .dumps (raw_data , indent = 2 , ensure_ascii = False ),
187+ original_advisory_text = advisory_text
188+ or json .dumps (raw_data , indent = 2 , ensure_ascii = False ),
187189 )
188190 except Exception as e :
189191 logger .error (f"Invalid AdvisoryData for { advisory_id } : { e } " )
@@ -324,8 +326,7 @@ def get_affected_purl(affected_pkg, raw_id):
324326
325327def get_explicit_affected_constraints (affected_pkg , raw_id , supported_ecosystem ):
326328 """
327- Return a univers VersionRange for the ``affected_pkg`` package data mapping
328- or None. Use a ``raw_id`` OSV id and ``supported_ecosystem``.
329+ Return a list of explicit version constraints for the ``affected_pkg`` data.
329330 """
330331 affected_versions = affected_pkg .get ("versions" ) or []
331332 constraints = []
@@ -340,7 +341,6 @@ def get_explicit_affected_constraints(affected_pkg, raw_id, supported_ecosystem)
340341 version_obj = version_range_class .version_class (version )
341342 constraint = VersionConstraint (comparator = "=" , version = version_obj )
342343 constraints .append (constraint )
343- validate_comparators (constraints )
344344 except Exception as e :
345345 logger .error (
346346 f"Invalid VersionConstraint: { version } " f"for OSV id: { raw_id !r} : error:{ e !r} "
@@ -349,25 +349,30 @@ def get_explicit_affected_constraints(affected_pkg, raw_id, supported_ecosystem)
349349 try :
350350 validate_comparators (constraints )
351351 except Exception as e :
352- logger .error (
353- f"InvalidConstraint: { version } " f"for OSV id: { raw_id !r} : error:{ e !r} "
354- )
352+ logger .error (f"InvalidConstraint: { version } " f"for OSV id: { raw_id !r} : error:{ e !r} " )
355353 return constraints
356354
357355
358356def get_version_ranges_constraints (ranges , raw_id , supported_ecosystem ):
359357 """
360- Return a list of unique fixed univers Versions given a ``fixed_range``
361- univers VersionRange and a ``raw_id``.
358+ Return a tuple containing lists of affected constraints, fixed constraints,
359+ introduced commits, and fixed commits
362360 For example::
363- >>> get_version_ranges_constraints(range ={}, raw_id="GHSA-j3f7-7rmc-6wqj", supported_ecosystem="pypi", )
361+ >>> get_version_ranges_constraints(ranges ={}, raw_id="GHSA-j3f7-7rmc-6wqj", supported_ecosystem="pypi")
364362 []
365- >>> get_version_ranges_constraints(
366- ... ranges={"type": "ECOSYSTEM", "events": [{"fixed": "1.7.0"}], },
363+ >>> affected, fixed, intro_commits, fixed_commits = get_version_ranges_constraints(
364+ ... ranges={"type": "ECOSYSTEM", "events": [{"fixed": "1.7.0"}]},
367365 ... raw_id="GHSA-j3f7-7rmc-6wqj",
368366 ... supported_ecosystem="pypi",
369367 ... )
370- [PypiVersion(string='1.7.0')]
368+ >>> affected
369+ [VersionConstraint(comparator='<', version=PypiVersion(string='1.7.0'))]
370+ >>> fixed
371+ [VersionConstraint(comparator='=', version=PypiVersion(string='1.7.0'))]
372+ >>> intro_commits
373+ []
374+ >>> fixed_commits
375+ []
371376 """
372377 fixed_commits = []
373378 intro_commits = []
0 commit comments