Browse Source

[trac547] removed assertions checking type or instance because of reusability of module

Naoki Kambe 14 years ago
parent
commit
41361697fe

+ 0 - 11
src/bin/stats/stats_httpd.py.in

@@ -71,7 +71,6 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
         self.send_head()
         self.send_head()
 
 
     def send_head(self):
     def send_head(self):
-        assert isinstance(self.server, HttpServer)
         try:
         try:
             if self.path == XML_URL_PATH:
             if self.path == XML_URL_PATH:
                 body = self.server.xml_handler()
                 body = self.server.xml_handler()
@@ -107,7 +106,6 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
 
 
     def log_message(self, format, *args):
     def log_message(self, format, *args):
         """Change the default log format"""
         """Change the default log format"""
-        assert isinstance(self.server, HttpServer)
         if self.server.verbose:
         if self.server.verbose:
             self.server.log_writer(
             self.server.log_writer(
                 "[b10-stats-httpd] %s - - [%s] %s\n" %
                 "[b10-stats-httpd] %s - - [%s] %s\n" %
@@ -198,8 +196,6 @@ class StatsHttpd:
         from the config manager"""
         from the config manager"""
         # load config
         # load config
         if len(new_config) > 0:
         if len(new_config) > 0:
-            assert type(self.config) is dict
-            assert type(new_config) is dict
             self.config.update(new_config)
             self.config.update(new_config)
         else:
         else:
             self.config = DEFAULT_CONFIG
             self.config = DEFAULT_CONFIG
@@ -209,8 +205,6 @@ class StatsHttpd:
                         for itm in self.mccs.get_module_spec().get_config_spec()
                         for itm in self.mccs.get_module_spec().get_config_spec()
                         ])
                         ])
                 )
                 )
-        assert 'listen_on' in self.config
-        assert type(self.config['listen_on']) is list
         # remove duplicated element
         # remove duplicated element
         self.http_addrs = list(
         self.http_addrs = list(
             set([ (cf['address'], cf['port']) for cf in self.config['listen_on'] ])
             set([ (cf['address'], cf['port']) for cf in self.config['listen_on'] ])
@@ -219,12 +213,10 @@ class StatsHttpd:
     def open_httpd(self):
     def open_httpd(self):
         """Opens sockets for HTTP. Iterating each HTTP address to be
         """Opens sockets for HTTP. Iterating each HTTP address to be
         configured in spec file"""
         configured in spec file"""
-        assert type(self.http_addrs) is list
         for addr in self.http_addrs:
         for addr in self.http_addrs:
             self.httpd.append(self._open_httpd(addr))
             self.httpd.append(self._open_httpd(addr))
 
 
     def _open_httpd(self, server_address, address_family=None):
     def _open_httpd(self, server_address, address_family=None):
-        assert type(server_address) is tuple
         try:
         try:
             # try IPv6 at first
             # try IPv6 at first
             if address_family is not None:
             if address_family is not None:
@@ -250,7 +242,6 @@ class StatsHttpd:
                 self.write_log(
                 self.write_log(
                     "[b10-stats-httpd] Started on address %s, port %s\n" %
                     "[b10-stats-httpd] Started on address %s, port %s\n" %
                     server_address)
                     server_address)
-        assert isinstance(httpd, HttpServer)
         return httpd
         return httpd
 
 
     def close_httpd(self):
     def close_httpd(self):
@@ -258,7 +249,6 @@ class StatsHttpd:
         if len(self.httpd) == 0:
         if len(self.httpd) == 0:
             return
             return
         for ht in self.httpd:
         for ht in self.httpd:
-            assert type(ht.server_address) is tuple
             if self.verbose:
             if self.verbose:
                 self.write_log(
                 self.write_log(
                     "[b10-stats-httpd] Closing address %s, port %s\n" %
                     "[b10-stats-httpd] Closing address %s, port %s\n" %
@@ -312,7 +302,6 @@ class StatsHttpd:
     def config_handler(self, new_config):
     def config_handler(self, new_config):
         """Config handler for the ModuleCCSession object. It resets
         """Config handler for the ModuleCCSession object. It resets
         addresses and ports to listen HTTP requests on."""
         addresses and ports to listen HTTP requests on."""
-        assert type(new_config) is dict
         if self.verbose:
         if self.verbose:
             self.write_log("[b10-stats-httpd] Loading config : %s\n" % str(new_config))
             self.write_log("[b10-stats-httpd] Loading config : %s\n" % str(new_config))
         for key in new_config.keys():
         for key in new_config.keys():

+ 0 - 1
src/bin/stats/tests/b10-stats-httpd_test.py

@@ -362,7 +362,6 @@ class TestStatsHttpd(unittest.TestCase):
 
 
     def test_config(self):
     def test_config(self):
         d = dict(_UNKNOWN_KEY_=None)
         d = dict(_UNKNOWN_KEY_=None)
-        assert type(d) is dict
         self.assertEqual(
         self.assertEqual(
             self.stats_httpd.config_handler(d),
             self.stats_httpd.config_handler(d),
             isc.config.ccsession.create_answer(
             isc.config.ccsession.create_answer(

+ 0 - 2
src/bin/stats/tests/http/server.py

@@ -22,7 +22,6 @@ class DummyHttpResponse:
         self.log = ""
         self.log = ""
 
 
     def _write_log(self, msg):
     def _write_log(self, msg):
-        assert type(msg) is str
         self.log = self.log + msg
         self.log = self.log + msg
 
 
 class HTTPServer:
 class HTTPServer:
@@ -85,6 +84,5 @@ class BaseHTTPRequestHandler:
     def _write(self, obj):
     def _write(self, obj):
         if self.path != self.response.path:
         if self.path != self.response.path:
             self.response = DummyHttpResponse(path=self.path)
             self.response = DummyHttpResponse(path=self.path)
-        assert type(obj) is bytes
         self.response.body = obj.decode()
         self.response.body = obj.decode()
 
 

+ 0 - 2
src/bin/stats/tests/isc/config/ccsession.py

@@ -22,7 +22,6 @@ from isc.cc.session import Session
 COMMAND_CONFIG_UPDATE = "config_update"
 COMMAND_CONFIG_UPDATE = "config_update"
 
 
 def parse_answer(msg):
 def parse_answer(msg):
-    assert type(msg) is dict
     assert 'result' in msg
     assert 'result' in msg
     try:
     try:
         return msg['result'][0], msg['result'][1]
         return msg['result'][0], msg['result'][1]
@@ -36,7 +35,6 @@ def create_answer(rcode, arg = None):
         return { 'result': [ rcode, arg ] }
         return { 'result': [ rcode, arg ] }
 
 
 def parse_command(msg):
 def parse_command(msg):
-    assert type(msg) is dict
     assert 'command' in msg
     assert 'command' in msg
     try:
     try:
         return msg['command'][0], msg['command'][1]
         return msg['command'][0], msg['command'][1]