changeset 368:2d58319eea84

Use modern syntax for raising exceptions.
author cmlenz
date Mon, 23 Jul 2007 13:12:24 +0000
parents 023b0b4a1f20
children 7c3ecdd84e7c
files bitten/build/api.py bitten/master.py bitten/recipe.py bitten/slave.py bitten/snapshot.py bitten/trac_ext/charts.py bitten/trac_ext/tests/web_ui.py bitten/util/beep.py bitten/util/md5sum.py bitten/util/xmlio.py
diffstat 10 files changed, 33 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/build/api.py
+++ b/bitten/build/api.py
@@ -166,7 +166,7 @@
                 writable = [pipe.tochild] * (not in_eof)
                 ready = select.select(readable, writable, [], timeout)
                 if not (ready[0] or ready[1]):
-                    raise TimeoutError, 'Command %s timed out' % self.executable
+                    raise TimeoutError('Command %s timed out' % self.executable)
                 if pipe.tochild in ready[1]:
                     sent = os.write(pipe.tochild.fileno(), in_data)
                     in_data = in_data[sent:]
--- a/bitten/master.py
+++ b/bitten/master.py
@@ -367,7 +367,7 @@
         string = string.split('.', 1)[0] # strip out microseconds
         return calendar.timegm(time.strptime(string, '%Y-%m-%dT%H:%M:%S'))
     except ValueError, e:
-        raise ValueError, 'Invalid ISO date/time %s (%s)' % (string, e)
+        raise ValueError('Invalid ISO date/time %s (%s)' % (string, e))
 
 def main():
     """Main entry point for running the build master."""
--- a/bitten/recipe.py
+++ b/bitten/recipe.py
@@ -74,7 +74,7 @@
             elif name == 'report':
                 function = Context.report_file
             if not function:
-                raise InvalidRecipeError, 'Unknown recipe command %s' % qname
+                raise InvalidRecipeError('Unknown recipe command %s' % qname)
 
             def escape(name):
                 name = name.replace('-', '_')
@@ -185,7 +185,7 @@
                 errors.append((generator, output))
         if errors:
             if self.onerror == 'fail':
-                raise BuildError, 'Build step %s failed' % self.id
+                raise BuildError('Build step %s failed' % self.id)
             log.warning('Ignoring errors in step %s (%s)', self.id,
                         ', '.join([error[1] for error in errors]))
 
