(input)
return None
Check that an option or argument given to GPG is in the set of allowed
    options, the latter being a strict subset of the set of all options known
    to GPG.

    :param str input: An input meant to be parsed as an option or flag to the
                      GnuPG process. Should be formatted the same as an option
                      or flag to the commandline gpg, i.e. "--encrypt-files".

    :ivar frozenset gnupg_options: All known GPG options and flags.

    :ivar frozenset allowed: All allowed GPG options and flags, e.g. all GPG
                             options and flags which we are willing to
                             acknowledge and parse. If we want to support a
                             new option, it will need to have its own parsing
                             class and its name will need to be added to this
                             set.

    :raises: :exc:`UsageError` if **input** is not a subset of the hard-coded
             set of all GnuPG options in :func:`_get_all_gnupg_options`.

             :exc:`ProtectedOption` if **input** is not in the set of allowed
             options.

    :rtype: str
    :return: The original **input** parameter, unmodified and unsanitized, if
             no errors occur.
Check that an option or argument given to GPG is in the set of allowed
    options, the latter being a strict subset of the set of all options known
    to GPG.
Check that an option or argument given to GPG is in the set of allowed options the latter being a strict subset of the set of all options known to GPG .
def _is_allowed(input):
    """Check that an option or argument given to GPG is in the set of allowed
    options, the latter being a strict subset of the set of all options known
    to GPG.

    :param str input: An input meant to be parsed as an option or flag to the
                      GnuPG process. Should be formatted the same as an option
                      or flag to the commandline gpg, i.e. "--encrypt-files".

    :ivar frozenset gnupg_options: All known GPG options and flags.

    :ivar frozenset allowed: All allowed GPG options and flags, e.g. all GPG
                             options and flags which we are willing to
                             acknowledge and parse. If we want to support a
                             new option, it will need to have its own parsing
                             class and its name will need to be added to this
                             set.

    :raises: :exc:`UsageError` if **input** is not a subset of the hard-coded
             set of all GnuPG options in :func:`_get_all_gnupg_options`.

             :exc:`ProtectedOption` if **input** is not in the set of allowed
             options.

    :rtype: str
    :return: The original **input** parameter, unmodified and unsanitized, if
             no errors occur.
    """
    gnupg_options = _get_all_gnupg_options()
    allowed = _get_options_group("allowed")

    ## these are the allowed options we will handle so far, all others should
    ## be dropped. this dance is so that when new options are added later, we
    ## merely add the to the _allowed list, and the `` _allowed.issubset``
    ## assertion will check that GPG will recognise them
    try:
        ## check that allowed is a subset of all gnupg_options
        assert allowed.issubset(gnupg_options)
    except AssertionError:
        raise UsageError("'allowed' isn't a subset of known options, diff: %s"
                         % allowed.difference(gnupg_options))

    ## if we got a list of args, join them
    ##
    ## see TODO file, tag :cleanup:
    if not isinstance(input, str):
        input = ' '.join([x for x in input])

    if isinstance(input, str):
        if input.find('_') > 0:
            if not input.startswith('--'):
                hyphenated = _hyphenate(input, add_prefix=True)
            else:
                hyphenated = _hyphenate(input)
        else:
            hyphenated = input
            ## xxx we probably want to use itertools.dropwhile here
            try:
                assert hyphenated in allowed
            except AssertionError as ae:
                dropped = _fix_unsafe(hyphenated)
                log.warn("_is_allowed(): Dropping option '%s'..." % dropped)
                raise ProtectedOption("Option '%s' not supported." % dropped)
            else:
                return input
    return None
def _is_allowed ( input ) : gnupg_options = _get_all_gnupg_options ( ) allowed = _get_options_group ( "allowed" ) ## these are the allowed options we will handle so far, all others should ## be dropped. this dance is so that when new options are added later, we ## merely add the to the _allowed list, and the `` _allowed.issubset`` ## assertion will check that GPG will recognise them try : ## check that allowed is a subset of all gnupg_options assert allowed . issubset ( gnupg_options ) except AssertionError : raise UsageError ( "'allowed' isn't a subset of known options, diff: %s" % allowed . difference ( gnupg_options ) ) ## if we got a list of args, join them ## ## see TODO file, tag :cleanup: if not isinstance ( input , str ) : input = ' ' . join ( [ x for x in input ] ) if isinstance ( input , str ) : if input . find ( '_' ) > 0 : if not input . startswith ( '--' ) : hyphenated = _hyphenate ( input , add_prefix = True ) else : hyphenated = _hyphenate ( input ) else : hyphenated = input ## xxx we probably want to use itertools.dropwhile here try : assert hyphenated in allowed except AssertionError as ae : dropped = _fix_unsafe ( hyphenated ) log . warn ( "_is_allowed(): Dropping option '%s'..." % dropped ) raise ProtectedOption ( "Option '%s' not supported." % dropped ) else : return input return None