
    !h&                       S r 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Jr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJrJr  SSKJ r   \(       a  SSK!J"r"  SSK#J$r$  SSK%J&r'  SSK(J)r)  SSK*J+r+  \" S5      r,S"S jr-S"S jr.      S#S jr/ S$             S%S jjr0\" S\ 5      r1S&S jr2   S'       S(S jjr3S)S jr4S*S jr5 S+         S,S jjr6S-S jr7S.S  jr8S/S! jr9g)0z<
This module contains some assorted functions used in tests
    )annotationsN)import_module)Path)split)TYPE_CHECKINGAnyTypeVarcast)TestCasemock)SkipTest)ScrapyDeprecationWarning)is_botocore_available)create_deprecated_class)is_asyncio_reactor_installedis_reactor_installed)DefaultSpider)	Awaitable)Deferred)Response)Spider)Crawler_Tc                 v    [         R                  " S[        SS9  S[        R                  ;  a  [        S5      eg )NzThe assert_gcs_environ() function is deprecated and will be removed in a future version of Scrapy. Check GCS_PROJECT_ID directly.   category
stacklevelGCS_PROJECT_IDzGCS_PROJECT_ID not found)warningswarnr   osenvironr        X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/utils/test.pyassert_gcs_environr'   %   s8    MM	*)	 rzz)122 *r%   c                 l    [         R                  " S[        SS9  [        5       (       d  [	        S5      eg )NzThe skip_if_no_boto() function is deprecated and will be removed in a future version of Scrapy. Check scrapy.utils.boto.is_botocore_available() directly.r   r   zmissing botocore library)r    r!   r   r   r   r$   r%   r&   skip_if_no_botor)   0   s6    MM	E)	 !""122 #r%   c                R   SSK Jn  [        R                  " S[        SS9  UR                  [        R                  R                  S5      S9nUR                  U 5      n U R                  U5      nUR                  5       n[        UR                  5      nU R                  U5        XVU4$ )Nr   )storagezjThe get_gcs_content_and_delete() function is deprecated and will be removed in a future version of Scrapy.r   r   r   )project)google.cloudr+   r    r!   r   Clientr"   r#   get
get_bucketget_blobdownload_as_stringlistacldelete_blob)bucketpathr+   clientblobcontentr4   s          r&   get_gcs_content_and_deleter;   ;   s     %MMt)
 ^^BJJNN3C$D^EFv&F??4 D%%'G
txx.C
tr%   c                  ^ SSK Jn  [        R                  " S[        SS9  U" 5       nUR                  X5        UR                  X45        U(       a  UR                  S5        / mS
U4S jjnUR                  SU  3U5        [        U 5      u  pUR                  U	5        UR                  U
5        S	R                  T5      $ )Nr   )FTPzjThe get_ftp_content_and_delete() function is deprecated and will be removed in a future version of Scrapy.r   r   Fc                (   > TR                  U 5        g N)append)dataftp_datas    r&   buffer_data/get_ftp_content_and_delete.<locals>.buffer_datad   s    r%   zRETR r%   )rA   bytesreturnNone)ftplibr=   r    r!   r   connectloginset_pasv
retrbinaryr   cwddeletejoin)r7   hostportusernamepassworduse_active_moder=   ftprC   dirnamefilenamerB   s              @r&   get_ftp_content_and_deleterX   N   s     MMt)
 %CKKIIh!UH NNU4&>;/dGGGGJJx88Hr%   
TestSpiderc                 f    [        5       (       d  [        S5      e0 n [        5       (       d  SU S'   U $ )a  Return a settings dict that works with the installed reactor.

``Crawler._apply_settings()`` checks that the installed reactor matches the
settings, so tests that run the crawler in the current process may need to
pass a correct ``"TWISTED_REACTOR"`` setting value when creating it.
zget_reactor_settings() called without an installed reactor, you may need to install a reactor explicitly when running your tests.NTWISTED_REACTOR)r   RuntimeErrorr   )settingss    r&   get_reactor_settingsr^   q   s@      !!U
 	
  "H'))&*"#Or%   c                    SSK Jn  0 [        5       EU=(       d    0 EnU" U5      nUR                  U =(       d    [        5      nUR                  5         U$ )zReturn an unconfigured Crawler object. If settings_dict is given, it
will be used to populate the crawler settings with a project level
priority.
r   )CrawlerRunner)scrapy.crawlerr`   r^   create_crawlerr   _apply_settings)	spiderclssettings_dictprevent_warningsr`   r]   runnercrawlers          r&   get_crawlerri      sX     - 

  B H 8$F##I$>?GNr%   c                     [        S5      R                  S   n [        [        U 5      R                  5      [
        R                  -   [
        R                  R                  SS5      -   $ )z^Return a PYTHONPATH suitable to use in processes so that they find this
