
    h*>                        U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z	d dlZ	d dlZd dlmZ d dlmZmZmZmZmZmZ d dlmZ d dlZd dlZd dlmZ ddlmZmZ dZ dEd	e!d
ee!ejD                  f   de#ddfdZ$dFdee!ejD                  f   de#de!fdZ%dee!ejD                  f   de!dede&fdZ'dGdee!ejD                  f   dee!   de&fdZ(dHd	e!de#de!fdZ)d	e!dee!   fdZ*	 	 	 dId	e!dee!ejD                  f   d
eee!ejD                  f      dee!   de#ddfdZ+dJdee!ejD                  f   de&de,e!   fdZ-dJdee!ejD                  f   de!de&de,e!   fdZ.	 	 dKde!dee!ejD                  f   d
eee!ejD                  f      dee!   fdZ/d ee!ejD                  f   d!ee!ejD                  f   d"ee!   ddfd#Z0ejb                  ejd                  d$Z3e4e!e#f   e5d%<   d ee!ejD                  f   d!ee!ejD                  f   d"ee!   ddfd&Z6e0e6d'Z7e4e!eee!ejD                  f   ee!ejD                  f   ee!   gdf   f   e5d(<   e jp                  ejp                  ejp                  d)Z9e4e!ed*ef   f   e5d+<   d,d,d-d.Z:e4e!e;ee!   ee!   f   f   e5d/<   d0ee!ejD                  f   de;e!ee!   ee!   f   fd1Z<	 	 dLd ee!ejD                  f   d!eee!ejD                  f      d2e&dejD                  fd3Z=	 	 dLd ee!ejD                  f   d!eee!ejD                  f      d2e&dee!ejD                  f   fd4Z>	 	 	 	 dMd	e!d5ee!ejD                  f   d6eee!ejD                  f      d
eee!ejD                  f      dee!   d2e&ddfd7Z?d8ede!fd9Z@ ed:e!eA      ZB	 	 	 dNd;eBd<ee!   d=eeeB      d>ee!   deBf
d?ZCdOd@ee!ejD                  f   dAe#dej                  fdBZEdCej                  dej                  fdDZGy)P    N)Iterable)AnyCallableIOOptionalTypeVarUnion)urlparse)tqdm   )#_download_file_from_remote_location_is_remote_location_availablezpytorch/visionurlfilename
chunk_sizereturnc                    t         j                  j                  t         j                  j                  | dt        i            5 }t        |d      5 }t        |j                  dd      5 }|j                  |      x}r?|j                  |       |j                  t        |             |j                  |      x}r?d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)N
User-AgentheaderswbBT)totalunit
unit_scale)urllibrequesturlopenRequest
USER_AGENTopenr   lengthreadwriteupdatelen)r   r   r   responsefhpbarchunks          X/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/torchvision/datasets/utils.py_urlretriever,      s    			 6 6s\S]D^ 6 _	` (dl(D! 	(RHOO#Z^)_ 	(cg#==44%4CJ' $==44%4	( 	(( (	( 	( 	( 	(( (s=   C/C#+AC>C#C/C C##C,	(C//C8fpathc                    t        j                  d      }t        | d      5 }|j                  |      x}r%|j	                  |       |j                  |      x}r%d d d        |j                         S # 1 sw Y   |j                         S xY w)NF)usedforsecurityrb)hashlibmd5r!   r#   r%   	hexdigest)r-   r   r2   fr*   s        r+   calculate_md5r5   #   s     ++e
,C	eT	 avvj))e)JJu vvj))e) ==? ==?s   8A44Br2   kwargsc                      |t        | fi |k(  S N)r5   )r-   r2   r6   s      r+   	check_md5r9   .   s    -0000    c                 `    t         j                  j                  |       sy|yt        | |      S )NFT)ospathisfiler9   )r-   r2   s     r+   check_integrityr?   2   s*    77>>% 
{UC  r:   max_hopsc           	      v   | }dt         d}t        |dz         D ]}  }t        j                  j	                  t        j                  j                  | |            5 }|j                  | k(  s|j                  | cd d d        c S |j                  } d d d         t        d| d| d|  d      # 1 sw Y   xY w)	NHEAD)Methodr      r   zRequest to z
 exceeded z( redirects. The last redirect points to .)r    ranger   r   r   r   r   RecursionError)r   r@   initial_urlr   _r'   s         r+   _get_redirect_urlrJ   :   s    Kz:G8a<  	
^^##FNN$:$:3$:$PQ 	U]||s"hll&:	 	 ,,C		 		
 +j
