
    3 dk                         d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZmZ  G d	 d
          Z G d de          Z G d dej                  ZdS )z 
Base class for Scrapy commands
    N)Path)AnyDictOptional)failure)CrawlerProcess)
UsageError)arglist_to_dictfeed_process_params_from_clic                       e Zd ZU dZdZee         ed<   i Ze	e
ef         ed<   dZddZd Zd	 Zd
 Zd Zd Zd Zd Zd ZdS )ScrapyCommandFNcrawler_processdefault_settingsr   returnc                     d | _         d S N)settingsselfs    8lib/python3.11/site-packages/scrapy/commands/__init__.py__init__zScrapyCommand.__init__   s    !    c                 R    t          | d          rt          d          || _        d S )N_crawlerzcrawler already set)hasattrRuntimeErrorr   )r   crawlers     r   set_crawlerzScrapyCommand.set_crawler   s.    4$$ 	64555r   c                     dS )zT
        Command syntax (preferably one-line). Do not include command name.
          r   s    r   syntaxzScrapyCommand.syntax"   	     rr   c                     dS )z4
        A short description of the command
        r    r!   r   s    r   
short_desczScrapyCommand.short_desc(   r#   r   c                 *    |                                  S )zA long description of the command. Return short description when not
        available. It cannot contain newlines since contents will be formatted
        by optparser which removes newlines and wraps text.
        )r%   r   s    r   	long_desczScrapyCommand.long_desc.   s    
    r   c                 *    |                                  S )zAn extensive help for the command. It will be shown when using the
        "help" command. It can contain newlines since no post-formatting will
        be applied to its contents.
        )r'   r   s    r   helpzScrapyCommand.help5   s    
 ~~r   c           	         |                     d          }|                    ddd           |                    ddd	d
d| j        d          d           |                    ddd           |                    ddd
d           |                    ddd           |                    dddg dd           |                    ddd           d
S )zO
        Populate option parse with options available for this command
        Global Options)titlez	--logfileFILEz(log file. if omitted stderr will be usedmetavarr)   z-Lz
--loglevelLEVELNzlog level (default: 	LOG_LEVEL))r/   defaultr)   z--nolog
store_truezdisable logging completely)actionr)   z	--profilez#write python cProfile stats to FILEz	--pidfilezwrite process ID to FILEz-sz--setappend
NAME=VALUEz&set/override setting (may be repeated))r5   r3   r/   r)   z--pdbzenable pdb on failure)add_argument_groupadd_argumentr   )r   parsergroups      r   add_optionszScrapyCommand.add_options<   sC    ))0@)AA.X 	 	
 	
 	
 	Ek(BEEE 	 	
 	
 	
 	l1M 	 	
 	
 	
 	6	 	 	
 	
 	
 	;=WXXX 9 	 	
 	
 	
 	7<>UVVVVVr   c                    	 | j                             t          |j                  d           n# t          $ r t          dd          w xY w|j        r?| j                             ddd           | j                             d|j        d           |j        r?| j                             ddd           | j                             d	|j        d           |j        r| j                             ddd           |j	        rTt          |j	                                      t          t          j                              t          j        z   d
           |j        rt#          j                     d S d S )Ncmdlinepriorityz#Invalid -s value, use -s NAME=VALUEF
print_helpLOG_ENABLEDTLOG_FILEr1   zutf-8)encoding)r   setdictr
   set
ValueErrorr	   logfileloglevelnologpidfiler   
write_textstrosgetpidlineseppdbr   startDebugModer   argsoptss      r   process_optionszScrapyCommand.process_options_   s   	VM!!/$(";";i!PPPP 	V 	V 	VBuUUUU	V < 	LMmTIFFFMj$,KKK= 	NMmTIFFFMk4=9MMM: 	HMmUYGGG< 	))BIKK  2:- *    8 	%"$$$$$	% 	%s	   .1 Ac                     t           )z2
        Entry point for running commands
        )NotImplementedErrorrT   s      r   runzScrapyCommand.runx   s
     "!r   )r   N)__name__
