Take an open file containing the IANA subtag registry, and yield a
    dictionary of information for each subtag it describes.
427725
def parse_file(file):
    
    lines = []
    for line in file:
        line = line.rstrip('\n')
        if line == '%%':
            # This is a separator between items. Parse the data we've
            # collected and yield the result.
            yield from parse_item(lines)
            lines.clear()
        elif line.startswith('  '):
            # This is a continuation line. Concatenate it to the previous
            # line, including one of the spaces.
            lines[-1] += line[1:]
        else:
            lines.append(line)
    yield from parse_item(lines)
279937
def gather_registries() -> Tuple[Dict, Mapping, Mapping]:
    
    id2devices = copy.copy(_id2devices)
    registry = copy.copy(_registry)
    selection = copy.copy(_selection)
    dict_ = globals()
    dict_['_id2devices'] = {}
    dict_['_registry'] = {Node: {}, Element: {}}
    dict_['_selection'] = {Node: {}, Element: {}}
    return id2devices, registry, selection
1079464
def _process_tags(self):
        """"""
        tags = []

        while True:
            tag_bf = unpack_ui16(self._src)
            tag_type = tag_bf >> 6   # upper 10 bits
            if tag_type == 0:
                # the end
                break
            tag_len = tag_bf & 0x3f  # last 6 bits
            if tag_len == 0x3f:
                # the length is the next four bytes!
                tag_len = unpack_ui32(self._src)

            try:
                tag_name = TAG_NAMES[tag_type]
            except KeyError:
                # malformed SWF, create and unknown object with malformed tag
                tag_payload = self._src.read(tag_len)
                _dict = {
                    '__str__': _repr,
                    '__repr__': _repr,
                    'name': 'UnspecifiedObject(tag={!r})'.format(tag_type),
                }
                tag = type("UnknownObject", (SWFObject,), _dict)()
                tag.raw_payload = tag_payload
                tags.append(tag)
                continue

            try:
                tag_meth = getattr(self, "_handle_tag_" + tag_name.lower())
            except AttributeError:
                if self.unknown_alert:
                    raise ValueError("Unknown tag: " + repr(tag_name))

                tag_payload = self._src.read(tag_len)
                _dict = {'__str__': _repr, '__repr__': _repr, 'name': tag_name}
                tag = type("UnknownObject", (SWFObject,), _dict)()
                tag.raw_payload = tag_payload
                tags.append(tag)
                continue

            # we know the tag type, and have the handler, let's process it
            prev_pos = self._src.tell()
            self._src.guard = tag_len
            try:
                with ReadQuantityController(self._src, tag_len):
                    tag = tag_meth()
                assert tag is not None, tag_name
            except ValueError:
                # an attempt to read too much happened; create a failing
                # object with the raw payload
                self._src.guard = None
                self._src.seek(prev_pos)
                tag_payload = self._src.read(tag_len)
                _dict = {'__str__': _repr, '__repr__': _repr, 'name': tag_name}
                tag = type("FailingObject", (SWFObject,), _dict)()
                tag.raw_payload = tag_payload
            tags.append(tag)
        return tags
543857
def read_targets(targets):
    """"""
    results = {}
    for target, regexer in regexer_for_targets(targets):
        with open(target) as fh:
            results.update(extract_keypairs(fh.readlines(), regexer))
    return results
896598
def get_files_information(self):
        
        if self.files == {}:
            self.get_files_types()

        for i in self.get_files():
            try:
                yield i, self.files[i], self.files_crc32[i]
            except KeyError:
                yield i, "", ""
263689
def _openResources(self):
        
        with Image.open(self._fileName) as image:
            self._array = np.asarray(image)
            self._bands = image.getbands()

            # Fill attributes. For now assume that the info item are not overridden by
            # the Image items.
            self._attributes = dict(image.info)
            self._attributes['Format'] = image.format
            self._attributes['Mode'] = image.mode
            self._attributes['Size'] = image.size
            self._attributes['Width'] = image.width
            self._attributes['Height'] = image.height
267752
def GetSubkeys(self):
    
    if not self._registry_key and self._registry:
      self._GetKeyFromRegistry()

    return iter(self._subkeys.values())
