Commits

Travis Shirk committed 42e903e

Removed handleFile R_CONT, R_HAT in favor of StopIteration

Comments (0)

Files changed (8)

src/eyed3/plugins/__init__.py

         self.config = config
 
     def handleFile(self, f):
-        return utils.FileHandler.R_CONT
+        pass
 
     def handleDone(self):
         pass
         mtype = utils.guessMimetype(f)
         if mtype is None or not (mtype.startswith("audio/") or
                                  mtype.startswith("application/")):
-            return utils.FileHandler.R_CONT
+            return
 
         self._num_loaded += 1
         try:
             if not self.audio_file:
                 printError("Unsupported file type: %s" % f)
 
-        return utils.FileHandler.R_CONT
-
     def handleDone(self):
         if self._num_loaded == 0:
             printMsg("Nothing to do")

src/eyed3/plugins/classic.py

         super(ClassicPlugin, self).handleFile(f, tag_version=parse_version)
 
         if not self.audio_file:
-            return self.R_CONT
+            return
 
         try:
             self.printHeader(f)
             if not save_tag and new_tag:
                 printError("No ID3 %s tag found!" %
                            id3.versionToString(self.args.tag_version))
-                return self.R_CONT
+                return
 
             self.printTag(self.audio_file.tag)
 
             log.error(traceback.format_exc())
             if self.args.debug_pdb:
                 import pdb; pdb.set_trace()
-            return self.R_HALT
-
-        return self.R_CONT
+            raise StopIteration()
 
     def printHeader(self, file_path):
         from stat import ST_SIZE

src/eyed3/plugins/examples.py

         else:
             self.mts[mt] = 1
         self.count += 1
-        return self.R_CONT
 
     def handleDone(self):
         printMsg("%d files checked" % self.count)

src/eyed3/plugins/lameinfo.py

         self.printHeader(f)
         if not self.audio_file or not self.audio_file.info.lame_tag:
             printMsg('No LAME Tag')
-            return self.R_CONT
+            return
 
         format = '%-20s: %s'
         lt = self.audio_file.info.lame_tag
                 printMsg('%s: %s' % ('Encoder Version', lt['encoder_version']))
             except KeyError:
                 pass
-            return self.R_CONT
+            return
 
         values = []
 

src/eyed3/plugins/statistics.py

                     self.bitrates[key] += 1
                     break
 
-        return self.R_CONT
-
     def handleDone(self):
         print("\nAnalyzed %d audio files (%d non-audio) (%d hidden)" %
               (self.count, self.non_audio_file_count, self.hidden_file_count))

src/eyed3/plugins/xep_118.py

             xml = self.getXML(self.audio_file)
             printMsg(xml)
 
-        return self.R_CONT
-
     def getXML(self, audio_file):
         tag = audio_file.tag
 

src/eyed3/utils/__init__.py

             f = f if type(f) is unicode else unicode(f, fs_encoding)
             f = os.path.abspath(os.path.join(root, f))
             if not _isExcluded(f):
-                if handler.handleFile(f) == FileHandler.R_HALT:
-                    return FileHandler.R_HALT
+                try:
+                    handler.handleFile(f)
+                except StopIteration:
+                    return
 
 
-##
-# A handler type for \c walk iterators.
 class FileHandler(object):
-    ## Return code which communicates that the iteration continue.
-    R_CONT = 0
-    ## Return code which communicates that the iteration stop.
-    R_HALT = -1
+    '''A handler interface for :func:`eyed3.utils.walk` callbacks.'''
 
-    ##
-    # Called for each file, MUST return either R_CONT to continue getting
-    # files or R_HALT to stop.
-    # 
-    # \param f The path to the file being visited.
-    # \returns Returns R_CONT to continue iterating or R_HALT to stop.
     def handleFile(self, f):
-        return FileHandler.R_CONT
+        '''Called for each file walked. The file ``f`` is the full path and
+        the return value is ignored. If the walk should abort the method should
+        raise a ``StopIteration`` exception.'''
+        pass
 
-    ##
-    # Called when there are no more files to handle.
     def handleDone(self):
+        '''Called when there are no more files to handle.'''
         pass
 
 

src/test/test_plugins.py

     assert_equal(p.args, "dummy_args")
     assert_equal(p.config, "dummy_config")
 
-    assert_equal(p.handleFile("f.txt"), FileHandler.R_CONT)
+    assert_is_none(p.handleFile("f.txt"))
     assert_is_none(p.handleDone())