o
    Žõ±j  ã                   @   sj   d dl m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mZmZ eedœZG dd„ deƒZd	S )
é    )Ústat)Úconnect)Ú	UniTargetÚUniProto)ÚurlparseÚparse_qs)Ústr_oneÚint_oneÚbool_one)ÚpagesizeÚratec                   @   sr   e Zd ZdZdejddddddddddfdeded	ed
efdd„Zdd„ Zdd„ Z	dd„ Z
edd„ ƒZdd„ ZdS )ÚMSLDAPTargetaq  
	Describes the connection to the server.
	
	:param host: IP address or hostname of the server
	:type host: str
	:param port: port of the LDAP service running on the server
	:type port: int
	:param proto: Connection protocol to be used
	:type proto: :class:`UniProto`
	:param tree: The tree to connect to
	:type tree: str
	:param proxies: specifies what kind of proxy to be used
	:type proxies: :class:`List[UniProxyTarget]`
	:param timeout: connection timeout in seconds
	:type timeout: int
	:param ldap_query_page_size: Maximum number of elements to fetch in each paged_query call.
	:type ldap_query_page_size: int
	:param ldap_query_ratelimit: rate limit of paged queries. This will cause a sleep (in seconds) between fetching of each page of the query
	:type ldap_query_ratelimit: float
	:param dc_ip: Ip address of the kerberos server (if kerberos is used)
	:type dc_ip: str
	é…  Né
   éè  r   ÚdnsÚdc_ipÚdomainÚhostnamec                 C   s6   t j| |||||||||
|	d� || _|| _|| _d S )N)r   Ússl_ctxÚproxiesr   r   r   )r   Ú__init__ÚtreeÚldap_query_page_sizeÚldap_query_ratelimit)ÚselfÚipÚportÚprotocolr   r   Útimeoutr   r   r   r   r   r   r   © r    úˆ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/msldap/commons/target.pyr   +   s    
zMSLDAPTarget.__init__c                 C   s   d|   ¡ | jf S )Nz
ldap/%s@%s)Úget_hostname_or_ipr   ©r   r    r    r!   Úto_target_string1   s   zMSLDAPTarget.to_target_stringc                 C   s6   | j tjkr	d}n| j tjkrd}d||  ¡ | jf S )NÚldapsÚldapz
%s://%s:%s)r   r   ÚCLIENT_SSL_TCPÚ
CLIENT_TCPr"   r   )r   Úprotor    r    r!   Úget_host4   s
   zMSLDAPTarget.get_hostc                 C   s   | j tjkS )N)r   r   r'   r#   r    r    r!   Úis_ssl;   s   zMSLDAPTarget.is_sslc                 C   s”  t | ƒ}g }|j ¡  d¡D ]}| | dd¡¡ q|d dkr&tj}d}nM|d dkr2tj}d}nA|d d	kr>tj}d}n5|d d
krJtj}d}n)|d dkrSt	ƒ ‚|d dkr_tj}d}n|d dkrktj}d}ntd|d  ƒ‚|jry|j}|d u r�tdƒ‚d }|jdvr‹|j}t | ||t¡\}}|d d urŸ|d nd}	|d d ur«|d nd}
t|j|j|j||j|j|	|
|j|j|j|j|jd�}|S )Nú+ú-Ú_r   ÚLDAPr   ÚLDAPSi|  ÚLDAP_SSLÚLDAP_TCPÚLDAP_UDPÚGCiÄ  ÚGC_SSLiÅ  zUnknown protocol! %szPort must be provided!)ú/Ú Nr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   ÚschemeÚupperÚsplitÚappendÚreplacer   r(   r'   ÚNotImplementedErrorÚ
CLIENT_UDPÚ	Exceptionr   Úpathr   Úfrom_urlÚmsldaptarget_url_paramsr   r   r   r   r   r   r   r   r   r   )Úconnection_urlÚurl_eÚschemesÚitemr   r   r@   Ú	unitargetÚextraparamsr   r   Útargetr    r    r!   rA   >   sf   
ózMSLDAPTarget.from_urlc                 C   s*   d}| j D ]}|d|| j | f 7 }q|S )Nz==== MSLDAPTarget ====
z%s: %s
)Ú__dict__)r   ÚtÚkr    r    r!   Ú__str__|   s   
zMSLDAPTarget.__str__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   Ústrr   r$   r*   r+   ÚstaticmethodrA   rM   r    r    r    r!   r      s    6
=r   N)Úosr   Úsqlite3r   Úasysocks.unicomm.common.targetr   r   Úurllib.parser   r   Ú%asysocks.unicomm.utils.paramprocessorr   r	   r
   rB   r   r    r    r    r!   Ú<module>   s   þ