570701
def parse(args):
    """"""

    import argparse

    parser = argparse.ArgumentParser(
        add_help=False,
        description="Remove spam and advertising from subtitle files.",
        usage="%(prog)s [OPTION]... TARGET...")
    parser.add_argument(
        "-a", "--aeidon",
        action="store_true",
        dest="aeidon",
        help="use python3-aeidon to process subtitles")
    parser.add_argument(
        "-f", "--file",
        action="append",
        dest="pattern_files",
        help="obtain matches from FILE")
    parser.add_argument(
        "--fix",
        action="store_true",
        dest="fix",
        help="repair potentially damaged subtitle files with aeidon")
    parser.add_argument(
        "-g", "--gui",
        action="store_true",
        dest="gui",
        help="indicate use from a GUI")
    parser.add_argument(
        "-h", "--help",
        action="help",
        help=argparse.SUPPRESS)
    parser.add_argument(
        "-r", "--regex",
        action="store_true",
        dest="regex",
        help="perform regex matching")
    parser.add_argument(
        "-s", "--case-sensitive",
        action="store_true",
        default=False,
        dest="case_sensitive",
        help="match case-sensitively")
    parser.add_argument(
        "-y", "--yes",
        action="store_true",
        dest="autoyes",
        help="automatic yes to prompts")
    parser.add_argument(
        "--version",
        action="version",
        version='%(prog)s ' + __version__)
    parser.add_argument(
        dest="targets",
        help=argparse.SUPPRESS,
        nargs="*")

    options = parser.parse_args(args)
    arguments = options.targets

    return options, arguments
98606
def read_dictionary_file(dictionary_path):
    """"""
    try:
        return _user_dictionary_cache[dictionary_path]
    except KeyError:
        if dictionary_path and os.path.exists(dictionary_path):
            with open(dictionary_path, "rt") as dict_f:
                words = set(re.findall(r"(\w[\w']*\w|\w)",
                                       " ".join(dict_f.read().splitlines())))
                return words

        return set()
897241
def mdgel_metadata(self):
        """"""
        for page in self.pages[:2]:
            if 'MDFileTag' in page.tags:
                tags = page.tags
                break
        else:
            return None
        result = {}
        for code in range(33445, 33453):
            name = TIFF.TAGS[code]
            if name not in tags:
                continue
            result[name[2:]] = tags[name].value
        return result
1373271
def filename_items_for_filetype(filenames, filetype_info):
        """"""
        matched_files = []
        for pattern in filetype_info['file_patterns']:
            for filename in match_filenames(filenames, pattern):
                if filename in matched_files:
                    continue
                try:
                    filename_info = parse(
                        pattern, get_filebase(filename, pattern))
                except ValueError:
                    logger.debug("Can't parse %s with %s.", filename, pattern)
                    continue
                matched_files.append(filename)
                yield filename, filename_info
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)
1168581
def get_info(self, apply_tag=None, info_dicts=False):
        
        raw_infos = self.fetcher.fetch(*self.info_files)
        raw_info = parse.merge_infos(*raw_infos, info_dicts=info_dicts)
        info = parse.parse_info(raw_info, apply_tag=apply_tag)
        return info
87916
def Parse(self, stat, file_object, knowledge_base):
    """"""
    _, _ = stat, knowledge_base
    # TODO(user): Convert this to use the far more intelligent plaso parser.
    ie = IEParser(file_object)
    for dat in ie.Parse():
      yield rdf_webhistory.BrowserHistoryItem(
          url=dat["url"],
          domain=urlparse.urlparse(dat["url"]).netloc,
          access_time=dat.get("mtime"),
          program_name="Internet Explorer",
          source_urn=file_object.urn)
717745
def extract_asset_tags(dstore, tagname):
    
    tagcol = dstore['assetcol/tagcol']
    if tagname:
        yield tagname, barray(tagcol.gen_tags(tagname))
    for tagname in tagcol.tagnames:
        yield tagname, barray(tagcol.gen_tags(tagname))
394141
def _items(self):
        """"""
        for name in self.declarations:
            yield name, self.declarations[name]
            for subkey, value in self.contexts[name].items():
                yield self.join(name, subkey), value
626844
def pull_tag_dict(data):
    
    # If there are tags, set them to a normal dict, vs. a list of dicts:
    tags = data.pop('Tags', {}) or {}
    if tags:
        proper_tags = {}
        for tag in tags:
            proper_tags[tag['Key']] = tag['Value']

        tags = proper_tags

    return tags