@@ -235,29 +235,29 @@
             violated
         """
         if self._root.name != 'build':
-            raise InvalidRecipeError, 'Root element must be <build>'
+            raise InvalidRecipeError('Root element must be <build>')
         steps = list(self._root.children())
         if not steps:
-            raise InvalidRecipeError, 'Recipe defines no build steps'
+            raise InvalidRecipeError('Recipe defines no build steps')
 
         step_ids = set()
         for step in steps:
             if step.name != 'step':
-                raise InvalidRecipeError, 'Only <step> elements allowed ' \
-                                          'at top level of recipe'
+                raise InvalidRecipeError('Only <step> elements allowed at '
+                                         'top level of recipe')
             if not step.attr.get('id'):
-                raise InvalidRecipeError, 'Steps must have an "id" attribute'
+                raise InvalidRecipeError('Steps must have an "id" attribute')
 
             if step.attr['id'] in step_ids:
-                raise InvalidRecipeError, 'Duplicate step ID "%s"' \
-                                          % step.attr['id']
+                raise InvalidRecipeError('Duplicate step ID "%s"' %
+                                         step.attr['id'])
             step_ids.add(step.attr['id'])
 
             cmds = list(step.children())
             if not cmds:
-                raise InvalidRecipeError, 'Step "%s" has no recipe commands' \
-                                          % step.attr['id']
+                raise InvalidRecipeError('Step "%s" has no recipe commands' %
+                                         step.attr['id'])
             for cmd in cmds:
                 if len(list(cmd.children())):
-                    raise InvalidRecipeError, 'Recipe command <%s> has ' \
-                                              'nested content' % cmd.name
+                    raise InvalidRecipeError('Recipe command <%s> has nested '
+                                             'content' % cmd.name)
--- a/bitten/slave.py
+++ b/bitten/slave.py
@@ -66,7 +66,7 @@
         if OrchestrationProfileHandler.URI not in profiles:
             err = 'Peer does not support the Bitten orchestration profile'
             log.error(err)
-            raise beep.TerminateSession, err
+            raise beep.TerminateSession(err)
         self.channels[0].profile.send_start([OrchestrationProfileHandler])
 
 
@@ -87,7 +87,7 @@
                     if elem.name == 'error':
                         log.error('Slave registration failed: %s (%d)',
                                   elem.gettext(), int(elem.attr['code']))
-                raise beep.TerminateSession, 'Registration failed!'
+                raise beep.TerminateSession('Registration failed!')
             log.info('Registration successful')
 
         self.config = Configuration(self.session.config)
@@ -276,7 +276,7 @@
             self.channel.send_ans(msgno, beep.Payload(xml))
             self.channel.send_nul(msgno)
 
-            raise beep.TerminateSession, 'Cancelled'
+            raise beep.TerminateSession('Cancelled')
 
 
 def main():
--- a/bitten/snapshot.py
+++ b/bitten/snapshot.py
@@ -79,8 +79,8 @@
 
         # Make sure we have permissions to write to the directory
         if not os.access(self.directory, os.R_OK + os.W_OK):
-            raise IOError, 'Insufficient permissions to create snapshots in ' \
-                           + self.directory
+            raise IOError('Insufficient permissions to create snapshots in %s' %
+                          self.directory)
 
         # Collect a list of all existing snapshot archives
         self._index = []
@@ -161,8 +161,8 @@
             filename = new_prefix + '.tar.bz2'
             new_filepath = os.path.join(self.directory, filename)
             if os.path.exists(new_filepath):
-                raise IOError, 'Snapshot file already exists at %s' \
-                               % new_filepath
+                raise IOError('Snapshot file already exists at %s' %
+                              new_filepath)
 
             self._cleanup(self.limit - 1)
 
--- a/bitten/trac_ext/charts.py
+++ b/bitten/trac_ext/charts.py
@@ -39,7 +39,7 @@
                                                          category)
                 break
         else:
-            raise TracError, 'Unknown report category "%s"' % category
+            raise TracError('Unknown report category "%s"' % category)
 
         return template, 'text/xml'
 
--- a/bitten/trac_ext/tests/web_ui.py
+++ b/bitten/trac_ext/tests/web_ui.py
@@ -223,7 +223,7 @@
                          'label': 'Test', 'description': 'Bla bla'})
 
         def get_node(path, rev=None):
-            raise TracError, 'No such node'
+            raise TracError('No such node')
         self.repos = Mock(get_node=get_node)
 
         module = BuildConfigController(self.env)
--- a/bitten/util/beep.py
+++ b/bitten/util/beep.py
@@ -296,7 +296,7 @@
                     log.error('Malformed frame header: [%s]',
                               ' '.join(self.header), exc_info=True)
                     self.header = None
-                    raise TerminateSession, 'Malformed frame header'
+                    raise TerminateSession('Malformed frame header')
             if size == 0:
                 self.payload = ''
                 self.set_terminator('END\r\n')
@@ -352,7 +352,7 @@
 
         except (AssertionError, IndexError, TypeError, ValueError), e:
             log.error('Malformed frame', exc_info=True)
-            raise TerminateSession, 'Malformed frame header'
+            raise TerminateSession('Malformed frame header')
 
     def terminate(self, handle_ok=None, handle_error=None):
         """Terminate the session by closing all channels."""
@@ -468,7 +468,7 @@
         """
         # Validate and update sequence number
         if seqno != self.seqno[0]:
-            raise TerminateSession, 'Out of sync with peer'
+            raise TerminateSession('Out of sync with peer')
         self.seqno[0] += len(payload)
 
         if more:
--- a/bitten/util/md5sum.py
+++ b/bitten/util/md5sum.py
@@ -73,7 +73,7 @@
         if not os.path.isfile(md5file):
             md5file = os.path.splitext(filename)[0] + '.md5'
             if not os.path.isfile(md5file):
-                raise IntegrityError, 'Checksum file not found'
+                raise IntegrityError('Checksum file not found')
         fileobj = file(md5file, 'r')
         try:
             content = fileobj.read()
@@ -82,10 +82,10 @@
         try:
             checksum, path = content.split('  ')
         except ValueError:
-            raise IntegrityError, 'Checksum file invalid'
+            raise IntegrityError('Checksum file invalid')
         if path != os.path.basename(filename):
-            raise IntegrityError, 'Checksum for a different file'
+            raise IntegrityError('Checksum for a different file')
 
     expected = generate(filename)
     if expected != checksum:
-        raise IntegrityError, 'Checksum does not match'
+        raise IntegrityError('Checksum does not match')
--- a/bitten/util/xmlio.py
+++ b/bitten/util/xmlio.py
@@ -180,7 +180,7 @@
             dom = minidom.parse(text_or_file)
         return ParsedElement(dom.documentElement)
     except expat.error, e:
-        raise ParseError, e
+        raise ParseError(e)
 
 
 class ParsedElement(object):
@@ -246,7 +246,7 @@
         def __getitem__(self, name):
             attr = self._node.getAttributeNode(name)
             if not attr:
-                raise KeyError, name
+                raise KeyError(name)
             return attr.value.encode('utf-8')
         def __setitem__(self, name, value):
             self._node.setAttribute(name, value)
Copyright (C) 2012-2017 Edgewall Software