2828from packageurl import PackageURL
2929
3030
31- def purl_to_lookups (purl_str , encode = True ):
31+ def purl_to_lookups (purl_str , encode = True , include_empty_fields = False ):
3232 """
33- Return a lookups dict built from the provided `purl` string.
34- Those lookups can be used as QuerySet filters.
33+ Return a lookups dictionary built from the provided `purl` (Package URL) string.
34+ These lookups can be used as QuerySet filters.
35+ If include_empty_fields is provided, the resulting dictionary will include fields
36+ with empty values. This is useful to get exact match.
37+ Note that empty values are always returned as empty strings as the model fields
38+ are defined with `blank=True` and `null=False`.
3539 """
3640 if not purl_str .startswith ("pkg:" ):
3741 purl_str = "pkg:" + purl_str
@@ -41,8 +45,11 @@ def purl_to_lookups(purl_str, encode=True):
4145 except ValueError :
4246 return # Not a valid PackageURL
4347
44- package_url_dict = package_url .to_dict (encode = encode )
45- return without_empty_values (package_url_dict )
48+ package_url_dict = package_url .to_dict (encode = encode , empty = "" )
49+ if include_empty_fields :
50+ return package_url_dict
51+ else :
52+ return without_empty_values (package_url_dict )
4653
4754
4855def without_empty_values (input_dict ):
0 commit comments