+
    4j)                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^RIHtHtHtHtHt ]'       d   ^ RIHt ^ RIHt ^RIH t  . R*Ot!]PD                  ! ]#4      t$ ! R R]%4      t&]! RRR7       ! R R4      4       t']! RRR7       ! R R4      4       t(R R lt)R R lt*R R lt+R R lt,R^R R!/R" R# llt-R$ R% lt.R& R' lt/R( R) lt0R# )+a}  Download every distribution referenced by a finished resolve.

Consumes a :class:`~nab_python.lockfile.LockInput` and writes every
recorded wheel, sdist, and direct-URL archive into a target directory,
verifying the recorded hash.  Local and VCS pins are skipped: their
contents live elsewhere on disk and the lockfile carries no ``sha256``
for them.  An artefact with a local ``file://`` URL (a find-links
index entry or a direct-URL archive) is copied from its on-disk path
rather than fetched over HTTP.

Use as a one-shot from the CLI ``nab download`` command, or
programmatically after :func:`~nab_python.resolve.build_lock_input`.
)annotationsN)	dataclass)Path)TYPE_CHECKING)urlsplit)atomic_write)AsyncSimpleClient)parse_file_url)	HttpError)
ArchivePinIndexPinLocalPin	LockInputVcsPin)Iterable)AsyncHttpTransport)PinShapeDownloadEntryDownloadErrorDownloadResultc                      ] tR t^4tRtRtR# )r   zAA downloaded artefact failed hash verification or the HTTP fetch. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       e/home/user/pdf2html-billing-ledger-validate/.venv/lib/python3.14/site-packages/nab_python/download.pyr   r   4   s    Kr   T)frozenslotsc                  f    ] tR t^8t$ RtR]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R	tR
]R&   RtR	# )r   a  One artefact to fetch into the output directory.

``hash_algo`` is one of ``sha256``, ``sha384``, ``sha512`` and
``digest`` is the recorded hex digest under that algorithm.
The downloader verifies against the first acceptable algorithm the
index published, preferring sha256 over sha384 over sha512.

``local_path`` is set for an artefact read from disk instead of
fetched over ``url``: a wheel or sdist from a local ``file://``
(find-links) index, or a direct-URL archive whose ``url`` is
``file://``.
strpackageversionfilenameurl	hash_algodigestNzPath | None
local_pathr   )r   r   r   r   r   __annotations__r*   r   r   r   r   r   r   8   s1     LLM	HNK"J"r   c                  0    ] tR t^Pt$ RtR]R&   R]R&   RtR# )r   zSummary of a download run.ztuple[Path, ...]writtenskippedr   N)r   r   r   r   r   r+   r   r   r   r   r   r   P   s    $r   c                    V ^8  d   QhRRRR/# )   
lock_inputr   returnIterable[DownloadEntry]r   )formats   "r   __annotate__r5   X   s        y  -D  r   c              #  \  "   \        4       p\        V P                  4       F  p\        V P                  V,          P                  P	                  4       4       FI  w  r4\        W44       F5  pVP                  V9  g   K  VP                  VP                  4       Vx  K7  	  KK  	  K  	  R# 5i)a0  Yield every downloadable artefact referenced by ``lock_input``.