:bcfbgghi
 	
	 	s   B/B//B8	c                     t        |       }t        j                  d|j                        y t        j                  d|j                        }|y |j                  d      S )Nz(drive|docs)[.]google[.]comz/file/d/(?P<id>[^/]*)id)r
   rematchnetlocr=   group)r   partsrN   s      r+   _get_google_drive_file_idrR   J   sP    SME	xx.=EHH-uzz:E};;tr:   rootmax_redirect_hopsc                    t         j                  j                  |      }|st         j                  j                  |       }t        j                  t         j                  j                  ||            }t        j                  |d       t        ||      ryt               rt        ||        n5t        | |      } t        |       }|t        ||||      S 	 t        | |       t        ||      st'        d	      y# t        j                  j                   t"        f$ r3}| dd dk(  r| j%                  dd      } t        | |       n|Y d}~id}~ww xY w)
a  Download a file from a url and place it in root.

    Args:
        url (str): URL to download file from
        root (str): Directory to place downloaded file in
        filename (str, optional): Name to save the file under. If None, use the basename of the URL
        md5 (str, optional): MD5 checksum of the download. If None, do not check
        max_redirect_hops (int, optional): Maximum number of redirect hops allowed
    Texist_okN)r@      httpszhttps:zhttp:File not found or corrupted.)r<   r=   
expanduserbasenamefspathjoinmakedirsr?   r   r   rJ   rR   download_file_from_google_driver,   r   errorURLErrorOSErrorreplaceRuntimeError)r   rS   r   r2   rT   r-   file_ides           r+   download_urlrh   W   s*     77d#D77##C(IIbggll423EKKt$ uc"$&+E37  .?@ ,C027D(CPP	e$ 5#&9:: ' %%w/ 	2Aw'!kk(G4S%( )	s   C< <#E)EEprefixc           	      z   t         j                  j                  |       } t        j                  |       D cg c]B  }t         j                  j	                  t         j                  j                  | |            sA|D }}|du r-|D cg c]"  }t         j                  j                  | |      $ }}|S c c}w c c}w )a  List all directories at a given root

    Args:
        root (str): Path to directory whose folders need to be listed
        prefix (bool, optional): If true, prepends the path to each result, otherwise
            only returns the name of the directories found
    T)r<   r=   r[   listdirisdirr^   )rS   ri   pdirectoriesds        r+   list_dirrp      s     77d#D jj.W"''--TST@U2V1WKW~6ABrww||D!,BB XBs   AB3:B3'B8suffixc           	         t         j                  j                  |       } t        j                  |       D cg c]T  }t         j                  j	                  t         j                  j                  | |            sA|j                  |      sS|V }}|du r-|D cg c]"  }t         j                  j                  | |      $ }}|S c c}w c c}w )a  List all files ending with a suffix at a given root

    Args:
        root (str): Path to directory whose folders need to be listed
        suffix (str or tuple): Suffix of the files to match, e.g. '.png' or ('.jpg', '.png').
            It uses the Python "str.endswith" method and is passed directly
        prefix (bool, optional): If true, prepends the path to each result, otherwise
            only returns the name of the files found
    T)r<   r=   r[   rk   r>   r^   endswith)rS   rq   ri   rm   filesro   s         r+   
list_filesru      s     77d#D

