
    dfw+                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZ 	 d dlZdZn# e$ r dZY nw xY w	 d dlZdZn# e$ r dZY nw xY w G d	 d
e          Z G d de          ZdS )    N)apps)serializers)BaseCommandCommandError)parse_apps_and_model_labels)DEFAULT_DB_ALIASrouterTFc                       e Zd ZdS )ProxyModelWarningN)__name__
__module____qualname__     dD:\Python Project\djangoTemplates\venv\Lib\site-packages\django/core/management/commands/dumpdata.pyr   r      s        Dr   r   c                       e Zd ZdZd Zd ZdS )CommandzOutput the contents of the database as a fixture of the given format (using each model's default manager unless --all is specified).c                    |                     dddd           |                     ddd	           |                     d
t          d           |                     dt          d	           |                     dddg d           |                     dddd           |                     dddd           |                     ddddd           |                     d d!d"#           |                     d$d%d&'           d S )(Nargszapp_label[.ModelName]*zHRestricts dumped data to the specified app_label or app_label.ModelName.)metavarnargshelpz--formatjsonz7Specifies the output serialization format for fixtures.)defaultr   z--indentz>Specifies the indent level to use when pretty-printing output.)typer   z
--databasezXNominates a specific database to dump fixtures from. Defaults to the "default" database.z-ez	--excludeappendzhAn app_label or app_label.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).)actionr   r   z--natural-foreign
store_trueuse_natural_foreign_keysz/Use natural foreign keys if they are available.)r   destr   z--natural-primaryuse_natural_primary_keysz/Use natural primary keys if they are available.z-az--alluse_base_managerzUse Django's base manager to dump all models stored in the database, including those that would otherwise be filtered or modified by a custom manager.z--pksprimary_keyszOnly dump objects with given primary keys. Accepts a comma-separated list of keys. This option only works when you specify one model.)r!   r   z-oz--outputz.Specifies file to which the output is written.)r   )add_argumentintr   )selfparsers     r   add_argumentszCommand.add_arguments$   s   +' 	 	
 	
 	
 	J 	 	
 	
 	

 	Q 	 	
 	
 	

 	$2 	 	
 	
 	
 	H 	 	
 	
 	
 	+B	 	 	
 	
 	
 	+B	 	 	
 	
 	
 	#" 	 
	
 
	
 
	
 	O 	 	
 	
 	
 	*#S 	 	
 	
 	
 	
 	
r   c           
      r	   !" |d         }|d         }|d         "|d         }|d         }|d         }|d         !|d         }|d	          |d
         }	|	r d |	                     d          D             ng t          |          \  |sJrt          d          t                              fdt          j                    D                       n{t          |          dk    rrt          d          i |D ]Q}
	 |
                     d          \  }}	 t          j        |          }n.# t          $ r!}t          t          |                    d }~ww xY w|j        |v rl	 |                    |          }n## t          $ r t          d|d|          w xY w                    |g           }|||vr|                    |           # t          $ rn rt          d          |
}	 t          j        |          }n.# t          $ r!}t          t          |                    d }~ww xY w|j        |v rY Gd |<   Y Ow xY w|t!          j                    vr=	 t!          j        |           n# t           j        $ r Y nw xY wt          d|z            d# !"fd	}	 d | j        _        d }d}|rE| j                                        r,|d         dk    r | j        }t/           |d                    }|r!t0          j                            |          \  }}t6          i |ft8          j        i |ft6          i |ft6          i |ft6          i |fd}t:          rt<          j        i |f|d<   t>          r0t@          j        dt@          j!        i|f|d<   t@          j        i |f|d<   	 ||         \  }}}n# tD          $ r t6          i |}}}Y nw xY w||k    r@t0          j        #                    |          }tI          j%        d| d| dtL                      ||d fi |}nd }	 t!          j'        | |            |!||p| j        ||!           |r|(                                 d S d S # |r|(                                 w w xY w# tR          $ r}|r t          d"|z            d }~ww xY w)$Nformatindentdatabaseexcludeoutput	tracebackr    r"   r#   r$   c                 6    g | ]}|                                 S r   )strip).0pks     r   
<listcomp>z"Command.handle.<locals>.<listcomp>t   s     @@@2BHHJJ@@@r   ,z,You can only use --pks option with one modelc              3   2   K   | ]}|j         |v|V  d S )N)models_module)r3   
app_configexcluded_appss     r   	<genexpr>z!Command.handle.<locals>.<genexpr>}   sE       % %+7m33  4333	% %r      .zUnknown model: z Unknown serialization format: %sFc              3   Z  K   r)t          j                                        d          }n[g }                                D ]D\  }}|(|                    |                                           /|                    |           E|D ]}|	v r|j        j        r6|j        j        |vr(t          j	        d|j        j
        z  t                     |j        j        st          j        |          rr|j        }n|j        }|                                                  |j        j        j                  }