A wheel, sdist, or direct-URL archive for each pin, deduplicated
by URL across the targets the resolve ran against so an artefact
shared by several of them is downloaded once.  Local and VCS pins
carry no downloadable URL and are skipped.
N)setsortedtargetspinsitems_entries_for_pinr'   add)r1   seenlabel	canonicalpinentrys   &     r   iter_artifactsrC   X   s      UD
**+$Z%7%7%>%C%C%I%I%KLNI))999D(HHUYY'K : M ,s   A8B,?-B,c               $    V ^8  d   QhRRRRRR/# )r0   r@   r#   rA   r   r2   r3   r   )r4   s   "r   r5   r5   i   s"       ( 7N r   c           
   #  0  "   \        V\        4      '       d   \        W4       R j  xL
  R # \        V\        4      '       d   VP                  w  r#\        VP                  4      pVP                  R8X  d   \        VP                  4      MR p\        V VP                  \        P                  ! VP                  4      VP                  VVP                  4       VR7      x  R # \        V\        \         34      '       d   R # RV: 2p\#        V4      h L5i)Nfiler$   r%   r&   r'   r(   r)   r*   zunknown pin shape: )
isinstancer   _iter_index_pinr   primary_digestr   r'   schemer	   r   r%   	posixpathbasenamepathlowerr   r   	TypeError)r@   rA   algor)   partsr*   msgs   &&     r   r<   r<   i   s      #x  "9222	C	$	$))!050F^CGG,D
KK''

3<<>!
 	
 
C(F+	,	,#C7+n% 	3s   %DDC-Dc               $    V ^8  d   QhRRRRRR/# )r0   r@   r#   rA   r   r2   r3   r   )r4   s   "r   r5   r5      s"     
 
s 
 
6M 
r   c              #     "   VP                   e   VP                   P                  w  r#\        V VP                  VP                   P                  VP                   P
                  VVP                  4       VP                   P                  R7      x  VP                   F[  pVP                  w  r#\        V VP                  VP                  VP
                  VVP                  4       VP                  R7      x  K]  	  R # 5i)NrG   )	sdistrJ   r   r%   r&   r'   rO   r*   wheels)r@   rA   rQ   r)   wheels   &&   r   rI   rI      s      yyyy//KKYY''		<<>yy++
 	
 ++KK^^		<<>''
 	
 s   C<C>c                    V ^8  d   QhRRRR/# )r0   	artefactslist[DownloadEntry]r2   Noner   )r4   s   "r   r5   r5      s     ( ()< ( (r   c                L   / pV  F  pVP                  VP                  4      pVel   VP                  VP                  8w  dQ   RVP                  : RVP                   RVP                   RVP                   RVP                   R2p\        V4      hW!VP                  &   K  	  R# )a  Refuse two distinct artefacts that would write to one output filename.

Index sdist/wheel filenames embed the package name and version, so they
never collide.  A direct-URL archive's filename is the bare basename of
its URL, which is arbitrary: two archives from different repositories
commonly share one (e.g. a GitHub ``v1.0.0.tar.gz`` tag tarball).  Two
artefacts with different digests but the same basename would clobber each
other in the flat output dir, silently dropping one, so refuse it loudly.
Nz%artefacts collide on output filename : ==z and z/ differ. Download them to separate directories.)getr&   r)   r$   r%   r   )rZ   by_namerB   priorrS   s   &    r   _reject_colliding_targetsrc      s     )+GENN+!=77I JMM?"U]]O 4MM?"U]]O 4::   $$"' r   max_concurrencyofflineFc               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r0   r1   r   	transportr   
output_dirr   rd   intre   boolr2   r   r   )r4   s   "r   r5   r5      sD      ! 
   r   c          
         VP                  RRR7       \        \        V 4      4      p\        V4       \        P
                  ! \        WQW#VR7      4      # )a  Download every artefact in ``lock_input`` into ``output_dir``.

Already-present files whose digest matches the recorded
algorithm are left alone so the command is idempotent.
Mismatched files are re-fetched and overwritten.  HTTP failures
and post-download hash mismatches both raise
:class:`DownloadError` after the fetcher has shut down.

