o Sb@sdZddlZddlZz ddlmZdZWn eydZYnwddlmZddl m Z dd Z d d Z d Z Gd ddeZdS)zASupport for resolving hosts and options from mongodb+srv:// URIs.N)resolverTF)CONNECT_TIMEOUT)ConfigurationErrorcCst|tr |S|S)N) isinstancebytesdecode)textr ;/tmp/pip-target-onvjaxws/lib/python/pymongo/srv_resolver.py maybe_decode!s r cOs*ttdr tj|i|Stj|i|S)Nresolve)hasattrrr query)argskwargsr r r _resolve(s rzdInvalid URI host: %s is not a valid hostname for 'mongodb+srv://'. Did you mean to use 'mongodb://'?c@s>eZdZdddZddZddZdd Zd d Zd d ZdS) _SrvResolverrcCs||_||_|p t|_|pd|_z t|ttdt y$Ynwz |j ddd|_ Wnt y@tt|fwt |j |_|jdkrStt|fdS)Nr)z an IP address.)_SrvResolver__fqdn_SrvResolver__srvr_SrvResolver__connect_timeout_SrvResolver__srv_max_hosts ipaddress ip_addressr_INVALID_HOST_MSG ValueErrorsplit_SrvResolver__plist Exceptionlen_SrvResolver__slen)selfZfqdnconnect_timeoutZsrv_service_nameZ srv_max_hostsr r r __init__7s&        z_SrvResolver.__init__c Csz t|jd|jd}WntjtjfyYdSty*}ztt|d}~wwt |dkr5tdd dd|D dS) NZTXTZlifetimerz Only one TXT record is supported&cSsg|]}d|jqS))joinstrings.0resr r r Usz,_SrvResolver.get_options..zutf-8) rrrrZNoAnswerZNXDOMAINr rstrr!r)r)r#resultsexcr r r get_optionsKs  z_SrvResolver.get_optionsc CsRztd|jd|jd|jd}W|Sty(}z |stt|d}~ww)N_z._tcp.ZSRVr&)rrrrr rr/)r#encapsulate_errorsr0r1r r r _resolve_uriWs  z_SrvResolver._resolve_uric Cs||}dd|D}|D]4}z|dddd|j d}Wnty3td|dfw|j|krBtd|dfq|jrRt|t |jt |}||fS)NcSs$g|]}t|jjdd|jfqS)T)Zomit_final_dot)r targetZto_textportr+r r r r.hsz<_SrvResolver._get_srv_response_and_hosts..rrrzInvalid SRV host: %s) r5rr"r rrrrandomsampleminr!)r#r4r0nodesnodeZnlistr r r _get_srv_response_and_hostsds &  z(_SrvResolver._get_srv_response_and_hostscCs|d\}}|S)NT)r=)r#r3r;r r r get_hostsxsz_SrvResolver.get_hostscCs|d\}}||jjfS)NF)r=Zrrsetttl)r#r0r;r r r get_hosts_and_min_ttl|s z"_SrvResolver.get_hosts_and_min_ttlN)r) __name__ __module__ __qualname__r%r2r5r=r>r@r r r r r6s    r)__doc__rr8ZdnsrZ_HAVE_DNSPYTHON ImportErrorZpymongo.commonrZpymongo.errorsrr rrobjectrr r r r s