r|                    
          }| r)|                                                                V  |j        rdnd}|                    |          E d{V  dS )	z
            Collate the objects to be serialized. If count_only is True, just
            count the number of objects to be serialized.
            T)allow_cyclesNz,%s is a proxy model and won't be serialized.)category)pk__ini  )
chunk_size)r   sort_dependenciesitemsextend
get_models_metaproxyproxy_for_modelwarningswarnlabelr   r	   allow_migrate_model_base_manager_default_managerusingorder_byr4   namefiltercount_prefetch_related_lookupsiterator)
count_onlymodelsr9   
model_listmodelobjectsquerysetrB   app_listexcluded_modelsr$   r#   r    rP   s           r   get_objectsz#Command.handle.<locals>.get_objects   s      
 ( 2$6NN$$4   .6nn.>.> 2 2*J
!)j&;&;&=&=>>>>j1111 L LO++;$ )DF)R)RMF++,!2   
 {( LV-Gu-U-U L' 9"'"5"'"8&}}U33<<U[^=PQQH# H#+??,?#G#G! L&//1177999999 %-$FPDDD # $,#4#4
#4#K#KKKKKKKK1L Lr   r   	verbosityT)rW   ).bz2z.gz.lzma.xzz.zipra   rb   rc   zUnsupported file extension (z). Fixtures saved in 'z'.wt)r,   r    r"   streamprogress_outputobject_countz Unable to serialize database: %s)F)*splitr   r   dictfromkeysr   get_app_configslenget_app_configLookupErrorstrr8   	get_model
setdefaultr   
ValueErrorr   get_public_serializer_formatsget_serializerSerializerDoesNotExiststdoutendingisattysumospathsplitextopengziphas_bz2bz2has_lzmalzmaFORMAT_ALONEKeyErrorbasenamerJ   rK   RuntimeWarning	serializeclose	Exception)#r'   
app_labelsoptionsr+   r,   excludesr/   show_tracebackr"   pksrL   	app_labelmodel_labelr9   erZ   app_list_valuer_   rf   rg   	file_rootfile_extcompression_formatsopen_methodkwargs	file_path	file_namere   r]   r:   r^   r$   r#   r    rP   s#                               @@@@@@@r   handlezCommand.handleg   su   ""
#9%" -#*+E#F #*+E#F "#56n% 	@@3@@@LLL)DX)N)N& 1	0 S"#QRRR}} % % % %"&"6"8"8% % %  HH :""|""#QRRRH# $0 $0#0-2[[-=-=*I{3%)%8%C%C

& 3 3 3*3q662223!/7:;V;V  * 4 4[ A A&   *l6?iiM  
 &.%8%8R%H%HN
 &1e>6Q6Q&--e444! 0 0 0# *J   !&I3%)%8%C%C

& 3 3 3*3q662223!/7:;V;V +/HZ(((0" BDDDD*622225    AFJKKK*	L *	L *	L *	L *	L *	L *	L *	L *	L *	L *	LX9	G!%DK"OL A$+,,.. A7;3G!3K3K"&+";;$#?#?#?@@ &(g&6&6v&>&>#	8!2y1 Ir62"B	2 "i0!2y1' '#  I368R2H'/ I	!4#454'0
 37)R1H'.H5H5R2K H H H6:BKKKH&& " 0 0 ; ;IM<x < <.7< < <&  
 %Y????#%KMM!-E-E!0T[$3!-	 	 	 	  #LLNNNNN# #6 #LLNNNN# 	G 	G 	G AAEFFF	Gs   GD43G4
E>EEG/FG F%%4GI8HI
H8H33H88I	II+J   JJ3DR 5O R OR OAR 1+Q6 R 6RR 
R6R11R6N)r   r   r   r   r)   r   r   r   r   r   r      sK        	J 	
A
 A
 A
FuG uG uG uG uGr   r   )r~   rz   rJ   django.appsr   django.corer   django.core.management.baser   r   django.core.management.utilsr   	django.dbr   r	   r   r   ImportErrorr   r   Warningr   r   r   r   r   <module>r      sj    				        # # # # # # A A A A A A A A D D D D D D . . . . . . . .JJJGG   GGGKKKHH   HHH	 	 	 	 	 	 	 	~G ~G ~G ~G ~Gk ~G ~G ~G ~G ~Gs!   7 A AA AA