
    ܖijN                     
   d dl mZ d dlmZ d dlmZ dZ	 dFdZ e       Z e       Zd Z	d Z
d Zd	 Ze
Ze
Zej                  d
      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d      d        Zej                  d       d!        Zej                  d"      d#        Zej                  d$      d%        Zej                  d
      d&        Zej                  d      d'        Zej                  d      d(        Z ej                  d$      d)        Z!ej                  d      d*        Z"ej                  d      d+        Z#ej                  ddd      d,        Z$ej                  d-      d.        Z%ej                  d       d/        Z&ej                  d0      d1        Z'ej                  d2      d3        Z(ej                  d4      d5        Z)ej                  d6      d7        Z*ej                  d8      d9        Z+d:e,d;e,fd<Z-ej                  d=      d>e,d;e,fd?       Z.ej                  d@      dA        Z/dB Z0dCe,d;e,fdDZ1yE)G    )
PackageURL)NoRouteAvailable)Routerz$https://repo.maven.apache.org/maven2c                     |dvrt        d      d| d| d| d| d| d| d| d| d	| d| d
| d| d| d| d}|j                  |       S )z_
    Return the download URL for a hosted git repository given a package type
    or None.
    )ziptar.gzz,Only zip and tar.gz extensions are supportedhttps://github.com//	/archive/.https://bitbucket.org/z/get/https://gitlab.com/z/-/archive/-)github	bitbucketgitlab)
ValueErrorget)type	namespacenameversionarchive_extensiondownload_url_by_types         _/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/packageurl/contrib/purl2url.py%get_repo_download_url_by_package_typer   "   s      11GHH (	{!D67)1M^L_`-i[$uWIQO`Nab'	{!D6WIQtfTUV]U^^_`q_rs
  ##D))    c                 J    |r	 | j                  |      S y # t        $ r Y y w xY w)N)processr   )routerpurls     r   _get_url_from_routerr"   8   s2    	>>$''    		s    	""c                 "    t        t        |       S )zB
    Return a repository URL inferred from the `purl` string.
    )r"   repo_routerr!   s    r   get_repo_urlr&   @   s      T22r   c                     t        t        |       }|r|S t        j                  |       }|j                  j                  dd      S )z@
    Return a download URL inferred from the `purl` string.
    download_urlN)r"   download_routerr   from_string
qualifiersr   )r!   r(   	purl_datas      r   get_download_urlr-   G   sD     (>L &&t,I##ND99r   c                 h    t         t        f}g }|D ]  } ||       }|s|j                  |         |S )zK
    Return all inferred URLs (repo, download) from the `purl` string.
    )r&   r-   append)r!   url_functionsinferred_urlsurl_funcurls        r   get_inferred_urlsr4   T   sI    
 	M
 M! &tn  %&
 r   zpkg:cargo/.*c                     t        j                  |       }|j                  }|j                  }|r
|rd| d| S |rd| S y)z9
    Return a cargo repo URL from the `purl` string.
    zhttps://crates.io/crates/r
   Nr   r*   r   r   r!   r,   r   r   s       r   build_cargo_repo_urlr8   k   sU    
 &&t,I>>DG*4&';;	*4&11 
r   zpkg:bitbucket/.*c                 x    t        j                  |       }|j                  }|j                  }|r|rd| d| S yy)z=
    Return a bitbucket repo URL from the `purl` string.
    r   r
   Nr   r*   r   r   r!   r,   r   r   s       r   build_bitbucket_repo_urlr<   {   sG    
 &&t,I##I>>D	'	{!D6:: tr   zpkg:github/.*c                     t        j                  |       }|j                  }|j                  }|j                  }|j
                  }|r|syd| d| }|r|j                  dd      }| d| | }|S )z:
    Return a github repo URL from the `purl` string.
    Nr	   r
   version_prefix z/tree/)r   r*   r   r   r   r+   r   )r!   r,   r   r   r   r+   repo_urlr>   s           r   build_github_repo_urlrA      s    
 &&t,I##I>>DG%%JY$YKq7H#(8"=Zvn%5gY?Or   zpkg:gitlab/.*c                 x    t        j                  |       }|j                  }|j                  }|r|rd| d| S yy)z:
    Return a gitlab repo URL from the `purl` string.
    r   r
   Nr:   r;   s       r   build_gitlab_repo_urlrC      sG    
 &&t,I##I>>D	$YKq77 tr   zpkg:(gem|rubygems)/.*c                     t        j                  |       }|j                  }|j                  }|r
