Browse Source

Rename _check to _parse

Since it didn't just check, it returned the object in some way.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac353@3232 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
8ec371d53d

+ 3 - 3
src/bin/bind10/bind10.py.in

@@ -63,7 +63,7 @@ import pwd
 import posix
 import posix
 
 
 import isc.cc
 import isc.cc
-import isc.net.check
+import isc.net.parse
 import isc.utils.process
 import isc.utils.process
 
 
 # Assign this process some longer name
 # Assign this process some longer name
@@ -582,7 +582,7 @@ def check_port(option, opt_str, value, parser):
     a valid port number. Used by OptionParser() on startup."""
     a valid port number. Used by OptionParser() on startup."""
     try:
     try:
         if opt_str in ['-p', '--port']:
         if opt_str in ['-p', '--port']:
-            parser.values.auth_port = isc.net.check.port_check(value)
+            parser.values.auth_port = isc.net.parse.port_parse(value)
         else:
         else:
             raise OptionValueError("Unknown option " + opt_str)
             raise OptionValueError("Unknown option " + opt_str)
     except ValueError as e:
     except ValueError as e:
@@ -593,7 +593,7 @@ def check_addr(option, opt_str, value, parser):
     a valid address. Used by OptionParser() on startup."""
     a valid address. Used by OptionParser() on startup."""
     try:
     try:
         if opt_str in ['-a', '--address']:
         if opt_str in ['-a', '--address']:
-            parser.values.address = isc.net.check.addr_check(value)
+            parser.values.address = isc.net.parse.addr_parse(value)
         else:
         else:
             raise OptionValueError("Unknown option " + opt_str)
             raise OptionValueError("Unknown option " + opt_str)
     except ValueError:
     except ValueError:

+ 3 - 3
src/bin/cmdctl/cmdctl.py.in

@@ -42,7 +42,7 @@ import random
 import time
 import time
 import signal
 import signal
 from isc.config import ccsession
 from isc.config import ccsession
-import isc.net.check
+import isc.net.parse
 import isc.utils.process
 import isc.utils.process
 from optparse import OptionParser, OptionValueError
 from optparse import OptionParser, OptionValueError
 from hashlib import sha1
 from hashlib import sha1
@@ -566,13 +566,13 @@ def run(addr = 'localhost', port = 8080, idle_timeout = 1200, verbose = False):
 
 
 def check_port(option, opt_str, value, parser):
 def check_port(option, opt_str, value, parser):
     try:
     try:
-        parser.values.port = isc.net.check.port_check(value)
+        parser.values.port = isc.net.parse.port_parse(value)
     except ValueError as e:
     except ValueError as e:
         raise OptionValueError(str(e))
         raise OptionValueError(str(e))
 
 
 def check_addr(option, opt_str, value, parser):
 def check_addr(option, opt_str, value, parser):
     try:
     try:
-        isc.net.check.addr_check(value)
+        isc.net.parse.addr_parse(value)
         parser.values.addr = value
         parser.values.addr = value
     except ValueError as e:
     except ValueError as e:
         raise OptionValueError(str(e))
         raise OptionValueError(str(e))

+ 6 - 7
src/bin/xfrin/xfrin.py.in

@@ -29,7 +29,7 @@ import random
 from optparse import OptionParser, OptionValueError
 from optparse import OptionParser, OptionValueError
 from isc.config.ccsession import *
 from isc.config.ccsession import *
 from isc.notify import notify_out
 from isc.notify import notify_out
-import isc.net.check
+import isc.net.parse
 import isc.utils.process
 import isc.utils.process
 try:
 try:
     from pydnspp import *
     from pydnspp import *
@@ -402,13 +402,12 @@ class Xfrin:
     def config_handler(self, new_config):
     def config_handler(self, new_config):
         self._max_transfers_in = new_config.get("transfers_in") or self._max_transfers_in
         self._max_transfers_in = new_config.get("transfers_in") or self._max_transfers_in
         if ('master_addr' in new_config) or ('master_port' in new_config):
         if ('master_addr' in new_config) or ('master_port' in new_config):
