Extracts weather groups (FM, PROB etc.) and populates group list

        Args:
            TAF report string

        Raises:
            MalformedTAF: Group decoding error
163881
def _init_groups(self, string):
        

        taf_group_pattern = """
            (?:FM|(?:PROB(?:\d{1,2})\s*(?:TEMPO)?)|TEMPO|BECMG|[\S\s])[A-Z0-9\+\-/\s$]+?(?=FM|PROB|TEMPO|BECMG|$)
        """

        group_list = []

        groups = re.findall(taf_group_pattern, string, re.VERBOSE)
        if not groups:
            raise MalformedTAF("No valid groups found")

        for group in groups:
            group_list.append(group)

        return(group_list)
461808
def _normalize_mirror_settings(self):
        

        def malformed_mirror_groups_except():
            return ImproperlyConfigured(
                "{} must be a collection of group names".format(
                    self.settings._name("MIRROR_GROUPS_EXCEPT")
                )
            )

        def malformed_mirror_groups():
            return ImproperlyConfigured(
                "{} must be True or a collection of group names".format(
                    self.settings._name("MIRROR_GROUPS")
                )
            )

        mge = self.settings.MIRROR_GROUPS_EXCEPT
        mg = self.settings.MIRROR_GROUPS

        if mge is not None:
            if isinstance(mge, (set, frozenset)):
                pass
            elif isinstance(mge, (list, tuple)):
                mge = self.settings.MIRROR_GROUPS_EXCEPT = frozenset(mge)
            else:
                raise malformed_mirror_groups_except()

            if not all(isinstance(value, str) for value in mge):
                raise malformed_mirror_groups_except()
            elif mg:
                warnings.warn(
                    ConfigurationWarning(
                        "Ignoring {} in favor of {}".format(
                            self.settings._name("MIRROR_GROUPS"),
                            self.settings._name("MIRROR_GROUPS_EXCEPT"),
                        )
                    )
                )
                mg = self.settings.MIRROR_GROUPS = None

        if mg is not None:
            if isinstance(mg, (bool, set, frozenset)):
                pass
            elif isinstance(mg, (list, tuple)):
                mg = self.settings.MIRROR_GROUPS = frozenset(mg)
            else:
                raise malformed_mirror_groups()

            if isinstance(mg, (set, frozenset)) and (
                not all(isinstance(value, str) for value in mg)
            ):
                raise malformed_mirror_groups()
915996
def parse(self, conditions):
        
        conditions_text = conditions
        try:
            conditions = shlex.split(fmt.to_utf8(conditions))
        except AttributeError:
            # Not a string, assume parsed tree
            conditions_text = self._tree2str(conditions)

        # Empty list?
        if not conditions:
            raise FilterError("No conditions given at all!")

        # NOT *must* appear at the start of a group
        negate = conditions[:1] == ["NOT"]
        if negate:
            conditions = conditions[1:]
            if not conditions:
                raise FilterError("NOT must be followed by some conditions!")

        # Handle grouping
        if '[' in conditions:
            tree = [[]]
            for term in conditions:
                if term == '[':
                    tree.append([]) # new grouping
                elif term == ']':
                    subtree = tree.pop()
                    if not tree:
                        raise FilterError("Unbalanced brackets, too many closing ']' in condition %r" % (conditions_text,))
                    tree[-1].append(subtree) # append finished group to containing level
                else:
                    tree[-1].append(term) # append to current level

            if len(tree) > 1:
                raise FilterError("Unbalanced brackets, too many open '[' in condition %r" % (conditions_text,))
            conditions = tree[0]

        # Prepare root matcher
        conditions = list(conditions)
        matcher = CompoundFilterAll()
        if "OR" in conditions:
            root = CompoundFilterAny()
            root.append(matcher)
        else:
            root = matcher

        # Go through conditions and parse them
        for condition in conditions:
            if condition == "OR":
                # Leading OR, or OR OR in sequence?
                if not matcher:
                    raise FilterError("Left-hand side of OR missing in %r!" % (conditions_text,))

                # Start next run of AND conditions
                matcher = CompoundFilterAll()
                root.append(matcher)
            elif isinstance(condition, list):
                matcher.append(self.parse(condition))
            else:
                matcher.append(self._create_filter(condition))

        # Trailing OR?
        if not matcher:
            raise FilterError("Right-hand side of OR missing in %r!" % (conditions_text,))

        return NegateFilter(root) if negate else root
