# HG changeset patch # User cmlenz # Date 1185196344 0 # Node ID 2d58319eea84b31b1a684b18c01e799e2cc306be # Parent 023b0b4a1f20345b2de61ee44c91bf57a6722ed5 Use modern syntax for raising exceptions. diff --git a/bitten/build/api.py b/bitten/build/api.py --- 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:] diff --git a/bitten/master.py b/bitten/master.py --- 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.""" diff --git a/bitten/recipe.py b/bitten/recipe.py --- 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 ' + raise InvalidRecipeError('Root element must be ') 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 elements allowed ' \ - 'at top level of recipe' + raise InvalidRecipeError('Only 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) diff --git a/bitten/slave.py b/bitten/slave.py --- 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(): diff --git a/bitten/snapshot.py b/bitten/snapshot.py --- 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) diff --git a/bitten/trac_ext/charts.py b/bitten/trac_ext/charts.py --- 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' diff --git a/bitten/trac_ext/tests/web_ui.py b/bitten/trac_ext/tests/web_ui.py --- 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) diff --git a/bitten/util/beep.py b/bitten/util/beep.py --- 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: diff --git a/bitten/util/md5sum.py b/bitten/util/md5sum.py --- 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') diff --git a/bitten/util/xmlio.py b/bitten/util/xmlio.py --- 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)