-            # Check if the new master is valid, there should be library for check it.
-            # and user should change the port and address together.
+            # User should change the port and address together.
             try:
             try:
                 addr = new_config.get('master_addr') or self._master_addr
                 addr = new_config.get('master_addr') or self._master_addr
                 port = new_config.get('master_port') or self._master_port
                 port = new_config.get('master_port') or self._master_port
-                isc.net.check.addr_check(addr)
-                isc.net.check.port_check(port)
+                isc.net.parse.addr_parse(addr)
+                isc.net.parse.port_parse(port)
                 self._master_addr = addr
                 self._master_addr = addr
                 self._master_port = port
                 self._master_port = port
             except ValueError:
             except ValueError:
@@ -568,8 +567,8 @@ def build_addr_info(addrstr, portstr):
     (address, port). The socktype is socket.SOCK_STREAM for now.
     (address, port). The socktype is socket.SOCK_STREAM for now.
     """
     """
     try:
     try:
-        port = isc.net.check.port_check(portstr)
-        addr = isc.net.check.addr_check(addrstr)
+        port = isc.net.parse.port_parse(portstr)
+        addr = isc.net.parse.addr_parse(addrstr)
         return (addr.family, socket.SOCK_STREAM, (addrstr, port))
         return (addr.family, socket.SOCK_STREAM, (addrstr, port))
     except ValueError as err:
     except ValueError as err:
         raise XfrinException("failed to resolve master address/port=%s/%s: %s" %
         raise XfrinException("failed to resolve master address/port=%s/%s: %s" %

+ 1 - 1
src/lib/python/isc/net/Makefile.am

@@ -1,5 +1,5 @@
 SUBDIRS = tests
 SUBDIRS = tests
 
 
-python_PYTHON = __init__.py addr.py check.py
+python_PYTHON = __init__.py addr.py parse.py
 
 
 pythondir = $(pyexecdir)/isc/net
 pythondir = $(pyexecdir)/isc/net

+ 2 - 2
src/lib/python/isc/net/check.py

@@ -20,7 +20,7 @@ Checking and parsing of ports and IP addresses.
 from isc.net.addr import IPAddr
 from isc.net.addr import IPAddr
 import socket
 import socket
 
 
-def port_check(port):
+def port_parse(port):
     """
     """
     Takes a port as an int or string and checks if it is valid. It returns
     Takes a port as an int or string and checks if it is valid. It returns
     the port as int. If it is not a valid port (the string doesn't contain
     the port as int. If it is not a valid port (the string doesn't contain
@@ -35,7 +35,7 @@ def port_check(port):
             " too large, allowed range is 0-65535")
             " too large, allowed range is 0-65535")
     return inted
     return inted
 
 
-def addr_check(addr):
+def addr_parse(addr):
     """
     """
     Checks and parses an IP address (either IPv4 or IPv6) and returns
     Checks and parses an IP address (either IPv4 or IPv6) and returns
     the IPAddr object. It raises ValueError if the passed string is not
     the IPAddr object. It raises ValueError if the passed string is not

+ 1 - 1
src/lib/python/isc/net/tests/Makefile.am

@@ -1,4 +1,4 @@
-PYTESTS = addr_test.py check_test.py
+PYTESTS = addr_test.py parse_test.py
 EXTRA_DIST = $(PYTESTS)
 EXTRA_DIST = $(PYTESTS)
 
 
 # later will have configure option to choose this, like: coverage run --branch
 # later will have configure option to choose this, like: coverage run --branch

+ 23 - 23
src/lib/python/isc/net/tests/check_test.py

@@ -13,61 +13,61 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 
-"""Tests for isc.net.check."""
+"""Tests for isc.net.parse."""
 import unittest
 import unittest
-from isc.net.check import port_check, addr_check
+from isc.net.parse import port_parse, addr_parse
 
 
 class TestCheckPort(unittest.TestCase):
 class TestCheckPort(unittest.TestCase):
     """
     """
-    Testcases for the isc.net.port_check function
+    Testcases for the isc.net.port_parse function
     """
     """
     def test_fail(self):
     def test_fail(self):
         """
         """
         Test if it fails on invalid input in the correct way.
         Test if it fails on invalid input in the correct way.
         """
         """
-        self.assertRaises(ValueError, port_check, "not a number")
-        self.assertRaises(ValueError, port_check, -1)
-        self.assertRaises(ValueError, port_check, 65536)
+        self.assertRaises(ValueError, port_parse, "not a number")
+        self.assertRaises(ValueError, port_parse, -1)
+        self.assertRaises(ValueError, port_parse, 65536)
 
 
     def test_success(self):
     def test_success(self):
         """
         """
         Test if it succeeds on valid inputs and returns the correct output
         Test if it succeeds on valid inputs and returns the correct output
         """
         """
-        self.assertEqual(port_check(0), 0)
-        self.assertEqual(port_check("65535"), 65535)
-        self.assertEqual(port_check(1234), 1234)
+        self.assertEqual(port_parse(0), 0)
+        self.assertEqual(port_parse("65535"), 65535)
+        self.assertEqual(port_parse(1234), 1234)
 
 
 class TestCheckIP(unittest.TestCase):
 class TestCheckIP(unittest.TestCase):
     """
     """
-    Testcases for the isc.net.ip_check function
+    Testcases for the isc.net.ip_par function
     """
     """
     def test_fail(self):
     def test_fail(self):
         """
         """
         Test if it fails on invalid input the correct way.
         Test if it fails on invalid input the correct way.
         """
         """
-        self.assertRaises(ValueError, addr_check, "not an address")
-        self.assertRaises(ValueError, addr_check, "123.456.789.012")
-        self.assertRaises(ValueError, addr_check, "123.0.0.")
+        self.assertRaises(ValueError, addr_parse, "not an address")
+        self.assertRaises(ValueError, addr_parse, "123.456.789.012")
+        self.assertRaises(ValueError, addr_parse, "123.0.0.")
         # Address range not allowed
         # Address range not allowed
-        self.assertRaises(ValueError, addr_check, "192.0.2.0/24")
-        self.assertRaises(ValueError, addr_check, "0000.0.0.0")
-        self.assertRaises(ValueError, addr_check, "bada:ddr0::")
-        self.assertRaises(ValueError, addr_check, "2001:db8::/32")
+        self.assertRaises(ValueError, addr_parse, "192.0.2.0/24")
+        self.assertRaises(ValueError, addr_parse, "0000.0.0.0")
+        self.assertRaises(ValueError, addr_parse, "bada:ddr0::")
+        self.assertRaises(ValueError, addr_parse, "2001:db8::/32")
         # This should be one part too long (eg. 9 segments)
         # This should be one part too long (eg. 9 segments)
-        self.assertRaises(ValueError, addr_check, "2001:db8:0:0:0:0:0:0:0")
+        self.assertRaises(ValueError, addr_parse, "2001:db8:0:0:0:0:0:0:0")
         # Only one :: allowed
         # Only one :: allowed
-        self.assertRaises(ValueError, addr_check, "2001::db8::c")
+        self.assertRaises(ValueError, addr_parse, "2001::db8::c")
 
 
     def test_success(self):
     def test_success(self):
         """
         """
         Test if it succeeds on valid inputs and returns addresses that look
         Test if it succeeds on valid inputs and returns addresses that look
         the same.
         the same.
         """
         """
-        self.assertEqual("192.0.2.0", str(addr_check("192.0.2.0")))
-        self.assertEqual("2001:bd8::", str(addr_check("2001:bd8::")))
+        self.assertEqual("192.0.2.0", str(addr_parse("192.0.2.0")))
+        self.assertEqual("2001:bd8::", str(addr_parse("2001:bd8::")))
         # It should strip the unnecesarry parts
         # It should strip the unnecesarry parts
-        self.assertEqual("2001:bd8::", str(addr_check("2001:bd8:0:0:0:0:0:0")))
-        self.assertEqual("::", str(addr_check("::")))
+        self.assertEqual("2001:bd8::", str(addr_parse("2001:bd8:0:0:0:0:0:0")))
+        self.assertEqual("::", str(addr_parse("::")))
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     unittest.main()
     unittest.main()