
    !hw                    \   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJrJrJrJr  S SKJr  S SKJr  S S	KJr  S S
KJr  \(       a  S SKJrJrJrJr  \S.     SS jjrSS jr  S     SS jjrSSS jjr SSS jjr!SSS jjr"      SS jr#SS.       S S jjr$g)!    )annotationsN)ConfigParser)
itemgetter)Path)TYPE_CHECKINGAnyCallablecast)
UsageError)BaseSettings)update_classpath)without_none_values)
CollectionIterableMappingMutableMapping)convertc                  ^^ SU4S jjmSUU4S jjnSS jnU" U 5        [        U" U 5      5      n [        U R                  5       [        S5      S9 VVs/ s H  u  pEUPM	     snn$ s  snnf )	zgCompose a component list from a :ref:`component priority dictionary
<component-priority-dictionaries>`.c                   > [        U  Vs1 s H  nT" U5      iM     sn5      [        U 5      :w  a  [        SU < S35      eg s  snf )NSome paths in 8 convert to the same object, please update your settings)len
ValueError)complistcr   s     X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/utils/conf.py_check_components/build_component_list.<locals>._check_components   sN    H-Hq
H-.#h-?  -. .  @-s   Ac                  > [        U [        5      (       a  [        5       nU R                  5        Hs  u  p#U R                  U5      nUc   eUR                  T" U5      5      U:X  a'  [	        S[        U R                  5       5      < S35      eUR                  T" U5      X4S9  Mu     U$ T" U 5        U R                  5        VVs0 s H  u  p#T" U5      U_M     snn$ s  snnf )Nr   r   )priority)
isinstancer   itemsgetpriorityr   listkeysset)compdictcompbskvprior   r   s        r   	_map_keys'build_component_list.<locals>._map_keys#   s    h--!^F (++A.'''%%gaj1T9$(hmmo)>(A B> > 
 

71:q
8 ) M(#*2..*:;*:$!
A*:;;;s   Cc                    U R                  5        H;  u  pUc  M
  [        U[        R                  5      (       a  M+  [	        SU SU S35      e   g)zDFail if a value in the components dict is not a real number or None.NzInvalid value z for component z., please provide a real number or None instead)r"   r!   numbersRealr   )r'   namevalues      r   _validate_values.build_component_list.<locals>._validate_values4   sR    #>>+KD E7<<)H)H $UG?4& AC C  ,       )key)r   zCollection[Any]returnNone)r'   Mapping[Any, Any]r8   zBaseSettings | dict[Any, Any])r'   r:   r8   r9   )r   sortedr"   r   )r'   r   r,   r3   r)   r*   r   s    `    @r   build_component_listr<      s^    < <" X"9X#67H !1z!}EFE$!AEFFFs   A(c                &    [        S U  5       5      $ )zKConvert a list of arguments like ['arg1=val1', 'arg2=val2', ...] to a
dict
c              3  D   #    U  H  oR                  S S5      v   M     g7f)=r6   N)split).0xs     r   	<genexpr>"arglist_to_dict.<locals>.<genexpr>F   s     1AQs    )dict)arglists    r   arglist_to_dictrG   B   s     1111r5   c                    Ub  [        U 5      [        U5      :X  a  g[        U 5      R                  5       n U S-  nUR                  5       (       a  [        U5      $ [	        U R
                  U 5      $ )zcReturn the path to the closest scrapy.cfg file by traversing the current
directory and its parents
 
scrapy.cfg)strr   resolveexistsclosest_scrapy_cfgparent)pathprevpathcfgfiles      r   rN   rN   I   s`     D	S] ::D\!G~~7|dkk400r5   c                d   [        5       nUR                  SU 5      (       a#  UR                  SU 5      [        R                  S'   [        5       nU(       a[  [        [        U5      R                  5      nU(       a5  U[        R                  ;  a   [        R                  R                  U5        gggg)zInitialize environment to use command-line tool from inside a project
dir. This sets the Scrapy settings module and modifies the Python path to
be able to locate the project module.
settingsSCRAPY_SETTINGS_MODULEN)
get_config
has_optiongetosenvironrN   rK   r   rO   sysrP   append)projectset_syspathcfgclosestprojdirs        r   init_envrb   Y   s    
 ,C
~~j'**/2wwz7/K

+, "Gd7m**+7#((2HHOOG$ 3; r5   c                R    [        U 5      n[        5       nUR                  U5        U$ )z(Get Scrapy config file as a ConfigParser)get_sourcesr   read)use_closestsourcesr_   s      r   rV   rV   h   s$    +&G
.CHHWJr5   c                :   [         R                  R                  S5      =(       d    [        S5      R	                  5       nSS[        [        U5      S-  5      [        [        S5      R	                  5       5      /nU (       a  UR                  [        5       5        U$ )NXDG_CONFIG_HOMEz	~/.configz/etc/scrapy.cfgzc:\scrapy\scrapy.cfgrJ   z~/.scrapy.cfg)rY   rZ   rX   r   
expanduserrK   r\   rN   )rf   xdg_config_homerg   s      r   rd   rd   p   s|    


()KT+->-I-I-K  	D!L01D!,,./	G )+,Nr5   c                   U R                  5       nUR                  SUR                  S5      5        UR                  SUS   5        UR                  SUR                  S5      =(       d    S 5        UR                  SUR	                  S5      5        UR                  S	US
   5        UR                  S0 5        US   c  UR                  SS 5        U$ UR                  SUR                  S5      5        U$ )Nbatch_item_countFEED_EXPORT_BATCH_ITEM_COUNTencodingFEED_EXPORT_ENCODINGfieldsFEED_EXPORT_FIELDSstore_emptyFEED_STORE_EMPTY
uri_paramsFEED_URI_PARAMSitem_export_kwargsFEED_EXPORT_INDENTindent)copy
setdefaultgetintgetdictorlistgetbool)feedrT   outs      r   *feed_complete_default_values_from_settingsr      s     ))+CNN%x7U'VWNN:x(>?@NN8X334HIQTRNN=("2"23E"FGNN<*;!<=NN',$%-x& J 	x1E!FGJr5   )overwrite_outputc               2  ^	 [        [        [        [        [        4   U R	                  S5      5      5      R                  5       m	SU	4S jjnSnU(       a  U(       a  [        S5      eUnSn0 nU HF  n UR                  SS5      u  pxU" U5        US:X  a  S	nU" U5        SU0XW'   U(       d  M?  SXW   S'   MH     UR                  U R                  S5      5        U$ ! [        [        4 a*    Un[        U5      R                  R                  S
S5      n N}f = f)z
Receives feed export params (from the 'crawl' or 'runspider' commands),
checks for inconsistencies in their quantities and returns a dictionary
suitable to be used as the FEEDS setting.
FEED_EXPORTERSc                H   > U T;  a  [        SU  S[        T5       S35      eg )NzUnrecognized output format 'z'. Set a supported one (z`) after a colon at the end of the output URI (i.e. -o/-O <URI>:<FORMAT>) or as a file extension.)r   tuple)output_formatvalid_output_formatss    r   check_valid_format8feed_process_params_from_cli.<locals>.check_valid_format   sA     44.}o >((-.B(C'D E::  5r5   Fz<Please use only one of -o/--output and -O/--overwrite-outputT:r6   -zstdout:.rI   format	overwriteFEEDS)r   rK   r8   r9   )r   r
   rE   rK   getwithbaser%   r   rsplitr   r   suffixreplaceupdategetdict)
rT   outputr   r   r   resultelementfeed_urifeed_formatr   s
            @r   feed_process_params_from_clir      s     +>T#s(^X112BCD+
df  IN  "	(*F	%$+NN3$:!H{+
 3$;'$k29,0F[)   MM(""7+,M J' 	@Hw-..66sB?K	@s   4C7DD)r'   zMutableMapping[Any, Any]r   zCallable[[Any], Any]r8   z	list[Any])rF   	list[str]r8   zdict[str, str])r   N)rP   zstr | os.PathLikerQ   zstr | os.PathLike | Noner8   rK   )defaultT)r]   rK   r^   boolr8   r9   )T)rf   r   r8   r   )rf   r   r8   r   )r   dict[str, Any]rT   r   r8   r   )rT   r   r   r   r   zlist[str] | Noner8   zdict[str, dict[str, Any]])%
__future__r   r/   rY   r[   configparserr   operatorr   pathlibr   typingr   r   r	   r
   scrapy.exceptionsr   scrapy.settingsr   scrapy.utils.deprecater   scrapy.utils.pythonr   collections.abcr   r   r   r   r<   rG   rN   rb   rV   rd   r   r    r5   r   <module>r      s    "  	 
 %   5 5 ( ( 3 3MM %5+G&+G "+G 	+G\2 ")-1
1&1 	1 %
$0* *.	444 '	4
 4r5   