
    x-j#                        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g Zej                            d          Z ej        eej                  s	  e	j                    Zej                            eddd          Zd Z ee           d ZddZd	 Zd
ej        fdZej        fdZddZdS )    N~z.cachepaddledatasetc                     	 t          j        t                     d S # t          $ r!}|j        t          j        k    r Y d }~d S d }~ww xY wN)osmakedirs	DATA_HOMEOSErrorerrnoEEXIST)pathexcs     U/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/dataset/common.pymust_mkdirsr   6   sb    
I   9$$ %$$$$$s    
AAAc                     t          j                    }t          | d          t          fdd          D ]}|                    |                                            |                                S )Nrbc                  .                          d          S )N   )read)fs   r   <lambda>zmd5file.<locals>.<lambda>D   s    affTll     r   )hashlibmd5openiterupdateclose	hexdigest)fnamehash_md5chunkr   s      @r   md5filer$   A   st    {}}HUDA****C00  GGIIIr   c                 ,   t          j        d|                                          }t          |t                    r't          j        d|                                          }t
          j                            t          |          }t
          j        	                    |          st          j
        |           t
          j                            |||                     d          d         n|          }t
          j        	                    |          rt          |          |k    r|S d}d}t
          j        	                    |          rt          |          |k    sst
          j        	                    |          r3t          j                            dt          |           d| d	           ||k     r|d
z  }nt!          d|  d|           t          j                            d| d|  d           t          j                            d           	 t#          j        d| d d          5 }|j                            d          }	|	Ct+          |d          5 }
t-          j        |j        |
           d d d            n# 1 swxY w Y   nt+          |d          5 }
d}t3          |	          }	|	|z  d
z   }|dk    r|dz  nd
}d}t4          j        j                            |d          }|                    |          D ]P}|
                    |           |d
z  }|                    |i            ||z  dk    r|                    |           Q	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   n# t@          $ r}Y d }~jd }~ww xY wt
          j        	                    |          _t          |          |k    st          j                            d           t          j!        "                                 |S )Nz^[a-zA-Z0-9_/\-]+$z^(?:(?!\.\.)[a-zA-Z0-9_/\.-])+$/r      zfile z  md5 
   zCannot download z within retry limit zCache file z not found, downloading z 
zBegin to download
GETT)timeoutfollow_redirectszcontent-lengthwbr      item)name)
chunk_sizez
Download finished
)#rematchgroup
isinstancestrr   r   joinr
   existsr	   splitr$   sysstderrwriteRuntimeErrorhttpxstreamheadersgetr   shutilcopyfileobjrawintr   hapiprogressbarProgressBar
iter_bytesr   	Exceptionstdoutflush)urlmodule_namemd5sum	save_namedirnamefilenameretryretry_limitrtotal_lengthr   r2   
total_iterlog_interval	log_indexbardataes                     r   downloadr^   J   s   (0+>>DDFFK)S!! H0)
 