installation of Scrapyscrapyr   
PYTHONPATH )	r   __path__strr   parentr"   pathsepr#   r/   )scrapy_paths    r&   get_pythonpathrs      sM      )2215KtK ''(2::5

|UW8XXXr%   c                 \    [         R                  R                  5       n [        5       U S'   U $ )zReturn a OS environment dict suitable to fork processes that need to import
this installation of Scrapy, instead of a system installed one.
rl   )r"   r#   copyrs   )envs    r&   get_testenvrw      s&     **//
C&(CJr%   c                    [         R                  " S[        SS9  U R                  UR	                  5       UR	                  5       U5        g)zdAsserts text1 and text2 have the same lines, ignoring differences in
line endings between platforms
z^The assert_samelines function is deprecated and will be removed in a future version of Scrapy.r   r   N)r    r!   r   assertEqual
splitlines)testcasetext1text2msgs       r&   assert_samelinesr      s?     MMh)
 ))+U-=-=-?Er%   c                r    [         R                  " 5       nUR                  5       nUR                  U 5        U$ r?   )asyncioQueuer/   
put_nowait)valueqgetters      r&   get_from_asyncio_queuer      s)    "==?AUUWFLLMr%   c                    SSK Jn JnJn  [        R
                  " S[        SS9  [        R                  " U5      n[        R                  " U5      nXCR                  l
        [        R                  " U 5      nXTR                  l
        X4U4$ )ztCreates autospec mocks for google-cloud-storage Client, Bucket and Blob
classes and set their proper return values.
r   )BlobBucketr.   ziThe mock_google_cloud_storage() function is deprecated and will be removed in a future version of Scrapy.r   r   )google.cloud.storager   r   r.   r    r!   r   r   create_autospecr0   return_valuer9   )r   r   r.   client_mockbucket_mock	blob_mocks         r&   mock_google_cloud_storager      st     :9MMs) &&v.K&&v.K*5'$$T*I$-!i00r%   c           	         SSK Jn  SSKJn  U" U5      n[	        SUR                  SU R                  S5      5      5      $ )Nr   )reactor)AgentDeferred[TxResponse]s   GETzutf-8)twisted.internetr   twisted.web.clientr   r
   requestencode)urlr   r   agents       r&   get_web_client_agent_reqr      s3    (('NE&fcjj>Q(RSSr%   )rF   rG   )r6   r   r7   ro   rF   z'tuple[bytes, list[dict[str, str]], Any])F)r7   ro   rP   ro   rQ   intrR   ro   rS   ro   rT   boolrF   rE   )rF   zdict[str, Any])NNT)rd   ztype[Spider] | Nonere   zdict[str, Any] | Nonerf   r   rF   r   )rF   ro   )rF   zdict[str, str]r?   )
r{   r   r|   ro   r}   ro   r~   z
str | NonerF   rG   )r   r   rF   zAwaitable[_T])rF   ztuple[Any, Any, Any])r   ro   rF   r   ):__doc__
__future__r   r   r"   r    	importlibr   pathlibr   	posixpathr   typingr   r   r	   r
   unittestr   r   twisted.trial.unittestr   scrapy.exceptionsr   scrapy.utils.botor   scrapy.utils.deprecater   scrapy.utils.reactorr   r   scrapy.utils.spiderr   collections.abcr   twisted.internet.deferr   r   r   
TxResponserk   r   ra   r   r   r'   r)   r;   rX   rY   r^   ri   rs   rw   r   r   r   r   r$   r%   r&   <module>r      si   #  	  #   4 4 # + 6 3 : S -)/9& T]33,2 "

  	
   @ %\=A
& &*+/!"(  	.Y CGFF"F+.F5?F	F1.Tr%   