|rd| d| S |rd| S y)z<
    Return a rubygems repo URL from the `purl` string.
    zhttps://rubygems.org/gems/z
/versions/Nr6   r7   s       r   build_rubygems_repo_urlrE      sU    
 &&t,I>>DG+D6G9EE	+D622 
r   zpkg:cran/.*c                 n    t        j                  |       }|j                  }|j                  }d| d| dS )z8
    Return a cran repo URL from the `purl` string.
    z'https://cran.r-project.org/src/contrib/_.tar.gzr6   r7   s       r   build_cran_repo_urlrI      s=    
 &&t,I>>DG4TF!G9GLLr   z
pkg:npm/.*c                     t        j                  |       }|j                  }|j                  }|j                  }d}|r|| dz  }|| z  }|r|d| z  }|S )z7
    Return a npm repo URL from the `purl` string.
    zhttps://www.npmjs.com/package/r
   z/v/r   r*   r   r   r   )r!   r,   r   r   r   r@   s         r   build_npm_repo_urlrL      so    
 &&t,I##I>>DG/HykO#4&Hc'O#Or   zpkg:pypi/.*c                     t        j                  |       }|j                  xs dj                  dd      }|j                  }|r|r	d| d| dS |rd| dS y)z8
    Return a pypi repo URL from the `purl` string.
    r?   rG   r   zhttps://pypi.org/project/r
   N)r   r*   r   replacer   r7   s       r   build_pypi_repo_urlrO      sk    
 &&t,INN b))#s3DG*4&'!<<	*4&22 
r   zpkg:composer/.*c                     t        j                  |       }|j                  }|j                  }|j                  }|r|rd| d| d| S |rd| d| S y)z<
    Return a composer repo URL from the `purl` string.
    zhttps://packagist.org/packages/r
   #Nr   r*   r   r   r   r!   r,   r   r   r   s        r   build_composer_repo_urlrT      sl    
 &&t,I>>DG##I01TF!G9MM	01TFCC 
r   zpkg:nuget/.*c                     t        j                  |       }|j                  }|j                  }|r
|rd| d| S |rd| S y)z9
    Return a nuget repo URL from the `purl` string.
    zhttps://www.nuget.org/packages/r
   Nr6   r7   s       r   build_nuget_repo_urlrV     sU    
 &&t,I>>DG0ayAA	077 
r   zpkg:hackage/.*c                     t        j                  |       }|j                  }|j                  }|r
|rd| d| S |rd| S y)z;
    Return a hackage repo URL from the `purl` string.
    $https://hackage.haskell.org/package/r   Nr6   r7   s       r   build_hackage_repo_urlrY     sU    
 &&t,I>>DG5dV1WIFF	5dV<< 
r   zpkg:golang/.*c                     t        j                  |       }|j                  }|j                  }|j                  }|r|rd| d| d| S |rd| d| S y)z:
    Return a golang repo URL from the `purl` string.
    zhttps://pkg.go.dev/r
   @NrK   )r!   r,   r   r   r   s        r   build_golang_repo_urlr\   $  sl    
 &&t,I##I>>DG$YKqayAA	$YKq77 
