Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/pyro_ext.cpython-37.pyc

B

�d{T[�@s�dZdZddlZddlZddlmZmZmZmZm	Z	e�
d�Ze�Z
e��e	_e
fdd�Zdd	�ZiZiZddd�Zd
d�Ze
ddd
fdd�Zdd�Ze
dfdd�Ze
dfdd�Ze
dfdd�Zdd�Zdd�ZdS)aDPython Remote Object utilities

Main functions available:

* `register_object` to expose arbitrary object through pyro using delegation
  approach and register it in the nameserver.
* `ns_unregister` unregister an object identifier from the nameserver.
* `ns_get_proxy` get a pyro proxy from a nameserver object identifier.
zrestructuredtext en�N)�core�naming�errors�util�configZpyrocCsdy|�dd�\}}Wn,tk
r@|tkr4tj}n|}|}YnX|dk	r\|�d�s\d|}||fS)N�.��:)�rsplit�
ValueError�_MARKERrZPYRO_NS_DEFAULTGROUP�
startswith)Zidstr�defaultnsgroup�nsgroup�nsid�r�H/opt/alt/python37/lib/python3.7/site-packages/logilab/common/pyro_ext.py�ns_group_and_id(s
rcCsD|sdSy|�d�\}}Wntk
r2d}Yn
Xt|�}||fS)N)NNr	)�splitr�int)Zhoststr�portrrr�
host_and_port5s
rTcCsR|tkrJ|std|��ts(tjdd�t|�\}}tj||d�}|t|<t|S)Nzno daemon for %sr)�banner)�hostr)�_DAEMONS�	ExceptionrZ
initServerrZDaemon)�
daemonhost�startrr�daemonrrr�_get_daemonBsrcCstjdd�t��jt|��S)z4locate and return the pyro name server to the daemonF)r)rZ
initClientrZNameServerLocatorZgetNSr)�nshostrrr�	locate_nsNsr!cCs�t||�\}}t|�}|rRt|�}y|�|�Wntjk
rFYnX|�|�t��}	|	�	|�d||f}
|�
|	|
�}t|�t|
<t
�d|||�|S)z�expose the object as a pyro object and register it in the name-server

    if use_pyrons is False, then the object is exposed, but no
    attempt to register it to a pyro nameserver is made.

    return the pyro daemon object
    z%s.%sz4registered %s a pyro object using group %s and id %s)rrr!�createGroupr�NamingErrorZ
useNameServerrZObjBaseZ
delegateTo�connect�str�
_PYRO_OBJS�_LOGGER�info)�objectrrrr Z
use_pyronsrr�nsd�impl�qnsidZurirrr�register_objectTs"	


r-cCst|S)N)r&)r,rrr�get_object_uriqsr.c
Cs�t||�\}}yt|�}Wn0tjk
rJ}zt�d|�Wdd}~XYnHXy"|�d||f�t�d|�Wn"tjk
r�t�	d|�YnXdS)zCunregister the object with the given nsid from the pyro name serverz!can't locate pyro name server: %sNz%s.%sz%%s unregistered from pyro name serverz%%s not registered in pyro name server)
rr!r�	PyroErrorr'�error�
unregisterr(r#�warning)rrr rr*�exrrr�
ns_unregistertsr4cCs�t||�\}}d||f}t|�}y|�|�Wn<tjk
rly|�|�Wntjk
rfYnXYnX|�|t|�dS)aLreregister a pyro object into the name server. You only have to specify
    the name-server id of the object (though you MUST have gone through
    `register_object` for the given object previously).

    This is especially useful for long running server while the name server may
    have been restarted, and its records lost.
    z%s.%sN)rr!r1rr#r"�registerr&)rrr rr,r*rrr�
ns_reregister�sr6c
Cs�t||�\}}yt|�}|�d||f�}WnTtjk
r^}zt�d|��Wdd}~XYn$tjk
r�t�d|��YnXt�|�S)zD
    if nshost is None, the nameserver is found by a broadcast.
    z%s.%sz4Could not connect to the Pyro name server (host: %s)NziCould not get proxy for %s (not registered in Pyro), you may have to restart your server-side application)	rr!�resolverZ
ProtocolErrorr/r#r�getProxyForURI)rrr rr*Zpyrourir3rrr�ns_get_proxy�sr9cCs
t�|�S)zCget a proxy for the passed pyro uri without using a nameserver
    )rr8)Zpyro_urirrr�	get_proxy�sr:cCs,t�dtttj���}g|_|�|�dS)NzPyro.%s)�logging�	getLoggerr%�idr�Log�handlers�setLevel)�levelZ
pyrologgerrrr�set_pyro_log_threshold�srB)T)�__doc__�
__docformat__r;�tempfileZPyrorrrrrr<r'r)r�
gettempdirZPYRO_STORAGErrrr&rr!r-r.r4r6r9r:rBrrrr�<module>s*