| OLD | NEW |
| 1 # Copyright (c) 2002-2010 LOGILAB S.A. (Paris, FRANCE). | 1 # Copyright (c) 2002-2013 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 |
| 11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 # | 12 # |
| 13 # You should have received a copy of the GNU General Public License along with | 13 # You should have received a copy of the GNU General Public License along with |
| 14 # this program; if not, write to the Free Software Foundation, Inc., | 14 # this program; if not, write to the Free Software Foundation, Inc., |
| 15 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 """ | 16 """ |
| 17 generic classes/functions for pyreverse core/extensions | 17 generic classes/functions for pyreverse core/extensions |
| 18 """ | 18 """ |
| 19 | 19 |
| 20 import sys | 20 import sys |
| 21 import re | 21 import re |
| 22 import os | 22 import os |
| 23 | 23 |
| 24 ########### pyreverse option utils ############################## | 24 ########### pyreverse option utils ############################## |
| 25 | 25 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 def insert_default_options(): | 43 def insert_default_options(): |
| 44 """insert default options to sys.argv | 44 """insert default options to sys.argv |
| 45 """ | 45 """ |
| 46 options = get_default_options() | 46 options = get_default_options() |
| 47 options.reverse() | 47 options.reverse() |
| 48 for arg in options: | 48 for arg in options: |
| 49 sys.argv.insert(1, arg) | 49 sys.argv.insert(1, arg) |
| 50 | 50 |
| 51 | 51 |
| 52 | 52 |
| 53 # astng utilities ########################################################### | 53 # astroid utilities ########################################################### |
| 54 | 54 |
| 55 SPECIAL = re.compile('^__[A-Za-z0-9]+[A-Za-z0-9_]*__$') | 55 SPECIAL = re.compile('^__[A-Za-z0-9]+[A-Za-z0-9_]*__$') |
| 56 PRIVATE = re.compile('^__[_A-Za-z0-9]*[A-Za-z0-9]+_?$') | 56 PRIVATE = re.compile('^__[_A-Za-z0-9]*[A-Za-z0-9]+_?$') |
| 57 PROTECTED = re.compile('^_[_A-Za-z0-9]*$') | 57 PROTECTED = re.compile('^_[_A-Za-z0-9]*$') |
| 58 | 58 |
| 59 def get_visibility(name): | 59 def get_visibility(name): |
| 60 """return the visibility from a name: public, protected, private or special | 60 """return the visibility from a name: public, protected, private or special |
| 61 """ | 61 """ |
| 62 if SPECIAL.match(name): | 62 if SPECIAL.match(name): |
| 63 visibility = 'special' | 63 visibility = 'special' |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 _CONSTRUCTOR = 1 | 99 _CONSTRUCTOR = 1 |
| 100 _SPECIAL = 2 | 100 _SPECIAL = 2 |
| 101 _PROTECTED = 4 | 101 _PROTECTED = 4 |
| 102 _PRIVATE = 8 | 102 _PRIVATE = 8 |
| 103 MODES = { | 103 MODES = { |
| 104 'ALL' : 0, | 104 'ALL' : 0, |
| 105 'PUB_ONLY' : _SPECIAL + _PROTECTED + _PRIVATE, | 105 'PUB_ONLY' : _SPECIAL + _PROTECTED + _PRIVATE, |
| 106 'SPECIAL' : _SPECIAL, | 106 'SPECIAL' : _SPECIAL, |
| 107 'OTHER' : _PROTECTED + _PRIVATE, | 107 'OTHER' : _PROTECTED + _PRIVATE, |
| 108 } | 108 } |
| 109 VIS_MOD = {'special': _SPECIAL, 'protected': _PROTECTED, \ | 109 VIS_MOD = {'special': _SPECIAL, 'protected': _PROTECTED, |
| 110 'private': _PRIVATE, 'public': 0 } | 110 'private': _PRIVATE, 'public': 0} |
| 111 | 111 |
| 112 class FilterMixIn: | 112 class FilterMixIn(object): |
| 113 """filter nodes according to a mode and nodes' visibility | 113 """filter nodes according to a mode and nodes' visibility |
| 114 """ | 114 """ |
| 115 def __init__(self, mode): | 115 def __init__(self, mode): |
| 116 "init filter modes" | 116 "init filter modes" |
| 117 __mode = 0 | 117 __mode = 0 |
| 118 for nummod in mode.split('+'): | 118 for nummod in mode.split('+'): |
| 119 try: | 119 try: |
| 120 __mode += MODES[nummod] | 120 __mode += MODES[nummod] |
| 121 except KeyError, ex: | 121 except KeyError, ex: |
| 122 print >> sys.stderr, 'Unknown filter mode %s' % ex | 122 print >> sys.stderr, 'Unknown filter mode %s' % ex |
| 123 self.__mode = __mode | 123 self.__mode = __mode |
| 124 | 124 |
| 125 | 125 |
| 126 def show_attr(self, node): | 126 def show_attr(self, node): |
| 127 """return true if the node should be treated | 127 """return true if the node should be treated |
| 128 """ | 128 """ |
| 129 visibility = get_visibility(getattr(node, 'name', node)) | 129 visibility = get_visibility(getattr(node, 'name', node)) |
| 130 return not (self.__mode & VIS_MOD[visibility] ) | 130 return not (self.__mode & VIS_MOD[visibility]) |
| 131 | 131 |
| OLD | NEW |