%'' 	 gll9k22G7>>'"" 
Gw||y'83##i H 
w~~h GH$5$5$?$?EKw~~h'' +GH,=,=,G,G7>>(## 	JJHWX%6%6HHfHHHIII;QJEEI3IIKII   	
D(DDCDDD	
 	
 	
 	
.///	sD4   6 y}}-=>>'h-- 5*15!4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 h-- 6%)
'*<'8'8%1J%>%B
0:RJ",,Q % %&	$k5AA&V B   %&LLJL$G$G 6 6DGGDMMM%NIJJy"555(<71<< #

9 5 5 566 6 6 6 6 6 6 6 6 6 6 6 6 6 66 6 6 6 6 6 6 6 6 6 6 6 6 6 64  	 	 	HHHH	S w~~h'' +GH,=,=,G,GX J,---JOs   N 5-M?"J	=M?	J	M?J	M?%B6M(M?(M,	,M?/M,	0M?3N ?NN NN 
N N c                      d t          t          j                  D             D ]Q} dt          t          j        d|                      v r)t          j        d|                                             Rd S )Nc                 <    g | ]}|                     d           |S )__)
startswith).0xs     r   
<listcomp>zfetch_all.<locals>.<listcomp>   s9       all4.@.@	  r   fetchzpaddle.dataset.)dirr   r   	importlibimport_modulerf   )rO   s    r   	fetch_allrj      s     v~&&   M M c#$Ck$C$CDD
 
 
 
 #$Ck$C$CDDJJLLLM Mr   z%05d.picklec                    t          |          st          d          g }d}t           |                       D ]g\  }}|                    |           ||k    rG||z  dk    r>t	          ||z  d          5 } |||           g }|dz  }ddd           n# 1 swxY w Y   h|r:t	          ||z  d          5 } |||           ddd           dS # 1 swxY w Y   dS dS )a  
    you can call the function as:

    split(paddle.dataset.cifar.train10(), line_count=1000,
        suffix="imikolov-train-%05d.pickle")

    the output files as:

    |-imikolov-train-00000.pickle
    |-imikolov-train-00001.pickle
    |- ...
    |-imikolov-train-00480.pickle

    :param reader: is a reader creator
    :param line_count: line count for each file
    :param suffix: the suffix for the output files, should contain "%d"
                means the id for each file. Default is "%05d.pickle"
    :param dumper: is a callable function that dump object to file, this
                function will be called as dumper(obj, f) and obj is the object
                will be dumped, f is a file object. Default is cPickle.dump.
    zdumper should be callable.r   wr*   N)callable	TypeError	enumerateappendr   )	reader
line_countsuffixdumperlinesindex_fidr   s	            r   r:   r:      s   , F 64555EG&&((##  1Q
??q:~22fw&,, ua   1                &7"C(( 	AF5!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s$   6BB	B	7CCCc                       fd}|S )a  
    Create a reader that yield element from the given files, select
    a file set according trainer count and trainer_id

    :param files_pattern: the files which generating by split(...)
    :param trainer_count: total trainer count
    :param trainer_id: the trainer rank id
    :param loader: is a callable function that load object from file, this
                function will be called as loader(f) and f is a file object.
                Default is cPickle.load
    c               3     K   t                    st          d          t          j                  } |                                  g }t	          |           D ]5\  }}|z  	k    r't          d|            |                    |           6|D ]=}t          |d          5 } |          }|E d {V  d d d            n# 1 swxY w Y   >d S )Nzloader should be callable.zappend file: rV   )rm   rn   globsortro   printrp   r   )
	file_listmy_file_listidxfnr   ru   files_patternloadertrainer_count
trainer_ids
         r   rq   z$cluster_files_reader.<locals>.reader   s@      	:8999Im,,	 ++ 	( 	(GC]"j00*b**+++##B''' 	! 	!Bb# !!q		        ! ! ! ! ! ! ! ! ! ! ! ! ! ! !	! 	!s   %CC		C		 )r   r   r   r   rq   s   ```` r   cluster_files_readerr      s5    ! ! ! ! ! ! ! ! Mr   Tc                     | r!t           j                            |           r| S |r&t          j        j                            |||          S t          |  d          )Nz& not exists and auto download disabled)r   r   r9   r   r   commonr^   
ValueError)r   rN   r   rO   r^   s        r   _check_exists_and_downloadr      sa     t$$  J~$--c;DDDDHHHIIIr   r   )T)r   r{   r   rh   r   pickler3   rC   r;   tempfiler?   r   paddle.dataset__all__r   
expanduserHOMEaccessW_OK
gettempdirr8   r
   r   r$   r^   rj   dumpr:   loadr   r   r   r   r   <module>r      s          				  				  



       
	w# ryrw ! 8  DGLLx9==	   I        A A A AHM M M &36; # # # #N 6<[   BJ J J J J Jr   