
    ܖi*                         d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 dZ G d d      Z G d	 d
eej                        Z G d dej                        Zy)    )ValidationError)models)gettext_lazy)
PackageURL)purl_to_lookups)type	namespacenameversion
qualifierssubpathc                   0    e Zd ZdZddZd Zd Zd Zd Zy)	PackageURLQuerySetMixinzK
    Add Package URL filtering methods to a django.db.models.QuerySet.
    c                 f    t        |||      }|r | j                  di |S | j                         S )ao  
        Filter the QuerySet based on a Package URL (purl) string with an option for
        exact match filtering.

        When `exact_match` is False (default), the method will match any purl with the
        same base fields as `purl_str` and allow variations in other fields.
        When `exact_match` is True, only the identical purl will be returned.
        )purl_strencodeinclude_empty_fields )r   filternone)selfr   r   exact_matchlookupss        d/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/packageurl/contrib/django/models.pyfor_package_urlz'PackageURLQuerySetMixin.for_package_url*   s:     "f;
 4;;)))yy{    c                 ~    | j                  t        j                  d       t        j                  d       z        S )z(Return objects with Package URL defined. r   r
   r   r   Qr   s    r   with_package_urlz(PackageURLQuerySetMixin.with_package_url:   s.    {{FHH"--r1B0BBCCr   c                 z    | j                  t        j                  d      t        j                  d      z        S )z&Return objects with empty Package URL.r   r   r    r!   r#   s    r   without_package_urlz+PackageURLQuerySetMixin.without_package_url>   s(    {{688,vxxR/@@AAr   c                 "    | j                         S )zDReturn objects with empty Package URL. Alias of without_package_url.)r&   r#   s    r   empty_package_urlz)PackageURLQuerySetMixin.empty_package_urlB   s    ''))r   c                 (     | j                   t         S )zOrder by Package URL fields.)order_byPACKAGE_URL_FIELDSr#   s    r   order_by_package_urlz,PackageURLQuerySetMixin.order_by_package_urlF   s    t}}011r   N)TF)	__name__
__module____qualname____doc__r   r$   r&   r(   r,   r   r   r   r   r   %   s"     DB*2r   r   c                       e Zd Zy)PackageURLQuerySetN)r-   r.   r/   r   r   r   r2   r2   K   s    r   r2   c                      e Zd ZdZ ej
                  dd ed            Z ej
                  dd ed            Z ej
                  dd ed	            Z	 ej
                  dd ed
            Z
 ej
                  dd ed            Z ej
                  dd ed            Zej                         Z G d d      Zed        Zd Zd Zy)PackageURLMixinz?
    Abstract Model for Package URL "purl" fields support.
       TzA short code to identify the type of this package. For example: gem for a Rubygem, docker for a container, pypi for a Python Wheel or Egg, maven for a Maven Jar, deb for a Debian package, etc.)
max_lengthblank	help_text   zaPackage name prefix, such as Maven groupid, Docker image owner, GitHub user or organization, etc.d   zName of the package.zVersion of the package.i   zYExtra qualifying data for a package such as the name of an OS, architecture, distro, etc.   z=Extra subpath within a package, relative to the package root.c                       e Zd ZdZy)PackageURLMixin.MetaTN)r-   r.   r/   abstractr   r   r   Metar=      s    r   r?   c                 X    	 | j                         }t        |      S # t        $ r Y yw xY w)z7
        Return the Package URL "purl" string.
        r   )get_package_url
ValueErrorstr)r   package_urls     r   rD   zPackageURLMixin.package_url   s6    
	..0K ;  		s    	))c                     t        | j                  | j                  | j                  | j                  | j
                  | j                        S )z.
        Get the PackageURL instance.
        )r   r   r	   r
   r   r   r   r#   s    r   rA   zPackageURLMixin.get_package_url   s;     IINNIILLOOLL
 	
r   c                 \   t        |t              st        j                  |      }|j                  dd      }|j	                         D ]a  \  }}| j
                  j                  |      }|r2t        |      |j                  kD  rt        d| d      }t        |      t        | ||       c y)a3  
        Set each field values to the values of the provided `package_url` string
        or PackageURL object.
        Existing values are always overwritten, forcing the new value or an
        empty string on all the `package_url` fields since we do not want to
        keep any previous values.
        Tr   )r   emptyzValue too long for field "z".N)
isinstancer   from_stringto_dictitems_meta	get_fieldlenr6   _r   setattr)r   rD   package_url_dict
field_namevaluemodel_fieldmessages          r   set_package_urlzPackageURLMixin.set_package_url   s     +z2$00=K&..d".E!1!7!7!9 	-J**..z:KUk&<&<<8BGH%g..D*e,	-r   N)r-   r.   r/   r0   r   	CharFieldrO   r   r	   r
   r   r   r   r2   
as_managerobjectsr?   propertyrD   rA   rV   r   r   r   r4   r4   O   s    6-
	D !  0
I 6*+D f-.G "!!)
J fSTG !++-G  	  	 
-r   r4   N)django.core.exceptionsr   	django.dbr   django.utils.translationr   rO   
packageurlr   packageurl.contrib.django.utilsr   r+   r   QuerySetr2   Modelr4   r   r   r   <module>rb      sL   6 3  6 ! ;V #2 #2L	0&// 	e-fll e-r   