| Index: third_party/pylint/checkers/__init__.py
 | 
| ===================================================================
 | 
| --- third_party/pylint/checkers/__init__.py	(revision 292986)
 | 
| +++ third_party/pylint/checkers/__init__.py	(working copy)
 | 
| @@ -1,4 +1,4 @@
 | 
| -# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
 | 
| +# Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
 | 
|  # http://www.logilab.fr/ -- mailto:contact@logilab.fr
 | 
|  #
 | 
|  # This program is free software; you can redistribute it and/or modify it under
 | 
| @@ -12,7 +12,7 @@
 | 
|  #
 | 
|  # You should have received a copy of the GNU General Public License along with
 | 
|  # this program; if not, write to the Free Software Foundation, Inc.,
 | 
| -# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 | 
| +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 | 
|  """utilities methods and classes for checkers
 | 
|  
 | 
|  Base id of standard checkers (used in msg and report ids):
 | 
| @@ -29,7 +29,8 @@
 | 
|  11: typecheck
 | 
|  12: logging
 | 
|  13: string_format
 | 
| -14-50: not yet used: reserved for future internal checkers.
 | 
| +14: string_constant
 | 
| +15-50: not yet used: reserved for future internal checkers.
 | 
|  51-99: perhaps used: reserved for external checkers
 | 
|  
 | 
|  The raw_metrics checker has no number associated since it doesn't emit any
 | 
| @@ -37,14 +38,14 @@
 | 
|  
 | 
|  """
 | 
|  
 | 
| +import sys
 | 
|  import tokenize
 | 
| -from os import listdir
 | 
| -from os.path import dirname, join, isdir, splitext
 | 
| +import warnings
 | 
|  
 | 
| -from logilab.astng.utils import ASTWalker
 | 
|  from logilab.common.configuration import OptionsProviderMixIn
 | 
|  
 | 
| -from pylint.reporters import diff_string, EmptyReport
 | 
| +from pylint.reporters import diff_string
 | 
| +from pylint.utils import register_plugins
 | 
|  
 | 
|  def table_lines_from_stats(stats, old_stats, columns):
 | 
|      """get values listed in <columns> from <stats> and <old_stats>,
 | 
| @@ -67,7 +68,7 @@
 | 
|      return lines
 | 
|  
 | 
|  
 | 
| -class BaseChecker(OptionsProviderMixIn, ASTWalker):
 | 
| +class BaseChecker(OptionsProviderMixIn):
 | 
|      """base class for checkers"""
 | 
|      # checker name (you may reuse an existing one)
 | 
|      name = None
 | 
| @@ -85,22 +86,14 @@
 | 
|  
 | 
|          linter is an object implementing ILinter
 | 
|          """
 | 
| -        ASTWalker.__init__(self, self)
 | 
|          self.name = self.name.lower()
 | 
|          OptionsProviderMixIn.__init__(self)
 | 
|          self.linter = linter
 | 
| -        # messages that are active for the current check
 | 
| -        self.active_msgs = set()
 | 
|  
 | 
|      def add_message(self, msg_id, line=None, node=None, args=None):
 | 
|          """add a message of a given type"""
 | 
|          self.linter.add_message(msg_id, line, node, args)
 | 
|  
 | 
| -    def package_dir(self):
 | 
| -        """return the base directory for the analysed package"""
 | 
| -        return dirname(self.linter.base_file)
 | 
| -
 | 
| -
 | 
|      # dummy methods implementing the IChecker interface
 | 
|  
 | 
|      def open(self):
 | 
| @@ -109,6 +102,7 @@
 | 
|      def close(self):
 | 
|          """called after visiting project (i.e set of modules)"""
 | 
|  
 | 
| +
 | 
|  class BaseRawChecker(BaseChecker):
 | 
|      """base class for raw checkers"""
 | 
|  
 | 
| @@ -119,9 +113,15 @@
 | 
|  
 | 
|          stream must implement the readline method
 | 
|          """
 | 
| +        warnings.warn("Modules that need access to the tokens should "
 | 
| +                      "use the ITokenChecker interface.",
 | 
| +                      DeprecationWarning)
 | 
|          stream = node.file_stream
 | 
| -        stream.seek(0) # XXX may be removed with astng > 0.23
 | 
| -        self.process_tokens(tokenize.generate_tokens(stream.readline))
 | 
| +        stream.seek(0) # XXX may be removed with astroid > 0.23
 | 
| +        if sys.version_info <= (3, 0):
 | 
| +            self.process_tokens(tokenize.generate_tokens(stream.readline))
 | 
| +        else:
 | 
| +            self.process_tokens(tokenize.tokenize(stream.readline))
 | 
|  
 | 
|      def process_tokens(self, tokens):
 | 
|          """should be overridden by subclasses"""
 | 
| @@ -128,36 +128,16 @@
 | 
|          raise NotImplementedError()
 | 
|  
 | 
|  
 | 
| -PY_EXTS = ('.py', '.pyc', '.pyo', '.pyw', '.so', '.dll')
 | 
| +class BaseTokenChecker(BaseChecker):
 | 
| +    """Base class for checkers that want to have access to the token stream."""
 | 
|  
 | 
| +    def process_tokens(self, tokens):
 | 
| +        """Should be overridden by subclasses."""
 | 
| +        raise NotImplementedError()
 | 
| +
 | 
| +
 | 
|  def initialize(linter):
 | 
|      """initialize linter with checkers in this package """
 | 
| -    package_load(linter, __path__[0])
 | 
| +    register_plugins(linter, __path__[0])
 | 
|  
 | 
| -def package_load(linter, directory):
 | 
| -    """load all module and package in the given directory, looking for a
 | 
| -    'register' function in each one, used to register pylint checkers
 | 
| -    """
 | 
| -    globs = globals()
 | 
| -    imported = {}
 | 
| -    for filename in listdir(directory):
 | 
| -        basename, extension = splitext(filename)
 | 
| -        if basename in imported or basename == '__pycache__':
 | 
| -            continue
 | 
| -        if extension in PY_EXTS and basename != '__init__' or (
 | 
| -             not extension and basename != 'CVS' and
 | 
| -             isdir(join(directory, basename))):
 | 
| -            try:
 | 
| -                module = __import__(basename, globs, globs, None)
 | 
| -            except ValueError:
 | 
| -                # empty module name (usually emacs auto-save files)
 | 
| -                continue
 | 
| -            except ImportError, exc:
 | 
| -                import sys
 | 
| -                print >> sys.stderr, "Problem importing module %s: %s" % (filename, exc)
 | 
| -            else:
 | 
| -                if hasattr(module, 'register'):
 | 
| -                    module.register(linter)
 | 
| -                    imported[basename] = 1
 | 
| -
 | 
| -__all__ = ('CheckerHandler', 'BaseChecker', 'initialize', 'package_load')
 | 
| +__all__ = ('BaseChecker', 'initialize')
 | 
| 
 |