r   zpkg:cocoapods/.*c                 V    t        j                  |       }|j                  }|xr d| S )z=
    Return a CocoaPods repo URL from the `purl` string.
    zhttps://cocoapods.org/pods/)r   r*   r   )r!   r,   r   s      r   build_cocoapods_repo_urlr^   5  s0    
 &&t,I>>D81$88r   zpkg:maven/.*c                    t        j                  |       }|j                  }|j                  }|j                  }|j
                  }|j                  dt              }|r%|r"|r|j                  dd      }| d| d| d| S yyy)z9
    Return a Maven repo URL from the `purl` string.
    repository_urlr   r
   N	r   r*   r   r   r   r+   r   DEFAULT_MAVEN_REPOSITORYrN   )r!   r,   r   r   r   r+   base_urls          r   build_maven_repo_urlrd   ?  s    
 &&t,I##I>>DG%%J~~.0HIHTg%%c3/	1YKqay99 &Tyr   c                 z    t        j                  |       }|j                  }|j                  }|r|r	d| d| dS yy)z=
    Return a cargo download URL from the `purl` string.
    z https://crates.io/api/v1/crates/r
   z	/downloadNr6   r7   s       r   build_cargo_download_urlrf   T  sI    
 &&t,I>>DG1$q	KK tr   c                 z    t        j                  |       }|j                  }|j                  }|r|r	d| d| dS yy)z@
    Return a rubygems download URL from the `purl` string.
    zhttps://rubygems.org/downloads/r   z.gemNr6   r7   s       r   build_rubygems_download_urlrh   b  sI    
 &&t,I>>DG0ayEE tr   c                     t        j                  |       }|j                  }|j                  }|j                  }d}|r|d| z  }|r|r| d| d| d| dS yy)z;
    Return a npm download URL from the `purl` string.
    zhttps://registry.npmjs.orgr
   z/-/r   z.tgzNrK   )r!   r,   r   r   r   rc   s         r   build_npm_download_urlrj   p  sv    
 &&t,I##I>>DG+Ha	{O#1TF#dV1WIT:: tr   c                 v   t        j                  |       }|j                  }|j                  }|j                  }|j
                  }|j                  dt              }|j                  dd      }|j                  d      }|r9|r6|r3|j                  dd      }|rd| nd}| d| d| d| d| d| | d| S y	y	y	)
