Make sure a valid parser is passed.

    Parameters
    ----------
    parser : str

    Raises
    ------
    KeyError
      * If an invalid parser is passed
779172
def _check_parser(parser):
    
    from pandas.core.computation.expr import _parsers

    if parser not in _parsers:
        raise KeyError('Invalid parser {parser!r} passed, valid parsers are'
                       ' {valid}'.format(parser=parser, valid=_parsers.keys()))
87487
def get_parser(self):
        
        self.path = None
        self.anony_defs = []
        self.exhausted = False
        return self
775644
def new_parser(self):
        

        parser = argparse.ArgumentParser(description=self.description)
        parser.add_argument(
            '--version', help='show version and exit',
            default=False, action='store_true')
        parser.add_argument(
            '--debug', help='enable debugging',
            default=False, action='store_true')
        return parser
780434
def _validate_importers(importers):
    
    # They could have no importers, that's chill
    if importers is None:
        return None

    def _to_importer(priority, func):
        assert isinstance(priority, int), priority
        assert callable(func), func
        return (priority, _importer_callback_wrapper(func))

    # Our code assumes tuple of tuples
    return tuple(_to_importer(priority, func) for priority, func in importers)
167587
def any_validator(obj, validators, **kwargs):
    
    if not len(validators) > 1:
        raise ValueError(
            "any_validator requires at least 2 validator.  Only got "
            "{0}".format(len(validators))
        )
    errors = ErrorDict()
    for key, validator in validators.items():
        try:
            validator(obj, **kwargs)
        except ValidationError as err:
            errors[key] = err.detail
        else:
            break
    else:
        if len(errors) == 1:
            # Special case for a single error.  Just raise it as if it was the
            # only validator run.
            error = errors.values()[0]
            raise ValidationError(error)
        else:
            # Raise all of the errors with the key namespaces.
            errors.raise_()
1229347
def register_parser(self, type, parser, **meta):
        
        try:
            self.registered_formats[type]['parser'] = parser
        except KeyError:
            self.registered_formats[type] = {'parser': parser}
        if meta:
            self.register_meta(type, **meta)
705208
def build_parser(line):
    # type: (Text) -> optparse.OptionParser
    
    parser = optparse.OptionParser(add_help_option=False)

    option_factories = SUPPORTED_OPTIONS + SUPPORTED_OPTIONS_REQ
    for option_factory in option_factories:
        option = option_factory()
        parser.add_option(option)

    # By default optparse sys.exits on parsing errors. We want to wrap
    # that in our own exception.
    def parser_exit(self, msg):
        # add offending line
        msg = 'Invalid requirement: %s\n%s' % (line, msg)
        raise RequirementsFileParseError(msg)
    # NOTE: mypy disallows assigning to a method
    #       https://github.com/python/mypy/issues/2427
    parser.exit = parser_exit  # type: ignore

    return parser
717686
def check(self):
        
        try:
            value = self.raw_value
        except (AttributeError, KeyError) as err:
            self._reraise_if_required(err)
        else:
            if self.checker:
                self.checker(self.full_name, value)
            try:
                self.validate(value)
                self.run_validators(value)
            except ValidationError as error:
                raise ValueError("Setting {} has an invalid value: {}".format(self.full_name, error))
278744
def validate(self, options):
        
        try:
            codecs.getencoder(options.char_encoding)
        except LookupError:
            self.parser.error("invalid 'char-encoding' %s" % options.char_encoding)
1141458
def parsing(**kwargs):
    

    from .validators import Object
    with _VALIDATOR_FACTORIES_LOCK:
        old_values = {}
        for key, value in iteritems(kwargs):
            if value is not None:
                attr = key.upper()
                old_values[key] = getattr(Object, attr)
                setattr(Object, attr, value)
        try:
            yield
        finally:
            for key, value in iteritems(kwargs):
                if value is not None:
                    setattr(Object, key.upper(), old_values[key])
214302
def _create_argument_parser(self):
        
        parser = self._new_argument_parser()
        self._add_base_arguments(parser)
        self._add_required_arguments(parser)
        return parser
305045
def add_peer_parser(subparsers, parent_parser):
    
    parser = subparsers.add_parser(
        'peer',
        help='Displays information about validator peers',
        description="Provides a subcommand to list a validator's peers")

    grand_parsers = parser.add_subparsers(title='subcommands',
                                          dest='subcommand')
    grand_parsers.required = True
    add_peer_list_parser(grand_parsers, parent_parser)
229489
def validate(cls):
        
        if cls.get_dict():
            cls.show_error(False)
            return True

        cls.show_error(True)
        return False
1241392
def init(parser = None):
    

    global p,subparsers
    if parser is None:
        p = argparse.ArgumentParser()
    else:
        p = parser

    arg = p.add_argument

    subparsers = p.add_subparsers()
1347900
def setup_parser(self, parser):
        

        parser.add_argument('task_name', help='task to create')
        parser.add_argument('clone_task', nargs='?',
                            help='existing task to clone')
        parser.add_argument('--skip-edit', action='store_true',
                            help='skip editing of task configuration')
1248452
def validate_kwargs(self, kwargs):
        
        if not self.response_type:
            msg = "response_type must be set on the Response subclass."
            raise ValidationException(msg)

        if (self.key_name and self.key_name in kwargs) or "type" in kwargs:
            name = self.__class__.__name__
            msg = "%s is an invalid argument for %s" % (self.key_name, name)
            raise ValidationException(msg)
1356244
def validate(cls, mapper_spec):
    
    if mapper_spec.input_reader_class() != cls:
      raise BadReaderParamsError("Mapper input reader class mismatch")
    params = _get_params(mapper_spec)
    if cls.BLOB_KEY_PARAM not in params:
      raise BadReaderParamsError("Must specify 'blob_key' for mapper input")
    blob_key = params[cls.BLOB_KEY_PARAM]
    blob_info = blobstore.BlobInfo.get(blobstore.BlobKey(blob_key))
    if not blob_info:
      raise BadReaderParamsError("Could not find blobinfo for key %s" %
                                 blob_key)