
    !h)                       S r SSKJr  SSKrSSKrSSK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  SSKJr  SS	KJr  SS
KJrJrJrJr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"  SSK#J$r$  SSK%J&r&  SSK'J(r(  \)\\*\+4r,\" S5      r-S S jr.S!S jr/S"S jr0S#S jr1S$S jr2S r3          S%S jr4\S&S j5       r5S'S jr6\ " SS9r7S(S jr8      S)S jr9g)*z.Helper functions which don't fit anywhere else    )annotationsN)deque)Iterable)contextmanager)partial)import_module)iter_modules)IOTYPE_CHECKINGAnyTypeVarcast)ScrapyDeprecationWarning)Item)LocalWeakReferencedCache)CallableIterator)
ModuleType)Spider)CrawlerTc                    U c  / $ [        U [        5      (       d(  [        U S5      (       a  [        [        [
           U 5      $ U /$ )zConvert an argument to an iterable. The argument can be a None, single
value, or an iterable.

Exception: if arg is a dict, [arg] will be returned
__iter__)
isinstance_ITERABLE_SINGLE_VALUEShasattrr   r   r   )args    X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/utils/misc.pyarg_to_iterr   #   s@     {	c233Z8P8PHSM3''5L    c                d   [        U [        5      (       d)  [        U 5      (       a  U $ [        S[	        U 5       35      e U R                  S5      nU SU XS-   S p2[        U5      n [        XC5      nU$ ! [         a    [        SU  S35      ef = f! [         a    [        SU SU S	35      ef = f)
a>  Load an object given its absolute object path, and return it.

The object can be the import path of a class, function, variable or an
instance, e.g. 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware'.

If ``path`` is not a string, but is a callable object, such as a class or
a function, then return it as is.
z:Unexpected argument type, expected string or object, got: .zError loading object 'z': not a full pathN   zModule 'z#' doesn't define any object named '')r   strcallable	TypeErrortyperindex
ValueErrorr   getattrAttributeError	NameError)pathdotmodulenamemodobjs         r   load_objectr4   0   s     dC  D>>KHdU
 	
Lkk# :t!GID

CWc  J  L1$7IJKKL  W(6(*MdVSTUVVWs    A5 (B 5BB/c                   / n[        U 5      nUR                  U5        [        US5      (       aZ  [        UR                  5       HA  u  p4nU S-   U-   nU(       a  U[        U5      -  nM%  [        U5      nUR                  U5        MC     U$ )zLoads a module and all its submodules from the given module path and
returns them. If *any* module throws an exception while importing, that
exception is thrown back.

For example: walk_modules('scrapy.utils')
__path__r"   )r   appendr   r	   r6   walk_modules)r.   modsr2   _subpathispkgfullpathsubmods           r   r8   r8   Q   s      D

CKKsJ!-cll!;AczG+HX..&x0F# "< Kr    c                    [         R                  " S[        SS9  [        R                  " 5       n U R                  S5      nU(       d   UR                  5       $ UR                  U5        M<  )zCalculate the md5 checksum of a file-like object without reading its
whole content in memory.

>>> from io import BytesIO
>>> md5sum(BytesIO(b'file content to hash'))
'784406af91dd5a54fbb9c84c2236595a'
zfThe scrapy.utils.misc.md5sum function is deprecated and will be removed in a future version of Scrapy.   
stackleveli  )warningswarnr   hashlibmd5readupdate	hexdigest)filemds      r   md5sumrM   g   s^     MM5 	! 	A
IIdO;;= 	
	 r    c                ^    U SL=(       a#    SU R                  SS5      R                  5       ;   $ )z3Return True if link rel attribute has nofollow typeNnofollow, )replacesplit)rels    r   rel_has_nofollowrU      s*    d?JzS[[c-B-H-H-JJJr    c                z   [         R                  " S[        SS9  Uc  Uc  [        S5      eUR                  nU(       a*  [        U S5      (       a  U R                  " U/UQ70 UD6nSnO4[        U S5      (       a  U R                  " U/UQ70 UD6nSnO
U " U0 UD6nSnUc  [        U R                   SU S	35      eU$ )
ak  Construct a class instance using its ``from_crawler`` or
``from_settings`` constructors, if available.

At least one of ``settings`` and ``crawler`` needs to be different from
``None``. If ``settings `` is ``None``, ``crawler.settings`` will be used.
If ``crawler`` is ``None``, only the ``from_settings`` constructor will be
tried.

``*args`` and ``**kwargs`` are forwarded to the constructors.

Raises ``ValueError`` if both ``settings`` and ``crawler`` are ``None``.

.. versionchanged:: 2.2
   Raises ``TypeError`` if the resulting instance is ``None`` (e.g. if an
   extension has not been implemented correctly).
zVThe create_instance() function is deprecated. Please use build_from_crawler() instead.r@   categoryrB   z-Specify at least one of settings and crawler.from_crawlerfrom_settings__new__r"    returned None)
rC   rD   r   r*   settingsr   rY   rZ   r'   __qualname__)objclsr]   crawlerargskwargsinstancemethod_names          r   create_instancere      s    " MM	3)	 ?LMM##76>22&&w@@@$		)	)''B4B6B%4*6*6../q^LMMOr    c               |   [        U S5      (       a  U R                  " U/UQ70 UD6nSnOe[        U S5      (       aJ  [        R                  " U R                   S3[
        SS9  U R                  " UR                  /UQ70 UD6nSnO
U " U0 UD6nSnUc  [        U R                   SU S35      e[        [        U5      $ )	zConstruct a class instance using its ``from_crawler`` or ``from_settings`` constructor.

.. versionadded:: 2.12

``*args`` and ``**kwargs`` are forwarded to the constructor.

Raises ``TypeError`` if the resulting instance is ``None``.
rY   rZ   z has from_settings() but not from_crawler(). This is deprecated and calling from_settings() will be removed in a future Scrapy version. You can implement a simple from_crawler() that calls from_settings() with crawler.settings.r@   rW   r[   r"   r\   )r   rY   rC   rD   r^   r   rZ   r]   r'   r   r   )r_   r`   ra   rb   rc   rd   s         r   build_from_crawlerrg      s     v~&&&&w@@@$		)	)""# $6 6 .	
 ''(8(8J4J6J%4*6*6../q^LMM8r    c               +    #    U  Vs0 s H"  o[         R                  R                  U5      _M$     nn[         R                  R                  U 5         Sv   UR	                  5        H.  u  pUc  [         R                  U	 M  U[         R                  U'   M0     gs  snf ! UR	                  5        H.  u  pUc  [         R                  U	 M  U[         R                  U'   M0     f = f7f)zsTemporarily set environment variables inside the context manager and
fully restore previous environment afterwards
N)osenvirongetrH   items)rb   koriginal_envvs       r   set_environrp      s      399&Qrzz~~a((&L9JJf" &&(DAyJJqM !

1	 ) :
 !&&(DAyJJqM !

1	 )s)   C%)B!C%B AC%AC""C%c              #    #    [        U /5      nSnU(       am  UR                  5       n [        U [        R                  5      (       a  U(       a  M?  SnUR                  [        R                  " U 5      5        U v   U(       a  Ml  gg7f)zjSimilar to ``ast.walk``, but walks only function body and skips nested
functions defined within the node.
FTN)r   popleftr   astFunctionDefextenditer_child_nodes)nodetodowalked_func_defs      r   walk_callablerz      sd      !$=DO
||~dCOO,,"OC((./
 $s   B BB   )limitc                   U [         ;   a  [        [         U    5      $ SS jn[        R                  " U 5      (       Ga-  U n[	        U[
        5      (       a#  UR                  n[	        U[
        5      (       a  M#  [        R                  " U5      n[        R                  " S5      nUR                  SU5      nUR                  U5      nU(       a*  [        R                  " SUR                  S5       3SU5      n[        R                  " U5      n[        U5       HN  n[	        U[        R                   5      (       d  M$  U" U5      (       a  M3  S[         U '   [        [         U    5      s  $    S[         U '   [        [         U    5      $ )	z
Returns True if a callable is a generator function which includes a
'return' statement with a value different than None, False otherwise
c                    U R                   nUS L =(       d/    [        U[        R                  5      =(       a    UR                   S L $ )N)valuer   rs   Constant)return_noder   s     r   returns_none4is_generator_with_return_value.<locals>.returns_none   s:    !!} 
ucll+Ct0C	
r    z	(^[\t ]+) 
r   TF)r   z
ast.Returnreturnbool)_generator_callbacks_cacher   inspectisgeneratorfunctionr   r   func	getsourcerecompilesubmatchgrouprs   parserz   Return)	r&   r   r   srcpatterncoder   treerw   s	            r   is_generator_with_return_valuer      s4   
 --.x899
 ""8,,w''99D w'' %**\*{{2s#c"66Bu{{1~./t<Dyy!$'D$

++L4F4F7;*846x@AA (
 ,1x(*8455r    c           
        U R                   R                  S5      (       d  g [        U5      (       a;  [        R                  " SU R
                  R                   SUR                   S3SS9  gg! [         aH    U R
                  R                  S-   UR                  -   n[        R                  " SU S	U S
U S3SS9   gf = f)zy
Logs a warning if a callable is a generator function and includes
a 'return' statement with a value different than None
WARN_ON_GENERATOR_RETURN_VALUENzThe "r"   a&  " method is a generator and includes a "return" statement with a value different than None. This could lead to unexpected behaviour. Please see https://docs.python.org/3/reference/simple_stmts.html#the-return-statement for details about the semantics of the "return" statement within generatorsr@   rA   z$Unable to determine whether or not "z" is a generator with a return value. This will not prevent your code from working, but it prevents Scrapy from detecting potential issues in your implementation of "zu". Please, report this in the Scrapy issue tracker (https://github.com/scrapy/scrapy/issues), including the code of "")r]   getboolr   rC   rD   	__class____name__IndentationError)spiderr&   callable_names      r   #warn_on_generator_with_return_valuer     s     ??""#CDD
)(33MM((112!H4E4E3F G^ ^
  4  	
((11C7(:K:KK2=/ B;;H/ J&&3_A	7
 	
	
s   A
A/ /AC C)r   r   r   zIterable[Any])r.   zstr | Callable[..., Any]r   r   )r.   r%   r   zlist[ModuleType])rJ   z	IO[bytes]r   r%   )rT   z
str | Noner   r   )
r_   ztype[T]r`   r   ra   r   rb   r   r   r   )rb   r%   r   zIterator[None])rw   zast.ASTr   zIterable[ast.AST])r&   Callable[..., Any]r   r   )r   r   r&   r   r   None):__doc__
__future__r   rs   rE   r   ri   r   rC   collectionsr   collections.abcr   
contextlibr   	functoolsr   	importlibr   pkgutilr	   typingr
   r   r   r   r   scrapy.exceptionsr   scrapy.itemr   scrapy.utils.datatypesr   r   r   typesr   scrapyr   scrapy.crawlerr   dictr%   bytesr   r   r   r4   r8   rM   rU   re   rg   rp   rz   r   r   r    r    r   <module>r      s    4 " 
   	 	   $ %  #   8 8 6  ;2 & c50 CL
B,2K
'T%14@CB " ""  6C@ "6J

0
	
r    