MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / update_purl_version

Function update_purl_version

vulnerabilities/utils.py:157–173  ·  view source on GitHub ↗

Return a new PackageURL derived from the ``purl`` PackageURL object or string with the new version. For example:: >>> purl = PackageURL.from_string("pkg:generic/this@1.2.3") >>> evolved = PackageURL.from_string("pkg:generic/this@2.2.3") >>> update_purl_version(purl, version

(purl, version)

Source from the content-addressed store, hash-verified

155
156
157def update_purl_version(purl, version):
158 """
159 Return a new PackageURL derived from the ``purl`` PackageURL object or string
160 with the new version.
161
162 For example::
163 >>> purl = PackageURL.from_string("pkg:generic/this@1.2.3")
164 >>> evolved = PackageURL.from_string("pkg:generic/this@2.2.3")
165 >>> update_purl_version(purl, version="2.2.3") == evolved
166 True
167 """
168 purl = normalize_purl(purl=purl)
169 if not version:
170 return purl
171 merged = purl.to_dict()
172 merged["version"] = version
173 return normalize_purl(PackageURL(**merged))
174
175
176def nearest_patched_package(

Callers 5

get_fixed_purlMethod · 0.90
get_exact_purlsFunction · 0.90
get_affected_purlsFunction · 0.90
get_exact_purl_from_versFunction · 0.90

Calls 2

normalize_purlFunction · 0.85
to_dictMethod · 0.45

Tested by

no test coverage detected