Creates a Feff_tag dictionary from a PARAMETER or feff.inp file.

        Args:
            filename: Filename for either PARAMETER or feff.inp file

        Returns:
            Feff_tag object
179663
def from_file(filename="feff.inp"):
        
        with zopen(filename, "rt") as f:
            lines = list(clean_lines(f.readlines()))
        params = {}
        eels_params = []
        ieels = -1
        ieels_max = -1
        for i, line in enumerate(lines):
            m = re.match(r"([A-Z]+\d*\d*)\s*(.*)", line)
            if m:
                key = m.group(1).strip()
                val = m.group(2).strip()
                val = Tags.proc_val(key, val)
                if key not in ("ATOMS", "POTENTIALS", "END", "TITLE"):
                    if key in ["ELNES", "EXELFS"]:
                        ieels = i
                        ieels_max = ieels + 5
                    else:
                        params[key] = val
            if ieels >= 0:
                if i >= ieels and i <= ieels_max:
                    if i == ieels + 1:
                        if int(line.split()[1]) == 1:
                            ieels_max -= 1
                    eels_params.append(line)

        if eels_params:
            if len(eels_params) == 6:
                eels_keys = ['BEAM_ENERGY', 'BEAM_DIRECTION', 'ANGLES', 'MESH', 'POSITION']
            else:
                eels_keys = ['BEAM_ENERGY', 'ANGLES', 'MESH', 'POSITION']
            eels_dict = {"ENERGY": Tags._stringify_val(eels_params[0].split()[1:])}
            for k, v in zip(eels_keys, eels_params[1:]):
                eels_dict[k] = str(v)
            params[str(eels_params[0].split()[0])] = eels_dict

        return Tags(params)
894970
def _load_config(self, filename):
        
        # Read entire file for metadata
        fh = open(filename, 'r')
        self.file_contents = fh.read()

        # Replace !include directives with content
        config_dir = os.path.split(filename)[0]
        include_re = re.compile('^(.*)!include\s+(.*)$', re.MULTILINE)

        def recursive_load(matchobj, path):
            first_spacing = matchobj.group(1)
            other_spacing = first_spacing.replace('-', ' ')
            fname = os.path.join(path, matchobj.group(2))
            new_path, _ = os.path.split(fname)
            new_path = os.path.realpath(new_path)
            text = ''
            with open(fname) as f:
                text = f.read()
            text = first_spacing + text
            text = text.replace('\n', '\n{}'.format(other_spacing), text.count('\n') - 1)
            return re.sub(include_re, lambda m : recursive_load(m, new_path), text)

#        def include_repl(matchobj):
#            first_spacing = matchobj.group(1)
#            other_spacing = first_spacing.replace('-', ' ')
#            fname = os.path.join(config_dir, matchobj.group(2))
#            text = ''
#            with open(fname) as f:
#                text = f.read()
#            text = first_spacing + text
#            text = text.replace('\n', '\n{}'.format(other_spacing), text.count('\n') - 1)
#            return text

        self.file_contents = re.sub(include_re, lambda m : recursive_load(m, config_dir), self.file_contents)
        # Read in dictionary
        self.config = self.__ordered_load(self.file_contents)

        # Convert functions of other params to true expressions
        for k in self.config.keys():
            self.config[k] = YamlConfig.__convert_key(self.config[k])

        fh.close()

        # Load core configuration
        return self.config
1171935
def from_filename(cls, filename):
        
        if not filename:
            logger.error('No filename specified')
            return None

        if not os.path.exists(filename):
            logger.error("Err: File '%s' does not exist", filename)
            return None

        if os.path.isdir(filename):
            logger.error("Err: File '%s' is a directory", filename)
            return None

        try:
            audiofile = eyed3.load(filename)
        except Exception as error:
            print(type(error), error)
            return None

        # Sometimes eyed3 may return a null object and not raise any exceptions
        if audiofile is None:
            return None

        tags = audiofile.tag
        album = tags.album
        title = tags.title
        lyrics = ''.join([l.text for l in tags.lyrics])
        artist = tags.album_artist
        if not artist:
            artist = tags.artist

        song = cls(artist, title, album, lyrics)
        song.filename = filename
        return song
686581
def generate_tags_multiple_files(input_files, tag, ignore_tags, ns=None):
    
    return itertools.chain.from_iterable([generate_xmltags(
        fn, tag, ignore_tags, ns) for fn in input_files])
1005009
def restricted_to_files(self,
                            filenames: List[str]
                            ) -> 'Spectra':
        
        tally_passing = \
            {fn: entries for (fn, entries) in self.__tally_passing.items() \
             if fn in filenames}
        tally_failing = \
            {fn: entries for (fn, entries) in self.__tally_failing.items() \
             if fn in filenames}
        return Spectra(self.__num_passing,
                       self.__num_failing,
                       tally_passing,
                       tally_failing)
1240270
def save_parameters(self, filename):
        
        params = self._collect_params_with_prefix()
        if self.pret_word_embs:  # don't save word embeddings inside model
            params.pop('pret_word_embs.weight', None)
        arg_dict = {key: val._reduce() for key, val in params.items()}
        ndarray.save(filename, arg_dict)
1159189
def from_file(filename, encoding='utf-8')
      mode = "rb:#{encoding}"
      mode = "rb" if RUBY_VERSION < '1.9'
      input = File.open(filename, mode) {|f| f.read() }
      compile(parse(input), filename, 1)
      return self
    end
1358342
def extension_from_filename(filename):
    
    # Parse out any extension specified in filename
    _indx1 = filename.find('[')
    _indx2 = filename.find(']')
    if _indx1 > 0:
        # check for closing square bracket:
        if _indx2 < _indx1:
            raise RuntimeError("Incorrect extension specification in file " \
                                "name \'%s\'." % filename)
        # Read extension name provided
        _fname = filename[:_indx1]
        _extn = filename[_indx1+1:_indx2].strip()
    else:
        _fname = filename
        _extn = None

    return _fname, _extn
58459
def _read_file(fname):
    
    with open(fname) as input_file:
        re_grammar = [x.strip('\n') for x in input_file.readlines()]
    return re_grammar
911638
def parse_filename(filename):
    

    _patterns = patterns.get_expressions()
    result = {}

    for cmatcher in _patterns:
        match = cmatcher.match(filename)
        if match:
            namedgroups = match.groupdict().keys()

            result['pattern'] = cmatcher.pattern
            result['series_name'] = match.group('seriesname')
            result['season_number'] = _get_season_no(match, namedgroups)
            result['episode_numbers'] = _get_episodes(match, namedgroups)
            break
    else:
        result = None

    return result
1095387
def createRtiFromFileName(fileName):
    
    cls, rtiRegItem = detectRtiFromFileName(fileName)
    if cls is None:
        logger.warn("Unable to import plugin {}: {}"
                    .format(rtiRegItem.fullName, rtiRegItem.exception))
        rti = UnknownFileRti.createFromFileName(fileName)
        rti.setException(rtiRegItem.exception)
    else:
        rti = cls.createFromFileName(fileName)

    assert rti, "Sanity check failed (createRtiFromFileName). Please report this bug."
    return rti
158944
def split_filename(name):
    
    parts = hashed_filename_re.match(name).groupdict()
    return (parts['name'] or '', parts['hash'] or '', parts['ext'] or '')
701617
def dict_conf(filename):
  

  f, ext = os.path.splitext(filename)
  ext = ext.lower()

  if ext == "conf" or ext == "ini":
    # python config via config parser

    config = ConfigParser()
    config.optionxform=str
    config.read(filename)
    rv = {}
    for section in config.sections():
      rv[section] = {}
      for key,value in config.items(section):
        rv[section][key] = value.strip('"').strip("'").decode("string_escape")
    return rv
  else:
    # other type of config, use munge
    if munge_config:
      src = munge_config.parse_url(filename)
      return src.cls().load(open(filename)).get("vodka")
    else:
      raise Exception("'%s' type of config encountered, install munge" % ext)
1001322
def parse_file_to_dict(self, fname):
        
        print('TODO - parse_file_to_dict' + fname)
        for m in self.maps:
            if m.tpe == 'file':
                if m.key[0:3] == 'col':
                    print('reading column..')
463783
def fromConfigFile(filename = DEFAULT_CONFIG_FILE):
    
    parser = SafeConfigParser()
    section = 'fenixedu'
    parser.read(filename)

    client_id = parser.get(section, 'client_id')
    redirect_uri = parser.get(section, 'redirect_uri')
    client_secret = parser.get(section, 'client_secret')

    base_url = parser.get(section, 'base_url')
    api_endpoint = parser.get(section, 'api_endpoint')
    api_version = parser.get(section, 'api_version')

    return FenixEduConfiguration(client_id = client_id,
                                  redirect_uri = redirect_uri,
                                  client_secret = client_secret,
                                  base_url = base_url,
                                  api_endpoint = api_endpoint,
                                  api_version = api_version)
208230
def from_filename(cls, filename, sync_from_start=True):
        
        # Inline imports: the Pygments dependency is optional!
        from pygments.util import ClassNotFound
        from pygments.lexers import get_lexer_for_filename

        try:
            pygments_lexer = get_lexer_for_filename(filename)
        except ClassNotFound:
            return SimpleLexer()
        else:
            return cls(pygments_lexer.__class__, sync_from_start=sync_from_start)
110506
def safe_filename(file_name, sep='_', default=None, extension=None):
    """"""
    if file_name is None:
        return decode_path(default)

    file_name = decode_path(file_name)
    file_name = os.path.basename(file_name)
    file_name, _extension = os.path.splitext(file_name)
    file_name = _safe_name(file_name, sep=sep)
    if file_name is None:
        return decode_path(default)
    file_name = file_name[:MAX_LENGTH]
    extension = _safe_name(extension or _extension, sep=sep)
    if extension is not None:
        file_name = '.'.join((file_name, extension))
        file_name = file_name[:MAX_LENGTH]
    return file_name