2Uc @sYdZdZdZedjdZddlZddlZddlZddl Z ddl Z de fdYZ e Z e jd krejjZejZne jd krd ZnSd Zyejjd Wnek rn&Xdejdd-Z?d.Z@d/ZAd0ZBd1ZCd2ZDd3ZEd4ZFdZGd5ZHd6ZId7ZJd8ZKd9ZLd:ZMd;ZNd<ZOd=ZPd>ZQd?ZRd@ZSdAZTdBZUdCZVdDZWdEZXdFZYdGZZdHZ[dIZ\dJZ]dKZ^dLZ_dMZ`dNZadOZbdPZcdQZddRZedSZfdTZgdUZhdVZidWZjdXZkdYZldZZmd[ZndZod\ZpdEZqdZrd]esfd^YZtd_ejufd`YZvdaevfdbYZwejxZyejzZ{dcej|fddYZ}dee}fdfYZ~dge}fdhYZedeeyejxe{evej|Zedeeye{evevevej|Zedeeyejxe{evevevej| Zedeeyejxe{evevejejej|ej| Zedee}eye{ej|Zedeeyejxe{evejejejej|ejxej| ZdiZe[dje fdkYZeZdlZdmZdnZeqddoZdEeqdeddedpddq ZdEeedEdrZddEedEdsZdEdtZdEeqeddduZdEeeeeddvZdwZeqeee'edEddxZdEeqeee'ddyZdEeqeee'edzZdeed{Zd|e fd}YZdS(~s Pure-Python interface to Apple Bonjour and compatible DNS-SD libraries pybonjour provides a pure-Python interface (via ctypes) to Apple Bonjour and compatible DNS-SD libraries (such as Avahi). It allows Python scripts to take advantage of Zero Configuration Networking (Zeroconf) to register, discover, and resolve services on both local and wide-area networks. Since pybonjour is implemented in pure Python, scripts that use it can easily be ported to Mac OS X, Windows, Linux, and other systems that run Bonjour. Note on strings: Internally, all strings used in DNS-SD are UTF-8 strings. String arguments passed to the DNS-SD functions provided by pybonjour must be either unicode instances or str instances that can be converted to unicode using the default encoding. (Passing a non-convertible str will result in an exception.) Strings returned from pybonjour (either directly from API functions or passed to application callbacks) are always unicode instances. s,Christopher Stawarz s1.1.1s$Revision: 6125 $iiNt _DummyLockcBs&eZedZedZRS(cCsdS(N((((s//usr/lib/python2.7/vendor-packages/pybonjour.pytacquireKscCsdS(N((((s//usr/lib/python2.7/vendor-packages/pybonjour.pytreleaseOs(t__name__t __module__t staticmethodRR(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRIstwin32tdarwinslibSystem.B.dylibslibdns_sd.so.1slibavahi-client.so.3t1tAVAHI_COMPAT_NOWARNiiiii i@iiiiiiiiii i i i i iiiiiiiiiiiiiiiiii!i"i#i$i%i&i'i(i)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiit BonjourErrorcBseZdZide6de6de6de6de6de6de 6de 6d e 6d e 6d e 6d e6d e6de6de6de6de6de6de6de6de6ZedZdZRS(s Exception representing an error returned by the DNS-SD library. The errorCode attribute contains the actual integer error code returned. s no such names no memorys bad params bad references bad states bad flagst unsupportedsnot initializedsalready registereds name conflicttinvalidtfirewallt incompatiblesbad interface indextrefusedsno such recordsno auths no such keys NAT traversals double NATsbad timecCs|tkr||n|S(N(tkDNSServiceErr_NoError(tclstresulttfunctargs((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt _errchecks cCs2||_tj|||jj|dfdS(Ntunknown(t errorCodet Exceptiont__init__t_errmsgtget(tselfR((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR!s  (RRt__doc__tkDNSServiceErr_NoSuchNametkDNSServiceErr_NoMemorytkDNSServiceErr_BadParamtkDNSServiceErr_BadReferencetkDNSServiceErr_BadStatetkDNSServiceErr_BadFlagstkDNSServiceErr_UnsupportedtkDNSServiceErr_NotInitializedt kDNSServiceErr_AlreadyRegisteredtkDNSServiceErr_NameConflicttkDNSServiceErr_InvalidtkDNSServiceErr_FirewalltkDNSServiceErr_Incompatiblet kDNSServiceErr_BadInterfaceIndextkDNSServiceErr_RefusedtkDNSServiceErr_NoSuchRecordtkDNSServiceErr_NoAuthtkDNSServiceErr_NoSuchKeytkDNSServiceErr_NATTraversaltkDNSServiceErr_DoubleNATtkDNSServiceErr_BadTimeRt classmethodRR(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR s2 t _utf8_char_pcBs eZedZdZRS(cCsz|dk rjt|| rjt|ts:tdnt|tsXt|}n|jd}ntjj|S(Ns(parameter must be a string type instancesutf-8( tNonet isinstancet basestringt TypeErrortunicodetencodetctypestc_char_pt from_param(Rtobj((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR=2scCs#|jdkrdS|jjdS(Nsutf-8(tvalueR5tdecode(R((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR@<s(RRR3R=R@(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR40s t_utf8_char_p_non_nullcBseZedZRS(cCs(|dkrtdntj|S(Nsparameter cannot be None(R5t ValueErrorR4R=(RR>((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR=Ds (RRR3R=(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRABst DNSRecordRefcBsAeZdZedZdZdZdZdZRS(s A DNSRecordRef pointer. DO NOT CREATE INSTANCES OF THIS CLASS! Only instances returned by the DNS-SD library are valid. Using others will likely cause the Python interpreter to crash. Application code should not use any of the methods of this class. The only valid use of a DNSRecordRef instance is as an argument to a DNS-SD function. To compare two DNSRecordRef instances for equality, use '==' rather than 'is'. cCs`t||k r7td|jt|jfn|jdkr\td|jn|S(Nsexpected '%s', got '%s'sinvalid %s instance(ttypeR8RR?R5RB(RR>((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR=`s cCs(t|t|ko'|j|jkS(N(RDR?(Rtother((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt__eq__iscCs ||k S(N((RRE((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt__ne__lscCs d|_dS(N(R5R?(R((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt _invalidateoscCs |jdk S(N(R?R5(R((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt_validrs( RRRR3R=RFRGRHRI(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRCOs    t_DNSRecordRef_or_nullcBseZedZRS(cCs|dkr|Stj|S(N(R5RCR=(RR>((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR=xs (RRR3R=(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRJvst DNSServiceRefcBsMeZdZdZdZdZdZdZdZdZ RS(sm A DNSServiceRef pointer. DO NOT CREATE INSTANCES OF THIS CLASS! Only instances returned by the DNS-SD library are valid. Using others will likely cause the Python interpreter to crash. An instance of this class represents an active connection to the mDNS daemon. The connection remains open until the close() method is called (which also terminates the associated browse, resolve, etc.). Note that this method is *not* called automatically when the instance is deallocated; therefore, application code must be certain to call close() when the connection is no longer needed. The primary use of a DNSServiceRef instance is in conjunction with select() or poll() to determine when a response from the daemon is available. When the file descriptor returned by fileno() is ready for reading, a reply from the daemon is available and should be processed by passing the DNSServiceRef instance to DNSServiceProcessResult(), which will invoke the appropriate application callback function. (Note that the file descriptor should never be read from or written to directly.) The DNSServiceRef class supports the context management protocol introduced in Python 2.5, meaning applications can use the 'with' statement to ensure that DNSServiceRef instances are closed regardless of whether an exception occurs, e.g. sdRef = DNSServiceBrowse(...) with sdRef: # sdRef will be closed regardless of how this block is # exited ... To compare two DNSServiceRef instances for equality, use '==' rather than 'is'. cOs)tj|||g|_g|_dS(N(RCRt _callbackst _record_refs(RRtkwargs((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRs cCs|S(N((R((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt __enter__scCs|jdS(N(tclose(RRDR?t traceback((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt__exit__scCs|jj|dS(N(RLtappend(Rtcb((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt _add_callbackscCs|jj|dS(N(RMRS(Rtref((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt_add_record_refscCsm|jrix|jD]}|jqW|`tjzt|WdtjX|j|`ndS(s Close the connection to the mDNS daemon and terminate any associated browse, resolve, etc. operations. N(RIRMRHt _global_lockRt_DNSServiceRefDeallocateRRL(RRV((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRPs    cCs,tjzt|}WdtjX|S(s Return the file descriptor associated with this connection. This descriptor should never be read from or written to directly. It should only be passed to select() or poll() to determine when a response from the mDNS daemon is available. N(RXRt_DNSServiceRefSockFDR(Rtfd((s//usr/lib/python2.7/vendor-packages/pybonjour.pytfilenos  ( RRRRRORRRURWRPR\(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRKs&      c Cst}t}d}d}itj||tffd6t||tffd6d||tffd6t||dtjtttj t tj ffd6t||dtjtttj t t t t tjtjtj ttj f fd6t||dttjtttjtjtj tj ffd 6t||ttttjtj tj ffd 6t||tttffd 6t||dtjtttj t t ttj ffd 6t||dtjtttj t t t ttj ffd 6t||dtjtffd6t||dttjtttj t tjtjtjtj tj ttj f fd6t||dtjtttj t tjtjttj ffd6d||ttj t tjtjtjtj ffd6tj||dtjtt t t ffd6}x|jD]\}\}}}} t|| } dgt| } |dk rd| |HstDNSServiceRefSockFDtDNSServiceProcessResulttDNSServiceRefDeallocateitDNSServiceEnumerateDomainstDNSServiceRegisteritDNSServiceAddRecordtDNSServiceUpdateRecordtDNSServiceRemoveRecordtDNSServiceBrowsetDNSServiceResolvetDNSServiceCreateConnectiontDNSServiceRegisterRecordtDNSServiceQueryRecordtDNSServiceReconfirmRecordtDNSServiceConstructFullNameicss|]}|fVqdS(N((t.0tval((s//usr/lib/python2.7/vendor-packages/pybonjour.pys -st_(!tTruetFalseR5R;tc_intRKt_DNSServiceErrorTypetPOINTERt_DNSServiceFlagstc_uint32t_DNSServiceDomainEnumReplytc_void_pR4RAtc_uint16t_DNSServiceRegisterReplyRCRJt_DNSServiceBrowseReplyt_DNSServiceResolveReplyt_DNSServiceRegisterRecordReplyt_DNSServiceQueryRecordReplytc_chartkDNSServiceMaxDomainNametitemst_CFunctlenttuplet _libdnssdR Rterrchecktglobals( tERRCHECKt NO_ERRCHECKtOUTPARAMt NO_OUTPARAMtspecstnametrestypeRtoutparamtargtypest prototypet paramflagsR((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt_create_function_bindingsCs                      %  t _NoDefaultcBseZdZdZRS(cCsdS(Ns ((R((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt__repr__GscCs||krtdndS(Ns required parameter value missing(RB(RR>((s//usr/lib/python2.7/vendor-packages/pybonjour.pytcheckJs (RRRR(((s//usr/lib/python2.7/vendor-packages/pybonjour.pyREs cCsLt|trt|}ntjtj|tj}t||fS(N(R6t TXTRecordtstrR;tcastR<RyR(tstringtvoid_p((s//usr/lib/python2.7/vendor-packages/pybonjour.pyt_string_to_length_and_void_pQscsAtj|tjtjdjfdt|DS(Ntc3s|]}|VqdS(N((Rnti(tchar_p(s//usr/lib/python2.7/vendor-packages/pybonjour.pys Zs(R;RRuRtjointxrange(tlengthR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyt_length_and_void_p_to_stringXscCs*tjzt|WdtjXdS(s/ Read a reply from the daemon, calling the appropriate application callback. This call will block until the daemon's response is received. Use sdRef in conjunction with select() or poll() to determine the presence of a response from the server before calling this function to process the reply without blocking. Call this function at any point if it is acceptable to block until the daemon's response arrives. Note that the client is responsible for ensuring that DNSServiceProcessResult() is called whenever there is a reply from the daemon; the daemon may terminate its connection with a client that does not process the daemon's responses. sdRef: A DNSServiceRef returned by any of the DNSService calls that take a callback parameter. N(RXRt_DNSServiceProcessResultR(tsdRef((s//usr/lib/python2.7/vendor-packages/pybonjour.pyR`fs csWtfd}tjzt|||d}WdtjX|j||S(s Asynchronously enumerate domains available for browsing and registration. The enumeration MUST be cancelled by closing the returned DNSServiceRef when no more domains are to be found. flags: Possible values are: kDNSServiceFlagsBrowseDomains to enumerate domains recommended for browsing. kDNSServiceFlagsRegistrationDomains to enumerate domains recommended for registration. interfaceIndex: If non-zero, specifies the interface on which to look for domains. Most applications will pass kDNSServiceInterfaceIndexAny (0) to enumerate domains on all interfaces. callBack: The function to be called when a domain is found or the call asynchronously fails. Its signature should be callBack(sdRef, flags, interfaceIndex, errorCode, replyDomain). return value: A DNSServiceRef instance. Callback Parameters: sdRef: The DNSServiceRef returned by DNSServiceEnumerateDomains(). flags: Possible values are: kDNSServiceFlagsMoreComing kDNSServiceFlagsAdd kDNSServiceFlagsDefault interfaceIndex: Specifies the interface on which the domain exists. errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise indicates the failure that occurred (in which case other parameters are undefined). replyDomain: The name of the domain. cs/dk r+|||||jndS(N(R5R@(RtflagstinterfaceIndexRt replyDomaintcontext(tcallBack(s//usr/lib/python2.7/vendor-packages/pybonjour.pyt _callbacks N(RxRXRt_DNSServiceEnumerateDomainsR5RRU(RRRRR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyRbs;    Rc stj|tj|tj|}|s>d\} }nt|\} }tfd} tjz.t|||||||| || d } Wdtj X| j | | S(s Register a service that is discovered via DNSServiceBrowse() and DNSServiceResolve() calls. flags: Indicates the renaming behavior on name conflict. Most applications will pass 0. interfaceIndex: If non-zero, specifies the interface on which to register the service. Most applications will pass kDNSServiceInterfaceIndexAny (0) to register on all available interfaces. name: If not None, specifies the service name to be registered. Most applications will not specify a name, in which case the computer name is used. (This name is communicated to the client via the callback.) If a name is specified, it must be 1-63 bytes of UTF-8 text. If the name is longer than 63 bytes, it will be automatically truncated to a legal length, unless the flag kDNSServiceFlagsNoAutoRename is set, in which case a BonjourError exception will be thrown. regtype: The service type followed by the protocol, separated by a dot (e.g. "_ftp._tcp"). The service type must be an underscore, followed by 1-14 characters, which may be letters, digits, or hyphens. The transport protocol must be "_tcp" or "_udp". New service types should be registered at . domain: If not None, specifies the domain on which to advertise the service. Most applications will not specify a domain, instead automatically registering in the default domain(s). host: If not None, specifies the SRV target host name. Most applications will not specify a host, instead automatically using the machine's default host name(s). Note that specifying a host name does NOT create an address record for that host; the application is responsible for ensuring that the appropriate address record exists, or creating it via DNSServiceRegisterRecord(). port: The port, in host (not network) byte order, on which the service accepts connections. Pass 0 for a "placeholder" service (i.e. a service that will not be discovered by browsing, but will cause a name conflict if another client tries to register that same name). Most clients will not use placeholder services. txtRecord: The TXT record rdata. If not None, txtRecord must be either a TXTRecord instance or a string containing a properly formatted DNS TXT record, i.e. ... callBack: The function to be called when the registration completes or asynchronously fails. Its signature should be callBack(sdRef, flags, errorCode, name, regtype, domain). The client MAY pass None for the callback, in which case the client will NOT be notified of the default values picked on its behalf, and the client will NOT be notified of any asynchronous errors (e.g. out of memory errors, etc.) that may prevent the registration of the service. The client may NOT pass the flag kDNSServiceFlagsNoAutoRename if the callback is None. The client may still deregister the service at any time by closing the returned DNSServiceRef. return value: A DNSServiceRef instance. The registration will remain active indefinitely until the client terminates it by closing the DNSServiceRef. Callback Parameters: sdRef: The DNSServiceRef returned by DNSServiceRegister(). flags: Currently unused, reserved for future use. errorCode: Will be kDNSServiceErr_NoError on success, otherwise will indicate the failure that occurred (including name conflicts, if the kDNSServiceFlagsNoAutoRename flag was used when registering). Other parameters are undefined if an error occurred. name: The service name registered. (If the application did not specify a name in DNSServiceRegister(), this indicates what name was automatically chosen.) regtype: The type of service registered, as it was passed to the callout. domain: The domain on which the service was registered. (If the application did not specify a domain in DNSServiceRegister(), this indicates the default domain on which the service was registered.) itcs>dk r:||||j|j|jndS(N(R5R@(RRRRtregtypetdomainR(R(s//usr/lib/python2.7/vendor-packages/pybonjour.pyRZs N(is( t _NO_DEFAULTRtsocketthtonsRR{RXRt_DNSServiceRegisterR5RRU( RRRRRthosttportt txtRecordRttxtLenRR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyRcs.{      cCsttj|tj|t|\}}tjzt||||||}WdtjX|j||S(sx Add a record to a registered service. The name of the record will be the same as the registered service's name. The record can later be updated or deregistered by passing the DNSRecordRef returned by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). Note that DNSServiceAddRecord/UpdateRecord/RemoveRecord are NOT thread-safe with respect to a single DNSServiceRef. If you plan to have multiple threads in your program simultaneously add, update, or remove records from the same DNSServiceRef, then it's the caller's responsibility to use a lock or take similar appropriate precautions to serialize those calls. sdRef: A DNSServiceRef returned by DNSServiceRegister(). flags: Currently ignored, reserved for future use. rrtype: The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, etc.). rdata: A string containing the raw rdata to be contained in the added resource record. ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value. return value: A DNSRecordRef instance, which may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). If sdRef is closed, the DNSRecordRef is also invalidated and may not be used further. N(RRRRXRt_DNSServiceAddRecordRRW(RRtrrtypetrdatatttltrdlent RecordRef((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRdus1      cCsXtj|t|\}}tjzt||||||WdtjXdS(s> Update a registered resource record. The record must either be: - The primary txt record of a service registered via DNSServiceRegister(), or - A record added to a registered service via DNSServiceAddRecord(), or - An individual record registered by DNSServiceRegisterRecord() sdRef: A DNSServiceRef returned by DNSServiceRegister() or DNSServiceCreateConnection(). RecordRef: A DNSRecordRef returned by DNSServiceAddRecord(), or None to update the service's primary txt record. flags: Currently ignored, reserved for future use. rdata: A string containing the new rdata to be contained in the updated resource record. ttl: The time to live of the updated resource record, in seconds. N(RRRRXRt_DNSServiceUpdateRecordR(RRRRRR((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRes%   cCs:tjzt|||WdtjX|jdS(s Remove a record previously added to a service record set via DNSServiceAddRecord(), or deregister a record registered individually via DNSServiceRegisterRecord(). sdRef: A DNSServiceRef returned by DNSServiceRegister() (if the record being removed was registered via DNSServiceAddRecord()) or by DNSServiceCreateConnection() (if the record being removed was registered via DNSServiceRegisterRecord()). recordRef: A DNSRecordRef returned by DNSServiceAddRecord() or DNSServiceRegisterRecord(). flags: Currently ignored, reserved for future use. N(RXRt_DNSServiceRemoveRecordRRH(RRR((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRfs   csjtj|tfd}tjzt|||||d}WdtjX|j||S(s Browse for instances of a service. flags: Currently ignored, reserved for future use. interfaceIndex: If non-zero, specifies the interface on which to browse for services. Most applications will pass kDNSServiceInterfaceIndexAny (0) to browse on all available interfaces. regtype: The service type being browsed for followed by the protocol, separated by a dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp". domain: If not None, specifies the domain on which to browse for services. Most applications will not specify a domain, instead browsing on the default domain(s). callBack: The function to be called when an instance of the service being browsed for is found, or if the call asynchronously fails. Its signature should be callBack(sdRef, flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain). return value: A DNSServiceRef instance. The browse operation will run indefinitely until the client terminates it by closing the DNSServiceRef. Callback Parameters: sdRef: The DNSServiceRef returned by DNSServiceBrowse(). flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. interfaceIndex: The interface on which the service is advertised. This index should be passed to DNSServiceResolve() when resolving the service. errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will indicate the failure that occurred. Other parameters are undefined if an error occurred. serviceName: The discovered service name. This name should be displayed to the user and stored for subsequent use in the DNSServiceResolve() call. regtype: The service type, which is usually (but not always) the same as was passed to DNSServiceBrowse(). One case where the discovered service type may not be the same as the requested service type is when using subtypes: The client may want to browse for only those ftp servers that allow anonymous connections. The client will pass the string "_ftp._tcp,_anon" to DNSServiceBrowse(), but the type of the service that's discovered is simply "_ftp._tcp". The regtype for each discovered service instance should be stored along with the name, so that it can be passed to DNSServiceResolve() when the service is later resolved. replyDomain: The domain of the discovered service instance. This may or may not be the same as the domain that was passed to DNSServiceBrowse(). The domain for each discovered service instance should be stored along with the name, so that it can be passed to DNSServiceResolve() when the service is later resolved. csAdk r=|||||j|j|jndS(N(R5R@(RRRRt serviceNameRRR(R(s//usr/lib/python2.7/vendor-packages/pybonjour.pyRrs N( RRR|RXRt_DNSServiceBrowseR5RRU(RRRRRRR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyRgsZ     cstj|tj|tj|tj|tfd}tjz"t||||||d}WdtjX|j||S(s Resolve a service name discovered via DNSServiceBrowse() to a target host name, port number, and txt record. Note: Applications should NOT use DNSServiceResolve() solely for txt record monitoring; use DNSServiceQueryRecord() instead, as it is more efficient for this task. Note: When the desired results have been returned, the client MUST terminate the resolve by closing the returned DNSServiceRef. Note: DNSServiceResolve() behaves correctly for typical services that have a single SRV record and a single TXT record. To resolve non-standard services with multiple SRV or TXT records, DNSServiceQueryRecord() should be used. flags: Currently ignored, reserved for future use. interfaceIndex: The interface on which to resolve the service. If this resolve call is as a result of a currently active DNSServiceBrowse() operation, then the interfaceIndex should be the index reported in the browse callback. If this resolve call is using information previously saved (e.g. in a preference file) for later use, then use kDNSServiceInterfaceIndexAny (0), because the desired service may now be reachable via a different physical interface. name: The name of the service instance to be resolved, as reported to the DNSServiceBrowse() callback. regtype: The type of the service instance to be resolved, as reported to the DNSServiceBrowse() callback. domain: The domain of the service instance to be resolved, as reported to the DNSServiceBrowse() callback. callBack: The function to be called when a result is found, or if the call asynchronously fails. Its signature should be callBack(sdRef, flags, interfaceIndex, errorCode, fullname, hosttarget, port, txtRecord). return value: A DNSServiceRef instance. The resolve operation will run indefinitely until the client terminates it by closing the DNSServiceRef. Callback Parameters: sdRef: The DNSServiceRef returned by DNSServiceResolve(). flags: Currently unused, reserved for future use. interfaceIndex: The interface on which the service was resolved. errorCode: Will be kDNSServiceErr_NoError (0) on success, otherwise will indicate the failure that occurred. Other parameters are undefined if an error occurred. fullname: The full service domain name, in the form ... hosttarget: The target hostname of the machine providing the service. port: The port, in host (not network) byte order, on which connections are accepted for this service. txtRecord: A string containing the service's primary txt record, in standard txt record format. c s\dk rXtj|}t||}|||||j|j||ndS(N(R5RtntohsRR@( RRRRtfullnamet hosttargetRRRR(R(s//usr/lib/python2.7/vendor-packages/pybonjour.pyRs  N( RRR}RXRt_DNSServiceResolveR5RRU(RRRRRRRR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyRhs"_        cCs)tjz t}WdtjX|S(s  Create a connection to the daemon allowing efficient registration of multiple individual records. return value: A DNSServiceRef instance. Closing it severs the connection and deregisters all records registered on this connection. N(RXRt_DNSServiceCreateConnectionR(R((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRis   c stj|tj|tj|t|\} }tfd} tjz.t||||||| ||| d } WdtjX|j | |j | | S(sw Register an individual resource record on a connected DNSServiceRef. Note that name conflicts occurring for records registered via this call must be handled by the client in the callback. sdRef: A DNSServiceRef returned by DNSServiceCreateConnection(). flags: Possible values are kDNSServiceFlagsShared or kDNSServiceFlagsUnique. interfaceIndex: If non-zero, specifies the interface on which to register the record. Passing kDNSServiceInterfaceIndexAny (0) causes the record to be registered on all interfaces. fullname: The full domain name of the resource record. rrtype: The numerical type of the resource record (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc.). rrclass: The class of the resource record (usually kDNSServiceClass_IN). rdata: A string containing the raw rdata, as it is to appear in the DNS record. ttl: The time to live of the resource record, in seconds. Pass 0 to use a default value. callBack: The function to be called when a result is found, or if the call asynchronously fails (e.g. because of a name conflict). Its signature should be callBack(sdRef, RecordRef, flags, errorCode). return value: A DNSRecordRef instance, which may be passed to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). (To deregister ALL records registered on a single connected DNSServiceRef and deallocate each of their corresponding DNSRecordRefs, close the DNSServiceRef.) Callback Parameters: sdRef: The connected DNSServiceRef returned by DNSServiceCreateConnection(). RecordRef: The DNSRecordRef returned by DNSServiceRegisterRecord(). flags: Currently unused, reserved for future use. errorCode: Will be kDNSServiceErr_NoError on success, otherwise will indicate the failure that occurred (including name conflicts). Other parameters are undefined if an error occurred. cs&dk r"||||ndS(N(R5(RRRRR(R(s//usr/lib/python2.7/vendor-packages/pybonjour.pyRws N( RRRR~RXRt_DNSServiceRegisterRecordR5RRURW( RRRRRtrrclassRRRRRR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyRjs,S        csztj|tj|tfd}tjz"t||||||d}WdtjX|j||S(s Query for an arbitrary DNS record. flags: Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast query in a non-local domain. Without setting this flag, unicast queries will be one-shot; that is, only answers available at the time of the call will be returned. By setting this flag, answers (including Add and Remove events) that become available after the initial call is made will generate callbacks. This flag has no effect on link-local multicast queries. interfaceIndex: If non-zero, specifies the interface on which to issue the query. Passing kDNSServiceInterfaceIndexAny (0) causes the name to be queried for on all interfaces. fullname: The full domain name of the resource record to be queried for. rrtype: The numerical type of the resource record to be queried for (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc.). rrclass: The class of the resource record (usually kDNSServiceClass_IN). callBack: The function to be called when a result is found, or if the call asynchronously fails. Its signature should be callBack(sdRef, flags, interfaceIndex, errorCode, fullname, rrtype, rrclass, rdata, ttl). return value: A DNSServiceRef instance. The query operation will run indefinitely until the client terminates it by closing the DNSServiceRef. Callback Parameters: sdRef: The DNSServiceRef returned by DNSServiceQueryRecord(). flags: Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. The Add flag is NOT set for PTR records with a ttl of 0, i.e. "Remove" events. interfaceIndex: The interface on which the query was resolved. errorCode: Will be kDNSServiceErr_NoError on success, otherwise will indicate the failure that occurred. Other parameters are undefined if an error occurred. fullname: The resource record's full domain name. rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc.). rrclass: The class of the resource record (usually kDNSServiceClass_IN). rdata: A string containing the raw rdata of the resource record. ttl: The resource record's time to live, in seconds. c sJdk rFt||}|||||j|||| ndS(N(R5RR@( RRRRRRRRRRR(R(s//usr/lib/python2.7/vendor-packages/pybonjour.pyRs N( RRRRXRt_DNSServiceQueryRecordR5RRU(RRRRRRRR((Rs//usr/lib/python2.7/vendor-packages/pybonjour.pyRksW      cCsutj|tj|tj|t|\}}tjz t|||||||WdtjXdS(s Instruct the daemon to verify the validity of a resource record that appears to be out of date (e.g. because tcp connection to a service's target failed). Causes the record to be flushed from the daemon's cache (as well as all other daemons' caches on the network) if the record is determined to be invalid. flags: Currently unused, reserved for future use. interfaceIndex: If non-zero, specifies the interface of the record in question. Passing kDNSServiceInterfaceIndexAny (0) causes all instances of this record to be reconfirmed. fullname: The resource record's full domain name. rrtype: The resource record's type (e.g. kDNSServiceType_PTR, kDNSServiceType_SRV, etc.). rrclass: The class of the resource record (usually kDNSServiceClass_IN). rdata: A string containing the raw rdata of the resource record. N(RRRRXRt_DNSServiceReconfirmRecordR(RRRRRRR((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRls)     cCsXtj|tj|tjzt|||}WdtjX|jjdS(s Concatenate a three-part domain name (as returned by a callback function) into a properly-escaped full domain name. Note that callback functions already escape strings where necessary. service: The service name; any dots or backslashes must NOT be escaped. May be None (to construct a PTR record name, e.g. "_ftp._tcp.apple.com."). regtype: The service type followed by the protocol, separated by a dot (e.g. "_ftp._tcp"). domain: The domain name, e.g. "apple.com.". Literal dots or backslashes, if any, must be escaped, e.g. "1st\. Floor.apple.com." return value: The resulting full domain name. Nsutf-8(RRRXRt_DNSServiceConstructFullNameRR?R@(tserviceRRtfullName((s//usr/lib/python2.7/vendor-packages/pybonjour.pyRmAs    RcBseZdZiedZdZdZdZdZdZ dZ e j dZ d Zd Zeed ZRS( s A mapping representing a DNS TXT record. The TXT record's name=value entries are stored as key/value pairs in the mapping. Although keys can be accessed in a case-insensitive fashion (meaning txt['foo'] and txt['FoO'] refer to the same value), key case is preserved in the wire representation of the record (so txt['FoO'] = 'bar' will generate a FoO=bar entry in the TXT record). Key order is also preserved, so keys appear in the wire format in the order in which they were created. Note that in addition to being valid as a txtRecord parameter to DNSServiceRegister(), a TXTRecord instance can be used in place of a resource record data string (i.e. rdata parameter) with any function that accepts one. cCsF||_g|_i|_x$|jD]\}}|||-~]+$cCs|}|j}t|}|dk rnt|trK|jd}n t|}|dt|7}n|jr|dkrtdn||j kr|jr|j j |dkrtd|n|j j |n||f|j |1s               7  ' n           ! N  C 3 $ p x  l n 7 1