__module____qualname__requires_projectr   r   r   __annotations__r   r   rN   r   exitcoder   r   r"   r%   r'   r)   r<   rW   rZ   r!   r   r   r   r      s         04OXn-444 (*d38n)))H" " " "     
    ! ! !     !W !W !WF% % %2" " " " "r   r   c                       e Zd ZdZd Zd ZdS )BaseRunSpiderCommandzb
    Common class used to share functionality between the crawl, parse and runspider commands
    c                    t                               | |           |                    dddg dd           |                    ddd	dd
           |                    ddd	dd           |                    dddd           d S )Nz-aspargsr6   r7   z%set spider argument (may be repeated))destr5   r3   r/   r)   z-oz--outputr-   zappend scraped items to the end of FILE (use - for stdout), to define format set a colon at the end of the output URI (i.e. -o FILE:FORMAT))r/   r5   r)   z-Oz--overwrite-outputzdump scraped items into FILE, overwriting any existing file, to define format set a colon at the end of the output URI (i.e. -O FILE:FORMAT)z-tz--output-formatFORMATzformat to use for dumping itemsr.   )r   r<   r9   )r   r:   s     r   r<   z BaseRunSpiderCommand.add_options   s    !!$/// 8 	 	
 	
 	
 	_ 	 	
 	
 	
 	 _ 	 	
 	
 	
 	2	 	 	
 	
 	
 	
 	
r   c                 X   t                               | ||           	 t          |j                  |_        n# t          $ r t          dd          w xY w|j        s|j        rEt          | j	        |j        |j
        |j                  }| j	                            d|d           d S d S )Nz#Invalid -a value, use -a NAME=VALUEFrA   FEEDSr>   r?   )r   rW   r
   rd   rH   r	   outputoverwrite_outputr   r   output_formatrG   )r   rU   rV   feedss       r   rW   z$BaseRunSpiderCommand.process_options   s    %%dD$777	V)$+66DKK 	V 	V 	VBuUUUU	V; 	B$/ 	B0"%	 E MguyAAAAA	B 	Bs	   8 AN)r[   r\   r]   __doc__r<   rW   r!   r   r   rb   rb      sB         
 
 
BB B B B Br   rb   c                   4     e Zd ZdZd fd	Z fdZd Z xZS )	ScrapyHelpFormatterz?
    Help Formatter for scrapy command line help messages.
          Nc                 R    t                                          ||||           d S )N)indent_incrementmax_help_positionwidth)superr   )r   progrs   rt   ru   	__class__s        r   r   zScrapyHelpFormatter.__init__   s:    -/	 	 	
 	
 	
 	
 	
r   c                 p    |                      |          }t                                          |          S r   )format_part_stringsrv   _join_parts)r   part_stringspartsrx   s      r   r{   zScrapyHelpFormatter._join_parts   s.    ((66ww""5)))r   c           	         r>d                              d          r#dd         t          d          d         z   d<   fdt          t                              D             }|ddd         D ]|}d|         v rdnd	}|         dd
                                         |<   d                    d|t          |                   z  dg          }                    |dz   |           }S )zM
        Underline and title case command line help message headers.
        r   zusage: zUsage
=====
  Nc                 J    g | ]}|                              d           | S )z:
)endswith).0ir|   s     r   
<listcomp>z;ScrapyHelpFormatter.format_part_strings.<locals>.<listcomp>   s@     
 
 
<?3K3KE3R3R

 
 
r   r+   -=r    
   )
startswithlenranger,   joininsert)r   r|   headingsindexchar	underlines    `    r   rz   z'ScrapyHelpFormatter.format_part_strings   s'     	ULO66yAA 	U0<?3y>>CSCS3TTLO
 
 
 
S..//
 
 
 ddd^ 	6 	6E*l5.AAJ33sD".u"5crc":"@"@"B"BLs<3F/G/G(G$ OPPI	95555r   )rp   rq   N)r[   r\   r]   rm   r   r{   rz   __classcell__)rx   s   @r   ro   ro      so         
 
 
 
 
 
* * * * *      r   ro   )rm   argparserO   pathlibr   typingr   r   r   twisted.pythonr   scrapy.crawlerr   scrapy.exceptionsr	   scrapy.utils.confr
   r   r   rb   HelpFormatterro   r!   r   r   <module>r      s<     				       & & & & & & & & & & " " " " " " ) ) ) ) ) ) ( ( ( ( ( ( K K K K K K K Kl" l" l" l" l" l" l" l"^3B 3B 3B 3B 3B= 3B 3B 3Bl    (0     r   