r"""Check format of htarg/ftarg and return dict.
504519
def _check_targ(targ, keys):
    """
    if not targ:  # If None
        targ = {}
    elif not isinstance(targ, (list, tuple, dict)):  # If only one value
        targ = [targ, ]
    if isinstance(targ, (list, tuple)):  # Put list into dict
        targ = {keys[i]: targ[i] for i in range(min(len(targ), len(keys)))}
    return targ
1316733
def get_arglist(self, objtxt):
        """"""
        obj, valid = self._eval(objtxt)
        if valid:
            return getargtxt(obj)
704264
def dictstr(arg):
    
    key, value = arg.split("=")

    if value.lower() == "true" or value.lower() == "false":
        value = bool(value)
    elif INT_RE.match(value):
        value = int(value)
    elif FLOAT_RE.match(value):
        value = float(value)
    return (key, value)
1275715
def inspect(self):
        """"""
        results = {}
        for fname in dir(self):
            if not fname.startswith('_'):
                value = getattr(self, fname)
                if isinstance(value, collections.Callable):
                    continue
                results[fname] = value
        return results
81261
def extract_format_spec(cls, format):
        """"""
        # -- BASED-ON: parse.extract_format()
        # pylint: disable=redefined-builtin, unsubscriptable-object
        if not format:
            raise ValueError("INVALID-FORMAT: %s (empty-string)" % format)

        orig_format = format
        fill = align = None
        if format[0] in cls.ALIGN_CHARS:
            align = format[0]
            format = format[1:]
        elif len(format) > 1 and format[1] in cls.ALIGN_CHARS:
            fill = format[0]
            align = format[1]
            format = format[2:]

        zero = False
        if format and format[0] == '0':
            zero = True
            format = format[1:]

        width = ''
        while format:
            if not format[0].isdigit():
                break
            width += format[0]
            format = format[1:]

        precision = None
        if format.startswith('.'):
            # Precision isn't needed but we need to capture it so that
            # the ValueError isn't raised.
            format = format[1:]  # drop the '.'
            precision = ''
            while format:
                if not format[0].isdigit():
                    break
                precision += format[0]
                format = format[1:]

        # the rest is the type, if present
        type = format
        if not type:
            raise ValueError("INVALID-FORMAT: %s (without type)" % orig_format)
        return FormatSpec(type, width, zero, align, fill, precision)
319138
def args_as_tuple(self):
        """"""
        if "," in self.arguments["header-names"]:
            result = tuple(tools.to_list(self.arguments["header-names"]))
        else:
            result = (self.arguments["header-names"].strip('"'),)
        result = result + (self.arguments["match-type"],)
        if "," in self.arguments["key-list"]:
            result = result + tuple(
                tools.to_list(self.arguments["key-list"], unquote=False))
        else:
            result = result + (self.arguments["key-list"].strip('"'),)
        return result
858013
def _argsdicts( args, mydict ):
    """"""
    
    if len( args ) == 0:
        args = None, 
    elif len( args ) == 1:
        args = _totuple( args[0] )
    else:
        raise Exception( "We should have never gotten here." )

    mykeys = list( mydict.keys( ) )
    myvalues = list( map( _totuple, list( mydict.values( ) ) ) )

    maxlength = max( list( map( len, [ args ] + myvalues ) ) )

    for i in range( maxlength ):
        thisdict = { }
        for key, value in zip( mykeys, myvalues ):
            try:
                thisdict[ key ] = value[i]
            except IndexError:
                thisdict[ key ] = value[-1]
        try:
            thisarg = args[i]
        except IndexError:
            thisarg = args[-1]

        yield thisarg, thisdict
663970
def RDcurv(s):
    """"""
    # See [ICC 2001] 6.5.3
    assert s[0:4] == 'curv'
    count, = struct.unpack('>L', s[8:12])
    if count == 0:
        return dict(gamma=1)
    table = struct.unpack('>%dH' % count, s[12:])
    if count == 1:
        return dict(gamma=table[0] * 2 ** -8)
    return table
868130
def _parse_arg(self, arg):
        """"""
        match = self.SPECIAL_RE.search(arg)
        if match:
            raise KatcpSyntaxError("Unescaped special %r." % (match.group(),))
        return self.UNESCAPE_RE.sub(self._unescape_match, arg)
1151385
def check_rst(code, ignore):
    """"""
    filename = '<string>'

    for result in check(code,
                        filename=filename,
                        ignore=ignore):
        yield result
311128
def _GetFormatter(self, format_str):
        
        formatter, args, func_type = self.formatters.LookupWithType(format_str)
        if formatter:
            return formatter, args, func_type
        else:
            raise BadFormatter('%r is not a valid formatter' % format_str)
74302
def _format_dict(self, info_dict):
        """"""
        for key, value in info_dict.items():
            if not value:
                info_dict[key] = "NA"
        return info_dict
815772
def _format_firewall_stdout(cmd_ret):
    '''
    
    '''
    ret_dict = {'success': True,
                'rulesets': {}}
    for line in cmd_ret['stdout'].splitlines():
        if line.startswith('Name'):
            continue
        if line.startswith('---'):
            continue
        ruleset_status = line.split()
        ret_dict['rulesets'][ruleset_status[0]] = bool(ruleset_status[1])

    return ret_dict
18193
def check_output_format(expected_formats):
    
    def output_format_decorator(func):
        def func_wrapper(*args, **kwargs):
            self = args[0]
            if self.output_format not in expected_formats:
                raise ValueError("expected output format {}, got {}".format('doc_gen', self.output_format))
            return func(*args, **kwargs)
        return func_wrapper
    return output_format_decorator
730861
def str_arg(d):
    """"""
    if not d:
        return None
    if isinstance(d, dict):
        if len(d) == 2 and d.get('type') == 'text' and 'value' in d:
            return str_arg(d['value'])
        if len(d) == 2 and d.get('type') == 'text' and 'subkey' in d:
            return ".%s" % d['subkey']
        if d.get('type') == 'module':
            return None
        return "{%s}" % str_args(d.items())
    if isinstance(d, list):
        if len(d) == 1:
            return str_arg(d[0])
        return "[%s]" % ", ".join(str_arg(elem) for elem in d)
    if isinstance(d, unicode):
        return '"%s"' % d

    return repr(d)
590929
def validate_args(opts):
    """"""
    if opts['--wide'] is None:
        opts['--wide'] = 2
    else:
        assert opts['--wide'] in ("1", "2"), opts['--wide']
    if opts['--alignment'] is None:
        opts['--alignment'] = 'left'
    else:
        assert opts['--alignment'] in ('left', 'right'), opts['--alignment']
    opts['--wide'] = int(opts['--wide'])
    opts['character_factory'] = WcWideCharacterGenerator
    if opts['--combining']:
        opts['character_factory'] = WcCombinedCharacterGenerator
    return opts
1360850
def _parse_arguments(arguments=None):
    """"""
    dir_hash = hashlib.sha1(os.getcwd().encode("utf-8")).hexdigest()

    parser = argparse.ArgumentParser(description="""Find spelling errors""")
    parser.add_argument("files",
                        nargs="*",
                        metavar=("FILE"),
                        help="""read FILE""",
                        type=str)
    parser.add_argument("--spellcheck-cache",
                        help="""path to spell-checking cache file""",
                        default=None)
    parser.add_argument("--technical-terms",
                        help="""path to file to source technical terms from""",
                        default=None)
    parser.add_argument("--stamp-file-path",
                        help="""path to directory to store cached results""",
                        default=os.path.join(tempfile.gettempdir(),
                                             "jobstamps",
                                             "spellcheck_linter",
                                             dir_hash))

    return parser.parse_args(arguments)