979826
def get_formatter_report(f: logging.Formatter) -> Optional[Dict[str, str]]:
    
    if f is None:
        return None
    return {
        '_fmt': f._fmt,
        'datefmt': f.datefmt,
        '_style': str(f._style),
    }
96801
def frommaf(args):
    
    p = OptionParser(frommaf.__doc__)
    p.add_option("--validate",
                 help="Validate coordinates against FASTA [default: %default]")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    maf, = args
    snpfile = maf.rsplit(".", 1)[0] + ".vcf"
    fp = open(maf)
    fw = open(snpfile, "w")
    total = 0
    id = "."
    qual = 20
    filter = "PASS"
    info = "DP=20"
    print("##fileformat=VCFv4.0", file=fw)
    print("#CHROM POS ID REF ALT QUAL FILTER INFO".replace(" ", "\t"), file=fw)
    for row in fp:
        atoms = row.split()
        c, pos, ref, alt = atoms[:4]
        try:
            c = int(c)
        except:
            continue
        c = "chr{0:02d}".format(c)
        pos = int(pos)
        print("\t".join(str(x) for x in \
                (c, pos, id, ref, alt, qual, filter, info)), file=fw)
        total += 1
    fw.close()

    validate = opts.validate
    if not validate:
        return

    from jcvi.utils.cbook import percentage

    f = Fasta(validate)
    fp = open(snpfile)
    nsnps = 0
    for row in fp:
        if row[0] == '#':
            continue

        c, pos, id, ref, alt, qual, filter, info = row.split("\t")
        pos = int(pos)
        feat = dict(chr=c, start=pos, stop=pos)
        s = f.sequence(feat)
        s = str(s)
        assert s == ref, "Validation error: {0} is {1} (expect: {2})".\
                        format(feat, s, ref)
        nsnps += 1
        if nsnps % 50000 == 0:
            logging.debug("SNPs parsed: {0}".format(percentage(nsnps, total)))
    logging.debug("A total of {0} SNPs validated and written to `{1}`.".\
                        format(nsnps, snpfile))
956964
def get_flat_groups(self, field=None):
        '''
        
        '''
        field = field if field else self._determine_group_field(field)
        temp_groups = self.data['grouped'][field]['groups']
        return [y for x in temp_groups for y in x['doclist']['docs']]
603315
def groups_filter_from_query(query, field_map={}):
    """"""
    f = None
    # filter groups
    for group in query.get("groups", []):
        group_f = MatchAll()
        for condition in group.get("conditions", []):
            field_name = condition["field"]
            field_name = field_map.get(field_name, field_name)
            operation = condition["type"]
            values = condition["values"]
            if values:
                values = [v["value"] for v in values]
                if operation == "all":
                    # NOTE: is there a better way to express this?
                    for value in values:
                        if "." in field_name:
                            path = field_name.split(".")[0]
                            group_f &= Nested(path=path, filter=Term(**{field_name: value}))
                        else:
                            group_f &= Term(**{field_name: value})
                elif operation == "any":
                    if "." in field_name:
                        path = field_name.split(".")[0]
                        group_f &= Nested(path=path, filter=Terms(**{field_name: values}))
                    else:
                        group_f &= Terms(**{field_name: values})
                elif operation == "none":
                    if "." in field_name:
                        path = field_name.split(".")[0]
                        group_f &= ~Nested(path=path, filter=Terms(**{field_name: values}))
                    else:
                        group_f &= ~Terms(**{field_name: values})

        date_range = group.get("time")
        if date_range:
            group_f &= date_range_filter(date_range)
        if f:
            f |= group_f
        else:
            f = group_f
    return f
58041
def __parse_fc_data(fc_data):
    """"""
    fc = []
    for day in fc_data:
        fcdata = {
            CONDITION: __cond_from_desc(
                __get_str(
                    day,
                    __WEATHERDESCRIPTION)
            ),
            TEMPERATURE: __get_float(day, __MAXTEMPERATURE),
            MIN_TEMP: __get_float(day, __MINTEMPERATURE),
            MAX_TEMP: __get_float(day, __MAXTEMPERATURE),
            SUN_CHANCE: __get_int(day, __SUNCHANCE),
            RAIN_CHANCE: __get_int(day, __RAINCHANCE),
            RAIN: __get_float(day, __MMRAINMAX),
            MIN_RAIN: __get_float(day, __MMRAINMIN),  # new
            MAX_RAIN: __get_float(day, __MMRAINMAX),  # new
            SNOW: 0,  # for compatibility
            WINDFORCE: __get_int(day, __WIND),
            WINDDIRECTION: __get_str(day, __WINDDIRECTION),      # new
            DATETIME: __to_localdatetime(__get_str(day, __DAY)),
        }
        fcdata[CONDITION][IMAGE] = day[__ICONURL]

        fc.append(fcdata)
    return fc
574147
def parse_groups(self, group, params):
        
        # When resuming upon throttling error, skip if already fetched
        if group['GroupName'] in self.groups:
            return
        api_client = params['api_client']
        # Ensure consistent attribute names across resource types
        group['id'] = group.pop('GroupId')
        group['name'] = group.pop('GroupName')
        group['arn'] = group.pop('Arn')
        # Get group's members
        group['users'] = self.__fetch_group_users(api_client, group['name']);
        # Get inline policies
        policies = self.__get_inline_policies(api_client, 'group', group['id'], group['name'])
        if len(policies):
            group['inline_policies'] = policies
        group['inline_policies_count'] = len(policies)
        self.groups[group['id']] = group
823659
def xinfo_groups(self, stream):
        """"""
        fut = self.execute(b'XINFO', b'GROUPS', stream)
        return wait_convert(fut, parse_lists_to_dicts)
1339670
def group_values(self, group_name):
        """"""
        group_index = self.groups.index(group_name)
        values = []
        for key in self.data_keys:
            if key[group_index] not in values:
                values.append(key[group_index])
        return values
625566
def parse_arg_line(fargs):
    

    # Convert to literal dict
    fargs = fargs.strip()
    if fargs == '':
        return {}

    pairs = [s.strip() for s in fargs.split(',')]
    # find first "="
    result = []
    for p in pairs:
        fe = p.find("=")
        if fe == -1:
            # no equal
            raise ValueError("malformed")
        key = p[:fe]
        val = p[fe + 1:]
        tok = "'{}': {}".format(key, val)
        result.append(tok)
    tokj = ','.join(result)
    result = "{{ {0} }}".format(tokj)
    state = ast.literal_eval(result)
    return state
1327894
def pars_in_groups(self):
        
        pargp = self.par_groups
        allpars = dict()
        for cpg in pargp:
            allpars[cpg] = [i for i in self.parameter_data.loc[self.parameter_data.pargp == cpg, 'parnme']]
        return allpars
430598
def get_taf_alt_ice_turb(wxdata: [str]) -> ([str], str, [str], [str]):  # type: ignore
    
    altimeter = ''
    icing, turbulence = [], []
    for i, item in reversed(list(enumerate(wxdata))):
        if len(item) > 6 and item.startswith('QNH') and item[3:7].isdigit():
            altimeter = wxdata.pop(i)[3:7]
        elif item.isdigit():
            if item[0] == '6':
                icing.append(wxdata.pop(i))
            elif item[0] == '5':
                turbulence.append(wxdata.pop(i))
    return wxdata, altimeter, icing, turbulence
872671
def group_by(self, fields, items=None):
        
        result = defaultdict(list)
        if items is None:
            items = self.items()

        try:
            key = operator.attrgetter(fields + '')
        except TypeError:
            def key(obj, names=tuple(fields)):
                'Helper to return group key tuple'
                return tuple(getattr(obj, x) for x in names)

        for item in items:
            result[key(item)].append(item)

        return result
1189774
def add_general_report_optgroup(parser):
    

    g = parser.add_argument_group("Reporting Options")

    g.add_argument("--report-dir", action="store", default=None)

    g.add_argument("--report", action=_opt_cb_report,
                   help="comma-separated list of report formats")
119822
def _parse_info(line):
        
        re_info = re.compile(
            r'\[(?P<name>\w+).(?P<ver>.*) ' +
            r'\((?P<rfm1name>\w+) (\w+):(?P<rfm1freq>\d+) ' +
            r'(?P<rfm1mode>.*)\)\]')

        info = {
            'name': None,
            'version': None,
            'rfm1name': None,
            'rfm1frequency': None,
            'rfm1datarate': None,
            'rfm1toggleinterval': None,
            'rfm1togglemask': None,
        }
        match = re_info.match(line)
        if match:
            info['name'] = match.group('name')
            info['version'] = match.group('ver')
            info['rfm1name'] = match.group('rfm1name')
            info['rfm1frequency'] = match.group('rfm1freq')
            values = match.group('rfm1mode').split(':')
            if values[0] == 'r':
                info['rfm1datarate'] = values[1]
            elif values[0] == 't':
                toggle = values[1].split('~')
                info['rfm1toggleinterval'] = toggle[0]
                info['rfm1togglemask'] = toggle[1]

        return info