
    3 d                         d dl Z d dlZd dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZ d Z G d d          Zd	 Zdd
Zd Zd Zd Zd Zd ZdS )    N)suppress)catch_warningsfilterwarnings)asyncioreactorerror)load_objectc                    ddl m} t          |           dk    rt          d|            | s|                    d||          S t          | d          s|                    | ||          S t          |           dk    r|                    | d         ||          S t          | d         | d         dz             D ]>}	 |                    |||          c S # t          j        $ r || d         k    r Y ;w xY wdS )	z<Like reactor.listenTCP but tries different ports in a range.r   reactor   zinvalid portrange: )	interface__iter__   N)	twisted.internetr   len
ValueError	listenTCPhasattrranger   CannotListenError)	portrangehostfactoryr   xs        4lib/python3.11/site-packages/scrapy/utils/reactor.py
listen_tcpr      sT   ((((((
9~~ <:y::;;; =  Gt <<<9j)) E  Gt DDD
9~~ H  1w$ GGG9Q<1!122  	$$Q4$@@@@@& 	 	 	IaL   	 s   CC:9C:c                   ,    e Zd ZdZd ZddZd Zd ZdS )	CallLaterOncezSchedule a function to be called in the next reactor loop, but only if
    it hasn't been already scheduled since the last time it ran.
    c                 >    || _         || _        || _        d | _        d S N)_func_a_kw_call)selffuncakws       r   __init__zCallLaterOnce.__init__$   s"    



    r   c                 Z    ddl m} | j        |                    ||           | _        d S d S Nr   r
   )r   r   r$   	callLater)r%   delayr   s      r   schedulezCallLaterOnce.schedule*   sC    ,,,,,,: 	8 **5$77DJJJ	8 	8r*   c                 J    | j         r| j                                          d S d S r    )r$   cancelr%   s    r   r1   zCallLaterOnce.cancel0   s0    : 	 J	  	 r*   c                 >    d | _          | j        | j        i | j        S r    )r$   r!   r"   r#   r2   s    r   __call__zCallLaterOnce.__call__4   s$    
tz47/dh///r*   N)r   )__name__
__module____qualname____doc__r)   r/   r1   r4    r*   r   r   r      s_           8 8 8 8     0 0 0 0 0r*   r   c                      t          j                    } t          j        dk    rQt          j        dk    rAt          | t           j                  s't          j                    } t          j        |            | S )N)      win32)asyncioget_event_loop_policysysversion_infoplatform
isinstanceWindowsSelectorEventLoopPolicyset_event_loop_policy)policys    r   get_asyncio_event_loop_policyrG   9   sl    *,,FF".LG#. 67#IJJ.
 799%f---Mr*   c                    t          |           }|t          j        u rXt          t          j                  5  t          |          }t          j        |           ddd           dS # 1 swxY w Y   dS |                     d          ^ }}|dgz   }t          d	                    |                    }t          t          j                  5   |             ddd           dS # 1 swxY w Y   dS )zInstalls the :mod:`~twisted.internet.reactor` with the specified
    import path. Also installs the asyncio event loop with the specified import
    path if the asyncio reactor is enabled)	eventloopN.install)
r   r   AsyncioSelectorReactorr   r   ReactorAlreadyInstalledErrorset_asyncio_event_looprK   splitjoin)reactor_pathevent_loop_pathreactor_class
event_loopmodule_installer_path	installers           r   install_reactorrY   F   su     --M== 	e899 	9 	9/@@J"Z8888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 "'',,
9+- 8 899	e899 	 	IKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   %A))A-0A-C''C+.C+c                       t          d           S r    )rN   r9   r*   r   _get_asyncio_event_loopr[   W   s    !$'''r*   c                    t                      }| .t          |           } |            }t          j        |           n	 t	                      5  t          ddt                     |                                }ddd           n# 1 swxY w Y   n8# t          $ r+ |	                                }t          j        |           Y nw xY w|S )z;Sets and returns the event loop with specified import path.NignorezThere is no current event loop)messagecategory)
rG   r   r>   set_event_loopr   r   DeprecationWarningget_event_loopRuntimeErrornew_event_loop)rR   rF   event_loop_classrT   s       r   rN   rN   [   s0   *,,F /&77%%''
z****	/!! 5 5 </   
 $2244
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5  	/ 	/ 	/  ..00J":.....	/ s6    B ,B:B B

B B
B 2CCc                     ddl m} t          |           }|j        |k    s*d|j         d|j        j         d|  d}t          |          dS )z{Raises :exc:`Exception` if the installed
    :mod:`~twisted.internet.reactor` does not match the specified import
    path.r   r
   zThe installed reactor (rJ   z$) does not match the requested one ()N)r   r   r   	__class__r6   r5   	Exception)rQ   r   rS   msgs       r   verify_installed_reactorrk   }   s     )(((((--M- 8"8 8%,%6%?8 8(48 8 8 	
 nn r*   c                     ddl m} t          |           }t          |j        |          rd S |j        j        j         d|j        j        j         }|j         d|j         }t          d| d| d          )Nr   r
   rJ   zUScrapy found an asyncio Twisted reactor already installed, and its event loop class (zF) does not match the one specified in the ASYNCIO_EVENT_LOOP setting (rg   )	r   r   r   rC   _asyncioEventlooprh   r6   r7   ri   )	loop_pathr   
loop_class	installed	specifieds        r   #verify_installed_asyncio_event_looprr      s    ((((((Y''J'+Z88 $.9 	? 	?%/<	? 	?  (DD:+BDDI
	!09	! 	! 	! 	! 	!  r*   c                  B    ddl m}  t          | t          j                  S r,   )r   r   rC   r   rL   r
   s    r   is_asyncio_reactor_installedrt      s'    ((((((g~DEEEr*   r    )r>   r@   
contextlibr   warningsr   r   r   r   r   scrapy.utils.miscr   r   r   rG   rY   r[   rN   rk   rr   rt   r9   r*   r   <module>rx      s     



       3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 ) ) ) ) ) )  (0 0 0 0 0 0 0 04
 
 
   "( ( (  D     &F F F F Fr*   