Commit b90bef25 authored by Wim Haanstra's avatar Wim Haanstra

Python 3 version of pybonjour

parents
1.1.1 (2008-05-08)
------------------
* All DNS-SD API calls are now made after acquiring a global lock
object. This object is a dummy (i.e. acquire() and release() do
nothing), except in the case where pybonjour is using Avahi's
Bonjour compatibility layer, in which case the lock is a
threading.RLock instance. This is necessary because the
compatibility layer is not thread safe.
* Added browse_resolve_query.py to examples
* Moved unit tests to test_pybonjour.py
1.1.0 (2007-06-14)
------------------
* Added TXTRecord class for generating and parsing DNS TXT records
Metadata-Version: 1.0
Name: pybonjour
Version: 1.1.1
Summary: Pure-Python interface to Apple Bonjour and compatible DNS-SD libraries
Home-page: http://o2s.csail.mit.edu/o2s-wiki/pybonjour
Author: Christopher Stawarz
Author-email: cstawarz@csail.mit.edu
License: UNKNOWN
Download-URL: http://o2s.csail.mit.edu/download/pybonjour/
Description: 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.
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: System :: Networking
----------------------------------------------------
pybonjour: Pure-Python interface to Apple Bonjour
Author: Christopher Stawarz <cstawarz@csail.mit.edu>
Version: 1.1.1
May 8, 2008
----------------------------------------------------
Introduction
------------
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.
pybonjour is free software, distributed under the MIT license.
Requirements
------------
pybonjour requires Python 2.4 or later. It also depends on ctypes
(version 1.0.1 or later), which is part of the standard library in
Python 2.5 but must be downloaded and installed separately for Python
2.4.
No additional software is required to use pybonjour under Mac OS X.
To use it under Windows, the Bonjour for Windows package must be
installed on your system. Most Linux systems use Avahi rather than
Bonjour for DNS-SD. If this is the case on your system, you'll need
to install Avahi's Bonjour compatibility library. (Under Ubuntu, the
package to install is libavahi-compat-libdnssd1.) Otherwise, or to
use pybonjour under other POSIX systems, you must download, compile,
and install Bonjour from source.
Both the Bonjour for Windows package and the latest Bonjour source
code are available for download at
http://developer.apple.com/networking/bonjour/download/
Documentation
-------------
pybonjour provides extensive online documentation, which can be
accessed from the Python prompt via 'help(pybonjour)'. In addition,
the examples directory contains scripts that demonstrate basic usage
of the module.
For more information, please visit
http://o2s.csail.mit.edu/o2s-wiki/pybonjour
import select
import sys
import pybonjour
regtype = sys.argv[1]
timeout = 5
resolved = []
def resolve_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
hosttarget, port, txtRecord):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print 'Resolved service:'
print ' fullname =', fullname
print ' hosttarget =', hosttarget
print ' port =', port
resolved.append(True)
def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName,
regtype, replyDomain):
if errorCode != pybonjour.kDNSServiceErr_NoError:
return
if not (flags & pybonjour.kDNSServiceFlagsAdd):
print 'Service removed'
return
print 'Service added; resolving'
resolve_sdRef = pybonjour.DNSServiceResolve(0,
interfaceIndex,
serviceName,
regtype,
replyDomain,
resolve_callback)
try:
while not resolved:
ready = select.select([resolve_sdRef], [], [], timeout)
if resolve_sdRef not in ready[0]:
print 'Resolve timed out'
break
pybonjour.DNSServiceProcessResult(resolve_sdRef)
else:
resolved.pop()
finally:
resolve_sdRef.close()
browse_sdRef = pybonjour.DNSServiceBrowse(regtype = regtype,
callBack = browse_callback)
try:
try:
while True:
ready = select.select([browse_sdRef], [], [])
if browse_sdRef in ready[0]:
pybonjour.DNSServiceProcessResult(browse_sdRef)
except KeyboardInterrupt:
pass
finally:
browse_sdRef.close()
import select
import socket
import sys
import pybonjour
regtype = sys.argv[1]
timeout = 5
queried = []
resolved = []
def query_record_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
rrtype, rrclass, rdata, ttl):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print ' IP =', socket.inet_ntoa(rdata)
queried.append(True)
def resolve_callback(sdRef, flags, interfaceIndex, errorCode, fullname,
hosttarget, port, txtRecord):
if errorCode != pybonjour.kDNSServiceErr_NoError:
return
print 'Resolved service:'
print ' fullname =', fullname
print ' hosttarget =', hosttarget
print ' port =', port
query_sdRef = \
pybonjour.DNSServiceQueryRecord(interfaceIndex = interfaceIndex,
fullname = hosttarget,
rrtype = pybonjour.kDNSServiceType_A,
callBack = query_record_callback)
try:
while not queried:
ready = select.select([query_sdRef], [], [], timeout)
if query_sdRef not in ready[0]:
print 'Query record timed out'
break
pybonjour.DNSServiceProcessResult(query_sdRef)
else:
queried.pop()
finally:
query_sdRef.close()
resolved.append(True)
def browse_callback(sdRef, flags, interfaceIndex, errorCode, serviceName,
regtype, replyDomain):
if errorCode != pybonjour.kDNSServiceErr_NoError:
return
if not (flags & pybonjour.kDNSServiceFlagsAdd):
print 'Service removed'
return
print 'Service added; resolving'
resolve_sdRef = pybonjour.DNSServiceResolve(0,
interfaceIndex,
serviceName,
regtype,
replyDomain,
resolve_callback)
try:
while not resolved:
ready = select.select([resolve_sdRef], [], [], timeout)
if resolve_sdRef not in ready[0]:
print 'Resolve timed out'
break
pybonjour.DNSServiceProcessResult(resolve_sdRef)
else:
resolved.pop()
finally:
resolve_sdRef.close()
browse_sdRef = pybonjour.DNSServiceBrowse(regtype = regtype,
callBack = browse_callback)
try:
try:
while True:
ready = select.select([browse_sdRef], [], [])
if browse_sdRef in ready[0]:
pybonjour.DNSServiceProcessResult(browse_sdRef)
except KeyboardInterrupt:
pass
finally:
browse_sdRef.close()
import select
import sys
import pybonjour
name = sys.argv[1]
regtype = sys.argv[2]
port = int(sys.argv[3])
def register_callback(sdRef, flags, errorCode, name, regtype, domain):
if errorCode == pybonjour.kDNSServiceErr_NoError:
print 'Registered service:'
print ' name =', name
print ' regtype =', regtype
print ' domain =', domain
sdRef = pybonjour.DNSServiceRegister(name = name,
regtype = regtype,
port = port,
callBack = register_callback)
try:
try:
while True:
ready = select.select([sdRef], [], [])
if sdRef in ready[0]:
pybonjour.DNSServiceProcessResult(sdRef)
except KeyboardInterrupt:
pass
finally:
sdRef.close()
This diff is collapsed.
#!/usr/bin/env python
################################################################################
#
# Copyright (c) 2007-2008 Christopher J. Stawarz
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
from distutils.core import setup
import pybonjour
# Grab the description from the package's doc string
desc = pybonjour.__doc__.strip().split('\n\n')
setup(
name = 'pybonjour',
version = pybonjour.__version__,
author = 'Christopher Stawarz',
author_email = 'cstawarz@csail.mit.edu',
url = 'http://o2s.csail.mit.edu/o2s-wiki/pybonjour',
description = desc[0].strip(),
long_description = desc[1].strip(),
download_url = 'http://o2s.csail.mit.edu/download/pybonjour/',
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python',
'Topic :: System :: Distributed Computing',
'Topic :: System :: Networking',
],
py_modules = ['pybonjour'],
)
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment