/usr/lib/python2.7/dist-packages/astroid/util.py is in python-astroid 1.4.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of astroid.
#
# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with astroid. If not, see <http://www.gnu.org/licenses/>.
#
# The code in this file was originally part of logilab-common, licensed under
# the same license.
import warnings
from astroid import exceptions
def generate_warning(message, warning):
return lambda *args: warnings.warn(message % args, warning, stacklevel=3)
rename_warning = generate_warning(
"%r is deprecated and will be removed in astroid %.1f, use %r instead",
PendingDeprecationWarning)
attribute_to_method_warning = generate_warning(
"%s is deprecated and will be removed in astroid %.1f, use the "
"method '%s()' instead.", PendingDeprecationWarning)
attribute_to_function_warning = generate_warning(
"%s is deprecated and will be removed in astroid %.1f, use the "
"function '%s()' instead.", PendingDeprecationWarning)
method_to_function_warning = generate_warning(
"%s() is deprecated and will be removed in astroid %.1f, use the "
"function '%s()' instead.", PendingDeprecationWarning)
class _Yes(object):
"""Special inference object, which is returned when inference fails."""
def __repr__(self):
return 'YES'
__str__ = __repr__
def __getattribute__(self, name):
if name == 'next':
raise AttributeError('next method should not be called')
if name.startswith('__') and name.endswith('__'):
return super(_Yes, self).__getattribute__(name)
if name == 'accept':
return super(_Yes, self).__getattribute__(name)
return self
def __call__(self, *args, **kwargs):
return self
def accept(self, visitor):
func = getattr(visitor, "visit_yes")
return func(self)
YES = _Yes()
def safe_infer(node, context=None):
"""Return the inferred value for the given node.
Return None if inference failed or if there is some ambiguity (more than
one node has been inferred).
"""
try:
inferit = node.infer(context=context)
value = next(inferit)
except exceptions.InferenceError:
return
try:
next(inferit)
return # None if there is ambiguity on the inferred node
except exceptions.InferenceError:
return # there is some kind of ambiguity
except StopIteration:
return value
|