z=
    Return a maven download URL from the `purl` string.
    r`   r   jar
classifierr   r
   r   r?   Nra   )	r!   r,   r   r   r   r+   rc   
maven_typerm   s	            r   build_maven_download_urlro     s    
 &&t,I##I>>DG%%J~~.0HIH.J-JTg%%c3/	)3q%
1YKqay$q	*UVWaVbcc &Tyr   c           	          t        j                  |       }|j                  }|j                  }|r|rd| d| d| d| d	S yy)z?
    Return a hackage download URL from the `purl` string.
    rX   r   r
   rH   Nr6   r7   s       r   build_hackage_download_urlrq     sV    
 &&t,I>>DG5dV1WIQtfAgYV]^^ tr   c                 x    t        j                  |       }|j                  }|j                  }|r|rd| d| S yy)z=
    Return a nuget download URL from the `purl` string.
    z%https://www.nuget.org/api/v2/package/r
   Nr6   r7   s       r   build_nuget_download_urlrs     sG    
 &&t,I>>DG6tfAgYGG tr   c                     t        |       S )z>
    Return a gitlab download URL from the `purl` string.
    )get_repo_download_urlr%   s    r   build_repo_download_urlrv     s    
 !&&r   z
pkg:hex/.*c                 z    t        j                  |       }|j                  }|j                  }|r|r	d| d| dS yy)z;
    Return a hex download URL from the `purl` string.
    zhttps://repo.hex.pm/tarballs/r   z.tarNr6   r7   s       r   build_hex_download_urlrx     sI    
 &&t,I>>DG.tfAgYdCC tr   c                    t        j                  |       }|j                  }|j                  }|j                  }|sy|r| d| }t        |      }t        |      }|j                  d      sd|z   }|r|r	d| d| dS yy)z>
    Return a golang download URL from the `purl` string.
    Nr
   vzhttps://proxy.golang.org/z/@v/.zip)r   r*   r   r   r   escape_golang_path
startswith)r!   r,   r   r   r   enameeversions          r   build_golang_download_urlr     s    
 &&t,I##I>>DG AdV$t$E!'*Hs#>*5'hZtDD tr   z
pkg:pub/.*c                 z    t        j                  |       }|j                  }|j                  }|r|r	d| d| dS yy)z;
    Return a pub download URL from the `purl` string.
    zhttps://pub.dev/api/archives/r   rH   Nr6   r7   s       r   build_pub_download_urlr     sI    
 &&t,I>>DG.tfAgYgFF tr   zpkg:swift/.*c                     t        j                  |       }|j                  }|j                  }|j                  }|s|s|syd| d| d| dS )zE
    Return a Swift Package download URL from the `purl` string.
    Nzhttps://r
   r   r{   rR   rS   s        r   build_swift_download_urlr     sX    
 &&t,I>>DG##Ii[$y	>>r   zpkg:luarocks/.*c                     t        j                  |       }|j                  xs i }|j                  dd      }|j                  }|j
                  }|r|r| d| d| dS yy)z@
    Return a LuaRocks download URL from the `purl` string.
    r`   zhttps://luarocks.orgr
   r   z	.src.rockN)r   r*   r+   r   r   r   )r!   r,   r+   r`   r   r   s         r   build_luarocks_download_urlr     sp    
 &&t,I%%+J^^$46LMN>>DG !4&')<< tr   zpkg:conda/.*c                    t        j                  |       }|j                  r|j                  sy|j                  xs i }|j                  }|j                  }|j                  d      }|j                  d      xs d}|j                  d      xs d}|j                  d      }dt        dt        fd	}	 |	|      }
|r| d
| d
| d| n	| d
| d| }|
 d| d| }|S )ag  
    Resolve a Conda PURL to a real downloadable URL

    Supported qualifiers:
      - channel: e.g., main, conda-forge (required for deterministic base)
      - subdir: e.g., linux-64, osx-arm64, win-64, noarch
      - build:  exact build string (optional but recommended)
      - type:   'conda' or 'tar.bz2' (preference; fallback to whichever exists)
    Nbuildchannelmainsubdirnoarchr   returnc                 >    | xs dj                         }|dv ryd| S )z
        Map a conda channel to its base URL.
        - 'main' / 'defaults' -> repo.anaconda.com
        - any other channel    -> conda.anaconda.org/<channel>
        r?   )r   defaultsz#https://repo.anaconda.com/pkgs/mainzhttps://conda.anaconda.org/)lower)r   chs     r   _conda_base_for_channelz9build_conda_download_url.<locals>._conda_base_for_channel0  s/     m""$%%8,RD11r   r   r   r
   )r   r*   r   r   r+   r   str)r!   pqr   r   r   r   r   req_typer   basepackage_identifierr(   s                r   build_conda_download_urlr     s     	t$A66	A66DiiGEE'NEeeI(&GUU8_(FuuV}H	2 	2 	2 #7+D 384&'!E7!H:.vQwiqQYPZ=[  V1VHA&8%9:Lr   zpkg:alpm/.*c                     t        j                  |       }|j                  }|j                  }|j                  j                  dd      }|r|sy |d   }d| d| d| d| d| d}|S )Narchanyr   z'https://archive.archlinux.org/packages/r
   r   z.pkg.tar.zst)r   r*   r   r   r+   r   )purl_strr!   r   r   r   first_letterr3   s          r   build_alpm_download_urlr   E  s|    !!(+D99DllG??vu-Dw7L3L>4&$qQXPYYZ[_Z``l
mCJr   r   r   c                 <    d| v r| j                  dd      \  }}|S | S )zd
    Remove the epoch (if any) from a Debian version.
    E.g., "1:2.4.47-2" becomes "2.4.47-2"
    :   )split)r   rG   rz   s      r   normalize_versionr   T  s)    
 g~}}S!$1Nr   z
pkg:deb/.*r   c                    t        j                  |       }|j                  }|j                  }|j                  }|j
                  xs i }|j                  d      }|j                  d      }|r|st        d      |sd}|r|j                  d      }n|dk(  rd}n|dk(  rd	}nt        d
|       t        |      }	|dk(  r	| d|	 d}
n| d|	 d| d}
d|d   j                          d| }| | d|
 S )z}
    Construct a download URL for a Debian or Ubuntu package PURL.
    Supports optional 'repository_url' in qualifiers.
    r   r`   z1Both name and version must be present in deb purlsourcer
   debianzhttps://deb.debian.org/debianubuntuz http://archive.ubuntu.com/ubuntuzUnsupported distro namespace: rG   z.dscz.debz/pool/main/r   )r   r*   r   r   r   r+   r   r   rstripNotImplementedErrorr   r   )r   r   r   r   r   r+   r   r`   rc   norm_versionfilename	pool_paths               r   build_deb_download_urlr   _  s!    	x(A66DiiGI#J>>&!D^^$45NwLMM!((- 6H("9H%(Fyk&RSS$W-LxV1\N$/V1\N!D66d1gmmo.av6IZ	{!H:..r   z