4(i1BGGNN277<<a;P,QVWV`V`agVhQiEi~0561dA&66L j6s   AC:CC'C
rf   c                    	 ddl }t        j                  j                  |      }|s| }t        j                  t        j                  j                  ||            }t        j                  |d       t        ||      ry|j                  | |dt               t        ||      st        d      y# t        $ r t        d      w xY w)	af  Download a Google Drive file from  and place it in root.

    Args:
        file_id (str): id of file to be downloaded
        root (str): Directory to place downloaded file in
        filename (str, optional): Name to save the file under. If None, use the id of the file.
        md5 (str, optional): MD5 checksum of the download. If None, do not check
    r   Nz`To download files from GDrive, 'gdown' is required. You can install it with 'pip install gdown'.TrV   F)rL   outputquiet
user_agentrZ   )gdownModuleNotFoundErrorre   r<   r=   r[   r]   r^   r_   r?   downloadr    )rf   rS   r   r2   rz   r-   s         r+   r`   r`      s    
 77d#DIIbggll423EKKt$uc"	NNge5ZNP5#&9:: '#  
n
 	

s   B1 1C	from_pathto_pathcompressionc                     t        j                  | |rd|dd   nd      5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nzr:rD   r)tarfiler!   
extractall)r}   r~   r   tars       r+   _extract_tarr      sH     
i;2k!"o%6!7C	P  TWw     s	   <A).bz2.xz_ZIP_COMPRESSION_MAPc                     t        j                  | d|r	t        |   nt         j                        5 }|j	                  |       d d d        y # 1 sw Y   y xY w)Nr   )r   )zipfileZipFiler   
ZIP_STOREDr   )r}   r~   r   zips       r+   _extract_zipr      sL     
3$8$EZaZlZl
  	w     s   AA).tarz.zip_ARCHIVE_EXTRACTORS)r   .gzr   ._COMPRESSED_FILE_OPENERS)r   r   )r   r   )z.tbzz.tbz2z.tgz_FILE_TYPE_ALIASESfilec                    t        j                  |       j                  }|st        d|  d      |d   }|t        v r|gt        |   S |t
        v r||dfS |t        v r(t        |      dkD  r|d   }|t
        v r||z   ||fS |d|fS t        t        t              t        t
              z  t        t              z        }t        d| d| d	      )
a  Detect the archive type and/or compression of a file.

    Args:
        file (str): the filename

    Returns:
        (tuple): tuple of suffix, archive type, and compression

    Raises:
        RuntimeError: if file has no suffix or suffix is not supported
    zFile 'zP' has no suffixes that could be used to detect the archive type and compression.NrD   z&Unknown compression or archive type: 'z'.
Known suffixes are: 'z'.)
pathlibPathsuffixesre   r   r   r   r&   sortedset)r   r   rq   suffix2valid_suffixess        r+   _detect_file_typer      s    ||D!**HTFjk
 	
 b\F ##4+F344 $$vt## ))x=1rlG --'&88tV##C 23c:M6NNQTUmQnnoN
?xG`ao`pprs
ttr:   remove_finishedc                    t        |       \  }}}|st        d| d      |<t        j                  t	        j
                  |       j                  |||nd            }t        |   } || d      5 }t        |d      5 }|j                  |j                                ddd       ddd       |rt	        j                  |        t        j                  |      S # 1 sw Y   =xY w# 1 sw Y   AxY w)a  Decompress a file.

    The compression is automatically detected from the file name.

    Args:
        from_path (str): Path to the file to be decompressed.
        to_path (str): Path to the decompressed file. If omitted, ``from_path`` without compression extension is used.
        remove_finished (bool): If ``True``, remove the file after the extraction.

    Returns:
        (str): Path to the decompressed file.
    z*Couldn't detect a compression from suffix rE   N r0   r   )r   re   r   r   r<   r]   rd   r   r!   r$   r#   remove)	r}   r~   r   rq   archive_typer   compressed_file_openerrfhwfhs	            r+   _decompressr   "  s    " ):)(D%FL+GxqQRR,,ryy3;;FT`TlLrtuv 6kB		4	0 Cgt9L PS		#((*  
		)<<     s$   1C&> CC&C#	C&&C/c           
          dt         j                  dt        t        t         j                  f   f fd}|t        j
                  j                         }t               \  }}}|sat         t        j
                  j                  |t        j
                  j                         j                  |d            |      } ||      S t        |   } | ||       |rt	        j                           |t        j                  |            S )aD  Extract an archive.

    The archive type and a possible compression is automatically detected from the file name. If the file is compressed
    but not an archive the call is dispatched to :func:`decompress`.

    Args:
        from_path (str): Path to the file to be extracted.
        to_path (str): Path to the directory the file will be extracted to. If omitted, the directory of the file is
            used.
        remove_finished (bool): If ``True``, remove the file after the extraction.

    Returns:
        (str): Path to the directory the file was extracted to.
    ret_pathr   c                 R    t        t              rt        j                  |       S | S r8   )