``offline`` refuses any artefact that would need an HTTP fetch;
already-present files and local ``file://`` artefacts are still
served.
T)parentsexist_okre   )mkdirlistrC   rc   asynciorun_run_downloads)r1   rg   rh   rd   re   rZ   s   &&&$$ r   download_lockrt      sN    ( TD1^J/0Ii(;;*w	
 r   c               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r0   rZ   r[   rg   r   rh   r   rd   ri   re   rj   r2   r   r   )r4   s   "r   r5   r5      sL     5J 5J"5J!5J 5J 	5J 5J 5Jr   c                 aaa	a
aa"   \         P                  ! V4      o
\        V4      o	. o. oR  V	VVV
VV3R llpV  Uu. uF  p\         P                  ! V! V4      4      NK!  	  pp \         P                  ! V!  G Rj  xL
   S	P                  4       G Rj  xL
  \        \        S4      \        S4      R7      # u upi  LA  \
         dS    T F+  pTP                  4       '       d   K  TP                  4        K-  	  \         P                  ! TRR/ G Rj  xL 
  h i ; i L  S	P                  4       G Rj  xL 
  i ; i5i)c                    V ^8  d   QhRRRR/# )r0   rB   r   r2   r\   r   )r4   s   "r   r5   $_run_downloads.<locals>.__annotate__   s     , ,- ,D ,r   c                H  <"   S;_uu_4       GR j  xL
  V P                   '       d/   \        V P                   4      P                  V P                   8w  d5   V P                   RV P                   RV P                   : 2p\        V4      hSV P                   ,          p\        W P                  V P                  4      '       dP   S	P                  V4       \        P                  RV P                   V P                  4        R R R 4      GR j  xL
  R # \        V SSR7      G R j  xL
 p\        P                  ! V P                  V4      P                  4       pW@P                  8w  dQ   V P                   RV P                   RV P                   RV P                    RV P                   RV 2p\        V4      h\!        W#4       S
P                  V4       \        P                  R	V4       R R R 4      GR j  xL
  R #  EL L L L  + GR j  xL 
 '       g   i     R # ; i5i)
Nr_   z: unsafe artefact filename: zskip %s (%s matches)rn   r^   z mismatch for z
  expected: z
  actual:   zwrote %s)r&   r   namer$   r%   r   _already_presentr(   r)   appendloggerinfo_fetch_byteshashlibnew	hexdigestr   )rB   rS   targetdataactualclientre   rh   semr.   r-   s   &    r   _one_run_downloads.<locals>._one   s    33 >>>T%..%9%>%>%..%P}}oR 7227..1CE  $C((%..0FFFv&2ENNEOOT 33 &eVWEED[[$7AACF%}}oRb8I$U^^$4 5##(<<.vhH 
 $C((&NN6"KK
F+5 33 F 333s|   H"G<H"C+HH"G?H"H$H%CH*H"5H6H"?H"HH"H	H
H	H		H"Nreturn_exceptionsT)r-   r.   )rq   	Semaphorer   create_taskgatherBaseExceptiondonecancelacloser   tuple)rZ   rg   rh   rd   re   r   ataskstr   r   r.   r-   s   &&f&d    @@@@r   rs   rs      s      

O
,Cy)FGG, ,: 4==9aW  a)9E=	nne$$$ mmo%.%.II >$ A6688
  nne<t<<< 	fmmosw   8E %B<%E(C ?C C ED#(EC #D +-D DD  D% #E%E 9D<:E  Ec               (    V ^8  d   QhRRRRRRRR/# )	r0   rB   r   r   r   re   rj   r2   bytesr   )r4   s   "r   r5   r5     s,     * **"3*AE*
*r   c          
     b  "   V P                   e    V P                   P                  4       # V'       d5   V P                   RV P                   RV P
                   R2p\        V4      h VP                  V P                  4      G Rj  xL
 #   \         dJ   pT P                   RT P                   RT P
                   RT P                    RT 2	p\        T4      ThRp?ii ; i L[  \         d=   pT P                   RT P                   RT P
                   RT 2p\        T4      ThRp?ii ; i5i)	zsRead a local artefact from disk, else fetch it over HTTP.

``offline`` refuses the HTTP half rather than fetching.
Nr_   z: failed to read z from r^   z.: artefact fetch unavailable in offline mode ()z: failed to fetch )
r*   
read_bytesOSErrorr$   r%   r&   r   downloadr'   r
   )rB   r   re   excrS   s   &&$  r   r   r     s<     #	.##..00 }}oR /!!& 03 	 C  *__UYY///  	.==/EMM? 3NN#6%*:*:);2cUD   $#-	. 0 *}}oR.@@PPRSVRWX 	 C c)	*sc   D/B D/4D/)C% C#C% D/C ACC  D/#C% %D,07D''D,,D/c               (    V ^8  d   QhRRRRRRRR/# )r0   r   r   rQ   r#   expected_digestr2   rj   r   )r4   s   "r   r5   r5   *  s.     Q QT Q Qs Qt Qr   c                    V P                  4       '       g   R # \        P                  ! WP                  4       4      P	                  4       V8H  # )F)existsr   r   r   r   )r   rQ   r   s   &&&r   r{   r{   *  s6    ==??;;t..01;;=PPr   )r   r   r   rt   rC   )1r   
__future__r   rq   r   loggingrL   dataclassesr   pathlibr   typingr   urllib.parser   nab_index.atomicr   nab_index.clientr   nab_index.local_indexr	   nab_index.transportr
   lockfiler   r   r   r   r   collections.abcr   r   r   __all__	getLoggerr   r}   	Exceptionr   r   r   rC   r<   rI   rc   rt   rs   r   r{   r   r   r   <module>r      s    #     !    ! ) . 0 ) G G(6" 
		8	$LI L $d## # $#. $d#  $ "2
6(0
  <5Jp*>Qr   