Ejemplo n.º 1
0
    def get_source_of_current_name(self):
        """Return the unicode source code of the object which is bound to the
        current name in the current input line. Throw `SourceNotFound` if the
        source cannot be found."""

        obj = self.current_func
        try:
            if obj is None:
                line = self.current_line
                if not line.strip():
                    raise SourceNotFound(_("Nothing to get source of"))
                if inspection.is_eval_safe_name(line):
                    obj = self.get_object(line)
            return inspection.get_source_unicode(obj)
        except (AttributeError, NameError) as e:
            msg = _(u"Cannot get source: %s") % (e, )
        except IOError as e:
            msg = u"%s" % (e, )
        except TypeError as e:
            if "built-in" in u"%s" % (e, ):
                msg = _("Cannot access source of %r") % (obj, )
            else:
                msg = _("No source code found for %s") % (self.current_line, )
        raise SourceNotFound(msg)
Ejemplo n.º 2
0
    def get_source_of_current_name(self):
        """Return the unicode source code of the object which is bound to the
        current name in the current input line. Throw `SourceNotFound` if the
        source cannot be found."""

        obj = self.current_func
        try:
            if obj is None:
                line = self.current_line
                if not line.strip():
                    raise SourceNotFound(_("Nothing to get source of"))
                if inspection.is_eval_safe_name(line):
                    obj = self.get_object(line)
            return inspection.get_source_unicode(obj)
        except (AttributeError, NameError) as e:
            msg = _(u"Cannot get source: %s") % (e, )
        except IOError as e:
            msg = u"%s" % (e, )
        except TypeError as e:
            if "built-in" in u"%s" % (e, ):
                msg = _("Cannot access source of %r") % (obj, )
            else:
                msg = _("No source code found for %s") % (self.current_line, )
        raise SourceNotFound(msg)
Ejemplo n.º 3
0
 def test_get_source_ascii(self):
     self.assertEqual(inspection.get_source_unicode(encoding_ascii.foo),
                      foo_ascii_only)
Ejemplo n.º 4
0
 def test_get_source_latin1(self):
     self.assertEqual(inspection.get_source_unicode(encoding_latin1.foo),
                      foo_non_ascii)