[ZCM] [ZC] 1840/ 2 Comment "ZConfig does not allow symbolic port
names"
Collector: Zope Bugs, Features,
and Patches ...
zope-coders-admin at zope.org
Mon Jul 11 10:09:20 EDT 2005
Issue #1840 Update (Comment) "ZConfig does not allow symbolic port names"
Status Accepted, Zope/bug medium
To followup, visit:
http://www.zope.org/Collectors/Zope/1840
==============================================================
= Comment - Entry #2 by tino on Jul 11, 2005 10:07 am
Patches:
>===================================================================
>--- lib/python/ZConfig/datatypes.py (Revision 33263)
>+++ lib/python/ZConfig/datatypes.py (Arbeitskopie)
>@@ -164,7 +164,24 @@
> return s.split()
>
>
>-port_number = RangeCheckedConversion(integer, min=1, max=0xffff).__call__
>+def port_number(portliteral,protocol='tcp'):
>+ "replacement for simple rangecheck to allow etc/services entries as ports"
>+ import socket
>+ try:
>+ p=integer(portliteral)
>+ except ValueError:
>+ try:
>+ p=socket.getservbyname(portliteral,protocol)
>+ except socket.error:
>+ raise ValueError("%r is not in etc/services" % portliteral)
>+ return p
>+ if p < 1:
>+ raise ValueError("%s is below lower bound (%s)"
>+ % (`p`, 1))
>+ if p > 0xffff:
>+ raise ValueError("%s is above upper bound (%s)"
>+ % (`p`, 0xffff))
>+ return p
>
>===================================================================
>--- lib/python/ZConfig/tests/test_datatypes.py (Revision 33263)
>+++ lib/python/ZConfig/tests/test_datatypes.py (Arbeitskopie)
>@@ -186,6 +186,8 @@
> eq(convert(":80"), (defhost, 80))
> eq(convert("80"), (defhost, 80))
> eq(convert("host.EXAMPLE.com"), ("host.example.com", None))
>+ # test getservbyname - breaks if services file is bad
>+ eq(convert(":chargen"), (defhost,19))
> self.assertRaises(ValueError, convert, "40 # foo")
>
> def test_datatype_inet_binding_address(self):
>@@ -196,6 +198,8 @@
> eq(convert(":80"), (defhost, 80))
> eq(convert("80"), (defhost, 80))
> eq(convert("host.EXAMPLE.com"), ("host.example.com", None))
>+ # test getservbyname - breaks if services file is bad
>+ eq(convert(":chargen"), (defhost,19))
> self.assertRaises(ValueError, convert, "40 # foo")
>
> def test_datatype_inet_connection_address(self):
>@@ -206,6 +210,8 @@
> eq(convert(":80"), (defhost, 80))
> eq(convert("80"), (defhost, 80))
> eq(convert("host.EXAMPLE.com"), ("host.example.com", None))
>+ # test getservbyname - breaks if services file is bad
>+ eq(convert(":chargen"), (defhost,19))
> self.assertRaises(ValueError, convert, "40 # foo")
>
> def test_datatype_integer(self):
>
________________________________________
= Request - Entry #1 by tino on Jul 11, 2005 10:03 am
Status: Pending => Accepted
Supporters added: tino
when you specify an address (for binding services like ZEO, Zserver)
it is usually handy to use symbolic names from DNS/hosts for
hostnames (which works) and also for services (which does not)
e.g.
address zeoserver:images
is easier to read then
address zeoserver:12345
If you have a lot of server and use to move them around, just changing
etc/services is less work then changing all the *conf files.
Also netstat -ltp (linux) will show you the port with name so
you can easily spot which service is running.
Last not least any internet program uses getservbyname
to resolve symbolic port names and so should zope.
==============================================================
More information about the Zope-Collector-Monitor
mailing list