pkg:apk/.*c                 L   t        j                  |       } | j                  }| j                  }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }|r|r|r|r|st        d      d| d| d| d| d| dS )	z
    Return a download URL for a fully qualified Alpine Linux package PURL.

    Example:
    pkg:apk/acct@6.6.4-r0?arch=x86&alpine_version=v3.11&repo=main
    r   repoalpine_versionzXAll qualifiers (arch, repo, alpine_version) and name/version must be present in apk purlz&https://dl-cdn.alpinelinux.org/alpine/r
   r   z.apk)r   r*   r   r   r+   r   r   )r!   r   r   r   r   r   s         r   build_apk_download_urlr     s     !!$'D99DllG??v&D??v&D__(()9:Nwd$nf
 	

 10@$qaPTvUVW^V__cdr   c                 *   t        j                  |       }|j                  }|j                  }|j                  }|j
                  }|j                  }|j                  d      }|r|S |r|r|sy|j                  dd      }| | }t        ||||      S )z
    Return ``download_url`` if present in ``purl`` qualifiers or
    if ``namespace``, ``name`` and ``version`` are present in ``purl``
    else return None.
    r(   Nr>   r?   )r   r   r   r   )	r   r*   r   r   r   r   r+   r   r   )	r!   r,   r   r   r   r   r+   r(   r>   s	            r   ru   ru     s     &&t,I##I>>D>>DG%%J>>.1L$7^^$4b9N 	*G0YT7 r   pathc           	          d}| D ]D  }|dk\  r8|dk  r3|dt        t        |      t        d      z   t        d      z
        z   z  }@||z  }F |S )aH  
    Return an case-encoded module path or version name.

    This is done by replacing every uppercase letter with an exclamation mark followed by the
    corresponding lower-case letter, in order to avoid ambiguity when serving from case-insensitive
    file systems.

    See https://golang.org/ref/mod#goproxy-protocol.
    r?   AZ!a)chrord)r   escaped_pathcs      r   r|   r|     sa     L 8SC#c!fs3x&7#c(&B"CCCLAL r   N)r   )2
packageurlr   packageurl.contrib.router   r   rb   r   r$   r)   r"   r&   r-   r4   purl2urlget_urlrouter8   r<   rA   rC   rE   rI   rL   rO   rT   rV   rY   r\   r^   rd   rf   rh   rj   ro   rq   rs   rv   rx   r   r   r   r   r   r   r   r   r   r   ru   r|    r   r   <module>r      sO  6 " 5 +A  7?*$ h(3
:& 
 >"2 #2 %&
; '
; ?# $. ?#
8 $
8 *+3 ,3 =!	M "	M <  !, =!3 "3 $%D &D  >"8 #8 #$= %= ?#8 $8  %&9 '9 >": #:( ~&
L '
L ./
F 0
F |$; %;& ~&d 'd* '(
_ )
_ ~&
H '
H (:OL' M' |$
D %
D 'E (E6 |$
G %
G ~&? '?  ()= *=" ~&( '(V }% &s s  |$'/S '/S '/ %'/T |$ %0<S S r   