Translate a (possibly incomplete) file or module name received from debugging client
        into an absolute file name.
492625
def normalize_path_in(self, client_file_name):
        
        _logger.p_debug("normalize_path_in(%s) with os.getcwd()=>%s", client_file_name, os.getcwd())
        
        # remove client CWD from file_path
        if client_file_name.startswith(self._CLIENT_CWD):
            file_name = client_file_name[len(self._CLIENT_CWD):]
        else:
            file_name = client_file_name
        
        # Try to find file using it's absolute path
        if os.path.isabs(file_name) and os.path.exists(file_name):
            _logger.p_debug("  => found absolute path: '%s'", file_name)
            return file_name
            
        # Can we find the file relatively to launch CWD (useful with buildout)
        f = os.path.join(self._CWD, file_name)  
        if  os.path.exists(f):
            _logger.p_debug("  => found path relative to self._CWD: '%s'", f)
            return f

        # Can we find file relatively to launch script
        f = os.path.join(sys.path[0], file_name)  
        if os.path.exists(f) and self.canonic(f) == self.mainpyfile:
            _logger.p_debug("  => found path relative to launch script: '%s'", f)
            return f
            
        # Try as an absolute path after adding .py extension 
        root, ext = os.path.splitext(file_name)
        if ext == '':
            f = file_name + '.py'
        if os.path.isabs(f):
            _logger.p_debug("  => found absolute path after adding .py extension: '%s'", f)
            return f
        
        # Can we find the file in system path
        for dir_name in sys.path:
            while os.path.islink(dir_name):
                dir_name = os.readlink(dir_name)
            f = os.path.join(dir_name, file_name)
            if os.path.exists(f):
                _logger.p_debug("  => found path in sys.path: '%s'", f)
                return f
        return None
436078
def build_filename(self, binary):
        """"""
        try:
            # Get exact timestamp of the build to build the local file name
            folder = self.builds[self.build_index]
            timestamp = re.search(r'([\d\-]+)-\D.*', folder).group(1)
        except Exception:
            # If it's not available use the build's date
            timestamp = self.date.strftime('%Y-%m-%d')

        return '%(TIMESTAMP)s-%(BRANCH)s-%(NAME)s' % {
            'TIMESTAMP': timestamp,
            'BRANCH': self.branch,
            'NAME': binary}
934402
def getFilename(name):
    """"""
    # first replace all illegal chars
    name = re.sub(r"[^0-9a-zA-Z_\-\.]", "_", name)
    # then remove double dots and underscores
    while ".." in name:
        name = name.replace('..', '.')
    while "__" in name:
        name = name.replace('__', '_')
    # remove a leading dot or minus
    if name.startswith((".", "-")):
        name = name[1:]
    return name
74412
def filename(value):
        '''
        
        '''
        return re.sub('[^a-zA-Z0-9.-_ ]', '', os.path.basename(InputSanitizer.trim(value)))
727649
def _module_name(filename):
        

        absfile = os.path.abspath(filename)
        match = filename

        for base in [''] + sys.path:
            base = os.path.abspath(base)
            if absfile.startswith(base):
                match = absfile[len(base):]
                break

        return SUFFIX_RE.sub('', match).lstrip('/').replace('/', '.')
1072116
def _filename(self_or_cls, filename):
        ""
        if not filename.endswith(self_or_cls.file_ext):
            return '%s.%s' % (filename, self_or_cls.file_ext)
        else:
            return filename
562162
def filename_from_headers(headers):
    
    if type(headers) == str:
        headers = headers.splitlines()
    if type(headers) == list:
        headers = dict([x.split(':', 1) for x in headers])
    cdisp = headers.get("Content-Disposition")
    if not cdisp:
        return None
    cdtype = cdisp.split(';')
    if len(cdtype) == 1:
        return None
    if cdtype[0].strip().lower() not in ('inline', 'attachment'):
        return None
    # several filename params is illegal, but just in case
    fnames = [x for x in cdtype[1:] if x.strip().startswith('filename=')]
    if len(fnames) > 1:
        return None
    name = fnames[0].split('=')[1].strip(' \t"')
    name = os.path.basename(name)
    if not name:
        return None
    return name
603472
private String setCurrentFilename(String relativePathOrPackage, String filename, String domain) throws Exception {
        currentFullFilename = convertToFullFilename(relativePathOrPackage, filename, domain);
        return "";
    }
1171699
def filename(self):
        
        if self.buildver:
            buildver = '-' + self.buildver
        else:
            buildver = ''
        pyver = '.'.join(self.pyver)
        abi = '.'.join(self.abi)
        arch = '.'.join(self.arch)
        # replace - with _ as a local version separator
        version = self.version.replace('-', '_')
        return '%s-%s%s-%s-%s-%s.whl' % (self.name, version, buildver,
                                         pyver, abi, arch)
192035
def generate_file_name(self):
        """"""
        if not self.project:
            raise UnderDefined("project name not given")

        out_data_dir = prms.Paths.outdatadir
        project_dir = os.path.join(out_data_dir, self.project)
        file_name = "cellpy_batch_%s.json" % self.name
        self.file_name = os.path.join(project_dir, file_name)
1052348
def fully_qualified_name(obj, sep='.'):
    """"""
    if inspect.isclass(obj):
        return obj.__module__ + sep + obj.__name__
    else:
        return obj.__module__ + sep + obj.__class__.__name__
1240918
def disambiguate_fname(self, fname):
        """"""
        files_path_list = [filename for filename in self.filenames
                           if filename]
        return sourcecode.disambiguate_fname(files_path_list, fname)
897729
def filename_to_str(self, filename):
        '''
        
        '''
        if filename.__class__ != str:
            if not IS_PY3K:
                filename = filename.encode(file_system_encoding)
            else:
                raise AssertionError('Expected to have str on Python 3. Found: %s (%s)' % (filename, filename.__class__))
        return filename
1127072
def get_title(src_name, src_type=None):
    """"""
    if src_type == 'tcp':
        return '{0}:{1}'.format(*src_name)
    return os.path.basename(src_name)
1338456
def import_file(filename, name=None):
    
    # Specifying a traditional dot-separated fully qualified name here
    # results in a number of "Parent module 'astropy' not found while
    # handling absolute import" warnings.  Using the same name, the
    # namespaces of the modules get merged together.  So, this
    # generates an underscore-separated name which is more likely to
    # be unique, and it doesn't really matter because the name isn't
    # used directly here anyway.
    mode = 'r'

    if name is None:
        basename = os.path.splitext(filename)[0]
        name = '_'.join(os.path.relpath(basename).split(os.sep)[1:])

    if not os.path.exists(filename):
        raise ImportError('Could not import file {0}'.format(filename))

    if import_machinery:
        loader = import_machinery.SourceFileLoader(name, filename)
        mod = loader.load_module()
    else:
        with open(filename, mode) as fd:
            mod = imp.load_module(name, fd, filename, ('.py', mode, 1))

    return mod
946395
def _get_module_name_from_fname(fname):
    """"""
    fname = fname.replace(".pyc", ".py")
    for mobj in sys.modules.values():
        if (
            hasattr(mobj, "__file__")
            and mobj.__file__
            and (mobj.__file__.replace(".pyc", ".py") == fname)
        ):
            module_name = mobj.__name__
            return module_name
    raise RuntimeError("Module could not be found")
1288268
def strip_vl_extension(filename):
    """"""
    for ext in ['.vl.json', '.json']:
        if filename.endswith(ext):
            return filename[:-len(ext)]
    else:
        return filename