Including Bonjour seems useful, but I don't really want to maintain it. 
  So... it needs a maintainer, and it also needs docs.

Michele Bertoldi wrote:
> Hi all,
> this was already posted on Turbogears mailing list but here is more 
> appropriate,
> 
> is anyone using Bonjour/Zeroconf in Paste?
> I found useful for testing purposes in Turbogears.
> I googled around and haven't found anything so i grabbed some code
> from turbogears/startup.py
> and adapted to Paste httpserver.py.
> Applied the patch just add bonjour=True do [server:main] section of
> config, if you want you can add also server_name and
> server_description to the same section of the ini file.
> Michele.
> diff against Paste-1.6:
> 
> --- httpserver.py.old   2008-03-31 23:21:09.000000000 +0200
> +++ httpserver.py       2008-06-06 01:55:13.000000000 +0200
> @@ -1122,12 +1122,54 @@
>     Raised to tell the server to really exit (SystemExit is normally
>     caught)
>     """
> +
> +DNS_SD_PID = None
> +
> +def start_bonjour(host=None, port=None, server_name=None,
> server_description=None):
> +    global DNS_SD_PID
> +    if DNS_SD_PID:
> +        return
> +
> +    if host=='0.0.0.0 <http://0.0.0.0>': host=''
> +    if not server_name: server_name='Paste'
> +    if not server_description: server_description='port '+str(port)
> +    name = server_name + ": " + server_description
> +    type = "_http._tcp"
> +    port = str(port)
> +    cmds = [['/usr/bin/avahi-publish-service', ["-H", host, name,
> type, port]],
> +            ['/usr/bin/dns-sd', ['-R', name, type, "."+host, port,
> "path=/"]]]
> +
> +    for cmd, args in cmds:
> +        # TODO:. This check is flawed.  If one has both services
> installed and
> +        # avahi isn't the one running, then this won't work.  We
> should either
> +        # try registering with both or checking what service is
> running and use
> +        # that.  Program availability on the filesystem was never
> enough...
> +        if os.path.exists(cmd):
> +            DNS_SD_PID = os.spawnv(os.P_NOWAIT, cmd, [cmd]+args)
> +            atexit.register(stop_bonjour)
> +            break
> +
> +
> +def stop_bonjour():
> +    import signal
> +    if not DNS_SD_PID:
> +        return
> +    try:
> +        os.kill(DNS_SD_PID, signal.SIGTERM)
> +    except OSError:
> +        pass
> +
> +
> +class DaemonizeException(Exception):
> +    pass
> +
> +
> 
>  def serve(application, host=None, port=None, handler=None,
> ssl_pem=None,
>           ssl_context=None, server_version=None,
> protocol_version=None,
>           start_loop=True, daemon_threads=None, socket_timeout=None,
>           use_threadpool=None, threadpool_workers=10,
> -          threadpool_options=None):
> +          threadpool_options=None,bonjour=None,server_name=None,
> server_description=None):
>     """
>     Serves your ``application`` over HTTP(S) via WSGI interface
> 
> @@ -1244,7 +1286,8 @@
>         else:
>             port = 8080
>     server_address = (host, int(port))
> -
> +    if bonjour:
> +        start_bonjour(host=host,port=port,server_name=server_name,
> server_description=server_description)
>     if not handler:
>         handler = WSGIHandler
>     if server_version:
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Paste-users mailing list
> [email protected]
> http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users


-- 
Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org

_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users

Reply via email to