Return the Python source file an object was defined in, if it exists.
187216
def getsourcefile(object):
    """"""
    filename = getfile(object)
    if string.lower(filename[-4:]) in ['.pyc', '.pyo']:
        filename = filename[:-4] + '.py'
    for suffix, mode, kind in imp.get_suffixes():
        if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix:
            # Looks like a binary file.  We want to only return a text file.
            return None
    if os.path.exists(filename):
        return filename
682994
def source(self):
        """"""
        if hasattr(self, 'srpm'):
            rpm = self.from_package(self.srpm)
            # Source RPMs don't have epoch for some reason
            rpm.epoch = self.epoch
            return rpm
754398
def get_python_files(files):
        """"""
        python_files = []
        for file_name in files:
            if file_name.endswith(".py"):
                python_files.append(file_name)

        return python_files
467284
def get_root_path(obj):
    
    try:
        filename = os.path.abspath(obj.__globals__['__file__'])
    except (KeyError, AttributeError):
        if getattr(obj, '__wrapped__', None):
            # decorator package has been used in view
            return get_root_path(obj.__wrapped__)
        filename = inspect.getfile(obj)
    return os.path.dirname(filename)
902889
def get_source_file_provenance(self, filename):
        """"""
        module_name = resolve.infer_module_name(filename, self.path)
        return resolve.Direct(filename, module_name)
1167533
def openSource(p, filetype=None):
    ''
    if not filetype:
        filetype = options.filetype
    if isinstance(p, str):
        if '://' in p:
            return openSource(UrlPath(p), filetype)  # convert to Path and recurse
        elif p == '-':
            return openSource(PathFd('-', vd().stdin), filetype)
        else:
            return openSource(Path(p), filetype)  # convert to Path and recurse
    elif isinstance(p, UrlPath):
        openfunc = 'openurl_' + p.scheme
        return getGlobals()[openfunc](p, filetype=filetype)
    elif isinstance(p, Path):
        if not filetype:
            filetype = p.suffix or 'txt'

        if os.path.isdir(p.resolve()):
            filetype = 'dir'

        openfunc = 'open_' + filetype.lower()
        if openfunc not in getGlobals():
            warning('no %s function' % openfunc)
            filetype = 'txt'
            openfunc = 'open_txt'
        vs = getGlobals()[openfunc](p)
    else:  # some other object
        status('unknown object type %s' % type(p))
        vs = None

    if vs:
        status('opening %s as %s' % (p.name, filetype))

    return vs
228168
def class_path(cls):
    """"""
    if cls.__module__ == '__main__':
        path = None
    else:
        path = os.path.dirname(inspect.getfile(cls))

    if not path:
        path = os.getcwd()

    return os.path.realpath(path)
1148040
@DefinedBy(Api.COMPILER)
    public JavaFileObject getSource() {
        if (source == null)
            return null;
        else
            return source.getFile();
    }
245394
public String getSourceFile() {
        if ( sourceFile == null )
            if ( parent != null )
                return ((SimpleNode)parent).getSourceFile();
            else
                return "<unknown file>";
        else
            return sourceFile;
    }
1001047
def source_file_name(self):
        
        try:
            fname = inspect.getsourcefile(self.code_obj)
        except TypeError:
            # In some cases the object is something complex like a cython
            # object that can't be easily introspected. An it's better to
            # return the source code file of the object as None, than crash
            pass
        else:
            if fname:
                fname = os.path.relpath(fname, BASE_PATH)
                return fname
142115
def getabsfile(object):
    """"""
    return os.path.normcase(
        os.path.abspath(getsourcefile(object) or getfile(object)))
1568
def get_source_class(self, _class):
        
        if not _class.get_name() in self.classes:
            return ""
        return self.classes[_class.get_name()]
189113
def inspect_io_obj(obj):
    
    itype = guess_io_type(obj)

    if itype == IOI_PATH_STR:
        ipath = anyconfig.utils.normpath(obj)
        ext = anyconfig.utils.get_file_extension(ipath)
        opener = open
    elif itype == IOI_PATH_OBJ:
        ipath = anyconfig.utils.normpath(obj.as_posix())
        ext = anyconfig.utils.get_file_extension(ipath)
        opener = obj.open
    elif itype == IOI_STREAM:
        ipath = anyconfig.utils.get_path_from_stream(obj)
        ext = anyconfig.utils.get_file_extension(ipath) if ipath else None
        opener = anyconfig.utils.noop
    elif itype == IOI_NONE:
        ipath = ext = None
        opener = anyconfig.utils.noop
    else:
        raise UnknownFileTypeError("%r" % obj)

    return (itype, ipath, opener, ext)
237784
def get_python_files(self):
        """"""
        return [resource for resource in self.get_files()
                if self.pycore.is_python_file(resource)]
930537
def load_source(self):
    """"""
    if self.filename in self.STDIN_NAMES:
      self.filename = 'stdin'
      self.source = pycodestyle.stdin_get_value()
    else:
      with pep257.tokenize_open(self.filename) as fd:
        self.source = fd.read()
162038
def _load_source_object(self):
		
		if hasattr(self, "source_obj"):
			self.source_text = getattr(self.source_obj, self.field)
			return self.source_obj

		self._load_source_model()
		self.source_obj = self.source_model.objects.get(id=self.object_id)
		return self.source_obj
1281953
def _get_src_file(self, val, default='Unknown'):
        '''
        
        '''
        path = default

        try:
            # http://stackoverflow.com/questions/6761337/inspect-getfile-vs-inspect-getsourcefile
            # first try and get the actual source file
            source_file = inspect.getsourcefile(val)
            if not source_file:
                # get the raw file since val doesn't have a source file (could be a .pyc or .so file)
                source_file = inspect.getfile(val)

            if source_file:
                path = os.path.realpath(source_file)

        except TypeError as e:
            path = default

        return path