| OLD | NEW |
| 1 # Copyright (c) 2003-2014 LOGILAB S.A. (Paris, FRANCE). | 1 # Copyright (c) 2003-2014 LOGILAB S.A. (Paris, FRANCE). |
| 2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 3 # | 3 # |
| 4 # This program is free software; you can redistribute it and/or modify it under | 4 # This program is free software; you can redistribute it and/or modify it under |
| 5 # the terms of the GNU General Public License as published by the Free Software | 5 # the terms of the GNU General Public License as published by the Free Software |
| 6 # Foundation; either version 2 of the License, or (at your option) any later | 6 # Foundation; either version 2 of the License, or (at your option) any later |
| 7 # version. | 7 # version. |
| 8 # | 8 # |
| 9 # This program is distributed in the hope that it will be useful, but WITHOUT | 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 obj.reverse() | 121 obj.reverse() |
| 122 return module, '.'.join(obj) | 122 return module, '.'.join(obj) |
| 123 | 123 |
| 124 def category_id(cid): | 124 def category_id(cid): |
| 125 cid = cid.upper() | 125 cid = cid.upper() |
| 126 if cid in MSG_TYPES: | 126 if cid in MSG_TYPES: |
| 127 return cid | 127 return cid |
| 128 return MSG_TYPES_LONG.get(cid) | 128 return MSG_TYPES_LONG.get(cid) |
| 129 | 129 |
| 130 | 130 |
| 131 def _decoding_readline(stream, module): |
| 132 return lambda: stream.readline().decode(module.file_encoding, |
| 133 'replace') |
| 134 |
| 135 |
| 131 def tokenize_module(module): | 136 def tokenize_module(module): |
| 132 stream = module.file_stream | 137 with module.stream() as stream: |
| 133 stream.seek(0) | 138 readline = stream.readline |
| 134 readline = stream.readline | 139 if sys.version_info < (3, 0): |
| 135 if sys.version_info < (3, 0): | 140 if module.file_encoding is not None: |
| 136 if module.file_encoding is not None: | 141 readline = _decoding_readline(stream, module) |
| 137 readline = lambda: stream.readline().decode(module.file_encoding, | 142 return list(tokenize.generate_tokens(readline)) |
| 138 'replace') | 143 return list(tokenize.tokenize(readline)) |
| 139 return list(tokenize.generate_tokens(readline)) | |
| 140 return list(tokenize.tokenize(readline)) | |
| 141 | 144 |
| 142 def build_message_def(checker, msgid, msg_tuple): | 145 def build_message_def(checker, msgid, msg_tuple): |
| 143 if implements(checker, (IRawChecker, ITokenChecker)): | 146 if implements(checker, (IRawChecker, ITokenChecker)): |
| 144 default_scope = WarningScope.LINE | 147 default_scope = WarningScope.LINE |
| 145 else: | 148 else: |
| 146 default_scope = WarningScope.NODE | 149 default_scope = WarningScope.NODE |
| 147 options = {} | 150 options = {} |
| 148 if len(msg_tuple) > 3: | 151 if len(msg_tuple) > 3: |
| 149 (msg, symbol, descr, options) = msg_tuple | 152 (msg, symbol, descr, options) = msg_tuple |
| 150 elif len(msg_tuple) > 2: | 153 elif len(msg_tuple) > 2: |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if scope == 'module': | 263 if scope == 'module': |
| 261 self.file_state.set_msg_status(msg, line, False) | 264 self.file_state.set_msg_status(msg, line, False) |
| 262 if msg.symbol != 'locally-disabled': | 265 if msg.symbol != 'locally-disabled': |
| 263 self.add_message('locally-disabled', line=line, | 266 self.add_message('locally-disabled', line=line, |
| 264 args=(msg.symbol, msg.msgid)) | 267 args=(msg.symbol, msg.msgid)) |
| 265 | 268 |
| 266 else: | 269 else: |
| 267 msgs = self._msgs_state | 270 msgs = self._msgs_state |
| 268 msgs[msg.msgid] = False | 271 msgs[msg.msgid] = False |
| 269 # sync configuration object | 272 # sync configuration object |
| 270 self.config.disable_msg = [mid for mid, val in six.iteritems(msgs) | 273 self.config.disable = [mid for mid, val in six.iteritems(msgs) |
| 271 if not val] | 274 if not val] |
| 272 | 275 |
| 273 def enable(self, msgid, scope='package', line=None, ignore_unknown=False): | 276 def enable(self, msgid, scope='package', line=None, ignore_unknown=False): |
| 274 """reenable message of the given id""" | 277 """reenable message of the given id""" |
| 275 assert scope in ('package', 'module') | 278 assert scope in ('package', 'module') |
| 276 catid = category_id(msgid) | 279 catid = category_id(msgid) |
| 277 # msgid is a category? | 280 # msgid is a category? |
| 278 if catid is not None: | 281 if catid is not None: |
| 279 for msgid in self.msgs_store._msgs_by_category.get(catid): | 282 for msgid in self.msgs_store._msgs_by_category.get(catid): |
| 280 self.enable(msgid, scope, line) | 283 self.enable(msgid, scope, line) |
| 281 return | 284 return |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 | 910 |
| 908 try: | 911 try: |
| 909 return getattr(checker.config, option.replace("-", "_")) | 912 return getattr(checker.config, option.replace("-", "_")) |
| 910 except AttributeError: | 913 except AttributeError: |
| 911 pass | 914 pass |
| 912 for provider in checker.linter.options_providers: | 915 for provider in checker.linter.options_providers: |
| 913 for options in provider.options: | 916 for options in provider.options: |
| 914 if options[0] == option: | 917 if options[0] == option: |
| 915 return getattr(provider.config, option.replace("-", "_")) | 918 return getattr(provider.config, option.replace("-", "_")) |
| 916 return default | 919 return default |
| OLD | NEW |