B t `î.ã @s.dZddlZddlZddlZddlZddlZdZdZdZy$ddlZddl Zddl ZdZdZWnFy ddl Z ddl Z e ZdZdZWndZdZdZYnXYnXeZ ejdkrÀeZddlZnddlZdZerÚe jjZn eræe jjZddd „Zdd d „Zddd„Zddd„Zddd„Zejejfdd„ZdS))Úget_nameserverÚget_dispatchersÚshutdown_pyro_componentséNFT)éréÚUnknownc Cstdkrtdƒ‚d}|dk r(|tjd<ndtjkr         rú:PyUtilibServerrc Csü|dkrt|||d}n$|dks$t‚|dks0t‚|dkstræx8|j ddD](} |  | ¡} | | f|krº| | | f¡qºWt |ƒ|kr`Pq`W|S)N)r r rz1Failed to locate Pyro name server on the network!grz:PyUtilibServer.dispatcher.)Úprefix) rÚAssertionErrorÚ RuntimeErrorrrÚflatlistÚ startswithÚappendÚ using_pyro4ÚlistÚlookupÚlen) Úgroupr r Znum_dispatcher_triesZmin_dispatchersrrZcumulative_sleep_timeZ dispatchersrÚ ns_entriesÚnameÚurirrrrss0        rc CsVtdkrtdƒ‚|dkr(t||||d}|dkr\}}|dkršy tj  |¡}|  ¡|  ¡WqšYqšXqšWntt rRxT|jddD]D}y2| |¡}| |¡t |¡}|  ¡| ¡WqòYqòXqòWtdƒtdƒtdƒdS) NzPyro or Pyro4 is not available)r r rrzQ***WARNING - Could not locate name server - Pyro components will not be shut downz:PyUtilibServer.dispatcher.z:Pyro.NameServer)r!Úz=*** NameServer must be shutdown manually when using Pyro4 ***)r r rrrr$r%Ú unregisterrZgetProxyForURIÚshutdownÚ _shutdownÚ_releaser'r(r)ÚremoveZProxyZ _pyroRelease) r r rrrr,r-r.Úproxyrrrr¢sR             rcCs|dkrZd}|tjkrŒttj|ƒ}tdtr0dnd||fƒtrP|dtj_qŒ|tj_n2tdtrfdnd|fƒtr„|dtj_n|tj_dS)NZPYUTILIB_PYRO_MAXCONNECTIONSz€Overriding %s default for maximum number of proxy connections to %s, based on specification provided by %s environment variable.ÚPyroÚPyro4rz‡Overriding %s default for maximum number of proxy connections to %s, based on specification provided by max_allowed_connections keyword) r rÚintrrr ÚconfigZPYRO_MAXCONNECTIONSZTHREADPOOL_SIZE)Zmax_allowed_connectionsZmax_pyro_connections_envnameÚnew_valrrrÚset_maxconnectionsÖs     r;ú 127.0.0.1cCs¸|jtjtjfkr:|jtjkr:ttdƒr:| tjtj d¡|jtjkrj|dkrZ|  d¡q¬|  |df¡nB|jtjkrž|dkrŠ|  d¡q¬|  |dddf¡nt d|jƒ‚|  ¡dS)arBind the socket to a free port and return the port number. Relies on ephemeral ports in order to ensure we are using an unbound port. This is important as many tests may be running simultaneously, especially in a buildbot environment. This method raises an exception if the sock.family is AF_INET and sock.type is SOCK_STREAM, *and* the socket has SO_REUSEADDR or SO_REUSEPORT set on it. Tests should *never* set these socket options for TCP/IP sockets. The only case for setting these options is testing multicasting via multiple UDP sockets. Additionally, if the SO_EXCLUSIVEADDRUSE socket option is available (i.e. on Windows), it will be set on the socket. This will prevent anyone else from bind()'ing to our host/port for the duration of the test. This code is copied from the stdlib's test.test_support module. ÚSO_EXCLUSIVEADDRUSErÚ localhost)z 127.0.0.1rr)z::1rrrzunsupported socket family: ) ÚfamilyÚsocketÚAF_INETÚAF_INET6ÚtypeÚ SOCK_STREAMÚhasattrÚ setsockoptÚ SOL_SOCKETr=ÚbindZCommunicationErrorÚ getsockname)Úsockr rrrÚ bind_portøs      rKcCs"t ||¡}t|ƒ}| ¡~|S)aReturns an unused port that should be suitable for binding. This is achieved by creating a temporary socket with the same family and type as the 'sock' parameter (default is AF_INET, SOCK_STREAM), and binding it to the specified host address (defaults to 0.0.0.0) with the port set to 0, eliciting an unused ephemeral port from the OS. The temporary socket is then closed and deleted, and the ephemeral port is returned. This code is copied from the stdlib's test.test_support module. )r@rKÚclose)r?ÚsocktypeZtempsockr rrrÚfind_unused_port7s rN)NNrr)r NNrrNN)NNrNr)N)r<)Ú__all__r Úsysrrr@r6rr'Z Pyro.coreZ Pyro.namingr7Z Pyro4.namingr Ú version_infoÚrangerÚqueueÚQueuerrÚ ProtocolErrorÚ TimeoutErrorrrrr;rKrArDrNrrrrÚ sf    9 ) 0 " ?