isinstancestrr<   r]   )r   r}   s    r+   path_or_strz$extract_archive.<locals>.path_or_strZ  s!    i%99X&&Or:   r   )r   )r   r   r	   r   r<   r=   dirnamer   r   r^   r\   rd   r   r   )	r}   r~   r   r   rq   r   r   r   	extractors	   `        r+   extract_archiver   F  s    (gll uS',,5F/G  ''//),(9)(D%FL+GGLL"''"2"29"="E"Efb"QR+

 8$$ $L1Ii+.
		)w||G,--r:   download_rootextract_rootc                    t         j                  j                  |      }||}|st         j                  j                  |       }t	        | |||       t         j                  j                  ||      }t        |||       y r8   )r<   r=   r[   r\   rh   r^   r   )r   r   r   r   r2   r   archives          r+   download_and_extract_archiver   v  sh     GG&&}5M$77##C(mXs3ggll=(3GG\?;r:   iterablec           	      h    ddj                  | D cg c]  }t        |       c}      z   dz   S c c}w )N'z', ')r^   r   )r   items     r+   iterable_to_strr     s-    H=Dc$i=>>DD=s   /
Tvalueargvalid_values
custom_msgc                    t        | t              s.|d}nd}|j                  t        |       |      }t	        |      || S | |vr9||}t	        |      d}|j                  | |t        |            }t	        |      | S )Nz'Expected type str, but got type {type}.z:Expected type str for argument {arg}, but got type {type}.)typer   zPUnknown value '{value}' for argument {arg}. Valid values are {{{valid_values}}}.)r   r   r   )r   r   formatr   
ValueErrorr   )r   r   r   r   msgs        r+   verify_str_argr     s     eS!;;CNCjjd5ksj3oL !C o eC**5cP\@]*^CoLr:   	file_nameslice_channelsc                    t        | d      5 }|j                         j                         }|dvrt        d      t	        j
                  d|j                               }|st        d      d |j                         D        \  }}t        |j                         j                               }|dk  rd}| }nd	}t        j                  ||d
z         }	ddd       dk(  rdnd}
	j                  |
      j                  ddd      }	t        j                  |	d      }	|	d|ddddf   }	|	j                  t        j                        S # 1 sw Y   zxY w)aD  Read file in .pfm format. Might contain either 1 or 3 channels of data.

    Args:
        file_name (str): Path to the file.
        slice_channels (int): Number of channels to slice out of the file.
            Useful for reading different data formats stored in .pfm files: Optical Flows, Stereo Disparity Maps, etc.
    r0   )   PFs   PfzInvalid PFM files   ^(\d+)\s(\d+)\s$zMalformed PFM header.c              3   2   K   | ]  }t        |        y wr8   )int).0dims     r+   	<genexpr>z_read_pfm.<locals>.<genexpr>  s     7SC7s   r   <>r4   )dtypeNr      rD   r   )axis)r!   readlinerstripr   rM   rN   	Exceptiongroupsfloatnpfromfilereshape	transposeflipastypefloat32)r   r   r4   header	dim_matchwhscaleendiandatapfm_channelss              r+   	_read_pfmr     s7    
i	 2!$$&'/00HH11::<@	3447I$4$4$671ajjl))+,19FFEF{{1FSL1#2& %1QL<<1l+55aA>D774a DA%&D;;rzz""12 2s   CEEtc                 >     | j                         j                  t        j                        j                  g | j                  | j                          j                  d      j                  g | j                  d d d j                  | j                        S )Nr   )
contiguousviewtorchuint8shapeelement_sizer   r   )r   s    r+   _flip_byte_orderr     s    W-EKK(--IqwwI8HINNrRWWjYZY`Y`adbdYejgijoopqpwpwxr:   )i   )i   r8   )r   )NNr   )F)NN)NF)NNNF)NNN)r   )Hbz2gzipr1   lzmar<   os.pathr   rM   r   r   urllib.errorurllib.requestr   collections.abcr   typingr   r   r   r   r   r	   urllib.parser
   numpyr   r   torch.utils.model_zoor   _internally_replaced_utilsr   r   r    r   r   r   r,   r5   boolr9   r?   rJ   rR   rh   listrp   ru   r`   r   	ZIP_BZIP2ZIP_LZMAr   dict__annotations__r   r   r!   r   r   tupler   r   r   r   r   bytesr   r   ndarrayr   Tensorr    r:   r+   <module>r
     s   
    	   	      $ > > !   & k
(c (U3+<%= (3 (_c (sGLL01 s UX 1U3,- 1C 13 14 1!5gll!23 !(3- !SW !
3 
# 
c 
 
3 
8C= 
  482;	2;
W\\!
"2; uS',,./02; 
#	2;
 2; 
2;j5gll*+ T d3i U3,- s D UYZ]U^ ( 48	";";
W\\!
""; uS',,./0"; 
#	";J S',,&' 27W\\8I2J YabeYf 	  ( d38n  S',,&' 27W\\8I2J YabeYf 	  w T#xsGLL/@)A5gllIZC[]efi]j(kmq(qrrs 
 HH9999: $sHS"W$556  F DeHSM8C=$@AAB (uE#w||"34 (usHSMS[\_S`?`9a (uZ 37!!!S',,&'!!eC-./!! !! \\	!!L 37!-.S',,&'-.eC-./-. -. 3	-.f 8<37!<	<gll*+< 5gll!234< uS',,./0	<
 
#< < 
<(Eh E3 E Ce
 *. $		# 8A;' 	
 8!#sGLL01 !#3 !#rzz !#H  r:   