当前位置: 首页>>代码示例>>Python>>正文


Python validate.Validator方法代码示例

本文整理汇总了Python中validate.Validator方法的典型用法代码示例。如果您正苦于以下问题:Python validate.Validator方法的具体用法?Python validate.Validator怎么用?Python validate.Validator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validate的用法示例。


在下文中一共展示了validate.Validator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def parse(self, config, defaults=None):
        """Parse the conf

        :param config: Configuration to parse
        :type config: str, list or File

        :param defaults: Default options
        :type defaults: dict
        """
        self.conf = {}
        self.conffile = config
        self.section = None
        if defaults is not None or not hasattr(self, 'defaults'):
            self.defaults = defaults
        self.validator = validate.Validator()
        try:
            self.conf = configobj.ConfigObj(config, encoding='utf-8')
            self.mtime = os.path.getmtime(self.conffile)
        except configobj.ConfigObjError as exp:
            # We were unable to parse the config
            self.logger.critical('Unable to parse configuration')
            raise exp 
开发者ID:ziirish,项目名称:burp-ui,代码行数:24,代码来源:config.py

示例2: validate

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def validate(self):
		
		for key in self.entrydict.keys():
			if key.find("Password") == -1:
				self.settings[self.section][key] = self.entrydict[key].get()
			else:
				self.settings[self.section][key] = myutils.password_obfuscate(self.entrydict[key].get())
		
		errortext="Some of your input contains errors. Detailed error output below.\n\n"
		
		val = Validator()
		valresult=self.settings.validate(val, preserve_errors=True)
		if valresult != True:
			if valresult.has_key(self.section):
				sectionval = valresult[self.section]
				for key in sectionval.keys():
					if sectionval[key] != True:
						errortext += "Error in item \"" + str(key) + "\": " + str(sectionval[key]) + "\n"
				tkMessageBox.showerror("Erroneous input. Please try again.", errortext)
			return 0
		else:
			return 1 
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:24,代码来源:controlpanel.py

示例3: read_default_config

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def read_default_config(self):
        """Read the default config file.

        :raises DefaultConfigValidationError: There was a validation error with
                                              the *default* file.
        """
        if self.validate:
            self.default_config = ConfigObj(configspec=self.default_file,
                                            list_values=False, _inspec=True,
                                            encoding='utf8')
            valid = self.default_config.validate(Validator(), copy=True,
                                                 preserve_errors=True)
            if valid is not True:
                for name, section in valid.items():
                    if section is True:
                        continue
                    for key, value in section.items():
                        if isinstance(value, ValidateError):
                            raise DefaultConfigValidationError(
                                'section [{}], key "{}": {}'.format(
                                    name, key, value))
        elif self.default_file:
            self.default_config, _ = self.read_config_file(self.default_file)

        self.update(self.default_config) 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:27,代码来源:config.py

示例4: read_config_file

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def read_config_file(self, f):
        """Read a config file *f*.

        :param str f: The path to a file to read.
        """
        configspec = self.default_file if self.validate else None
        try:
            config = ConfigObj(infile=f, configspec=configspec,
                               interpolation=False, encoding='utf8')
        except ConfigObjError as e:
            logger.warning(
                'Unable to parse line {} of config file {}'.format(
                    e.line_number, f))
            config = e.config

        valid = True
        if self.validate:
            valid = config.validate(Validator(), preserve_errors=True,
                                    copy=True)
        if bool(config):
            self.config_filenames.append(config.filename)

        return config, valid 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:25,代码来源:config.py

示例5: validate_config

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def validate_config(config):
        """Validate configuration
        """
        validator = validate.Validator()
        result = config.validate(validator,
                                 copy=True,
                                 preserve_errors=True)

        if not isinstance(result, bool):
            raise ValueError("Configuration does not adhere"
                             " to the specification: %s" %
                             configobj.flatten_errors(config, result))
        elif not result:
            # This should never happen
            raise RuntimeError(  # pragma: no cover
                "Configuration validated to false.") 
开发者ID:duerrp,项目名称:pyexperiment,代码行数:18,代码来源:Config.py

示例6: dict2cfgfile

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def dict2cfgfile():
    for inst_det in param_dict.keys():

        cfg_filename = "{}/runhlaprocessing_{}.cfg".format(os.path.join(os.path.dirname(__file__), "pars"),inst_det.replace(" ","_").lower())
        configspec_filename ="{}/runhlaprocessing_config.spec".format(os.path.join(os.path.dirname(__file__),"pars"))
        print("FILENAME: ",cfg_filename)
        print("CONFIGSPEC: ",configspec_filename)
        config = ConfigObj(cfg_filename,configspec=configspec_filename)


        for section in param_dict[inst_det].keys():
            config[section] = {}
            for param in param_dict[inst_det][section].keys():
                print(inst_det, section,param,">>>>>> ",param_dict[inst_det][section][param])
                config[section][param] = param_dict[inst_det][section][param]
            print("\n")

        validator = Validator()
        result = config.validate(validator)
        print("RESULT: ",result)
        config.write()
        print("Wrote "+cfg_filename)
        return()

#============================================================================================================ 
开发者ID:spacetelescope,项目名称:drizzlepac,代码行数:27,代码来源:make_cfgobj_files.py

示例7: readcfgfile

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def readcfgfile(inst_det):
    cfg_filename = "{}/runhlaprocessing_{}.cfg".format(os.path.join(os.path.dirname(__file__), "pars"),inst_det.replace(" ", "_").lower())
    configspec_filename = "{}/runhlaprocessing_config.spec".format(os.path.join(os.path.dirname(__file__),"pars"))
    print("Converting config file {} to parameter dictionary".format(cfg_filename))
    newconfig = ConfigObj(cfg_filename,configspec=configspec_filename)
    validator = Validator()
    newconfig.validate(validator)
    param_dict={}
    for section in newconfig.keys():
        param_dict[section]={}
        for parameter in newconfig[section].keys():
            value = newconfig[section][parameter]
            param_dict[section][parameter] = value


    for section in param_dict.keys():
        for parameter in param_dict[section].keys():
            value = param_dict[section][parameter]
            print(section, parameter, value, type(value))
    return(param_dict)


#============================================================================================================ 
开发者ID:spacetelescope,项目名称:drizzlepac,代码行数:25,代码来源:make_cfgobj_files.py

示例8: parse_config_file

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def parse_config_file(config_file, config_spec_file):

    assert validators.PanoptesValidators.valid_nonempty_string(config_file), u'config_file must be a non-empty str'
    assert validators.PanoptesValidators.valid_nonempty_string(config_spec_file), \
        u'config_spec_file must be a non empty str'

    try:
        config = ConfigObj(config_file, configspec=config_spec_file, interpolation=u'template', file_error=True)
    except IOError as e:
        raise PanoptesConfigurationParsingError(u'Error reading file: %s' % str(e))
    except ConfigObjError as e:
        raise PanoptesConfigurationParsingError(u'Error parsing config file "%s": %s' % (config_file, str(e)))

    validator = Validator()
    result = config.validate(validator, preserve_errors=True)

    if result is not True:
        errors = u''
        for (section_list, key, error) in flatten_errors(config, result):
            if key is None:
                errors += u'Section(s) ' + u','.join(section_list) + u' are missing\n'
            else:
                errors += u'The "' + key + u'" key in section "' + u','.join(section_list) + u'" failed validation\n'

        raise PanoptesConfigurationParsingError(u'Error parsing the configuration file: %s' % errors)

    return config 
开发者ID:yahoo,项目名称:panoptes,代码行数:29,代码来源:helpers.py

示例9: parse_crawler_config

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def parse_crawler_config(config_path='crawler.conf'):
    global _config

    # 1. get configs
    _config = ConfigObj(infile=misc.execution_path(config_path),
                        configspec=misc.execution_path(CONFIG_SPEC_PATH))

    # Configspec is not being used currently
    # but keeping validate() and apply_user_args() for future.
    # Essentially NOP right now

    # 2. apply defaults
    vdt = Validator()
    _config.validate(vdt) 
开发者ID:cloudviz,项目名称:agentless-system-crawler,代码行数:16,代码来源:config_parser.py

示例10: _validate_ini

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def _validate_ini(self):
        # building a validator
        validator = Validator({
            'region_func': _region,
            'account_func': _account,
            'project_func': _project_mapping
        })
        # validate
        param_valid_dict = self._config_dict.validate(validator=validator)
        if not param_valid_dict:
            raise Exception(f'Error while parsing {self._config_path}')
        # check non-required parameters
        prefix_value = self._config_dict.get(RESOURCES_PREFIX_CFG)
        if prefix_value:
            if len(prefix_value) > 5:
                if not isinstance(param_valid_dict, dict):
                    param_valid_dict = {RESOURCES_PREFIX_CFG: False}
                else:
                    param_valid_dict[RESOURCES_PREFIX_CFG] = False

        suffix_value = self._config_dict.get(RESOURCES_SUFFIX_CFG)
        if suffix_value:
            if len(suffix_value) > 5:
                if not isinstance(param_valid_dict, dict):
                    param_valid_dict = {RESOURCES_SUFFIX_CFG: False}
                else:
                    param_valid_dict[RESOURCES_SUFFIX_CFG] = False

        # processing results
        if isinstance(param_valid_dict, dict):
            messages = ''
            for key, value in param_valid_dict.items():
                if not value:
                    messages += '\n{0} {1}'.format(key,
                                                   ERROR_MESSAGE_MAPPING[key])

            if messages:
                raise Exception('Configuration is invalid. ' + messages) 
开发者ID:epam,项目名称:aws-syndicate,代码行数:40,代码来源:processor.py

示例11: __init__

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def __init__(self):
        super(ComicStreamerConfig, self).__init__()
               
        self.csfolder = AppFolders.settings()

        # make sure folder exisits
        if not os.path.exists( self.csfolder ):
            os.makedirs( self.csfolder )

        # set up initial values
        self.filename = os.path.join(self.csfolder, "settings")
        self.configspec=io.StringIO(ComicStreamerConfig.configspec)
        self.encoding="UTF8"
        
        # since some stuff in the configobj has to happen during object initialization,
        # use a temporary delegate,  and them merge it into self
        tmp = ConfigObj(self.filename, configspec=self.configspec, encoding=self.encoding)
        validator = Validator()
        tmp.validate(validator,  copy=True)
       
        # set up the install ID
        if tmp['general']['install_id'] == '':
            tmp['general']['install_id'] = uuid.uuid4().hex
            
        #set up the cookie secret
        if tmp['security']['cookie_secret'] == '':
            tmp['security']['cookie_secret'] = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)

        # normalize the folder list
        tmp['general']['folder_list'] = [os.path.abspath(os.path.normpath(unicode(a))) for a in tmp['general']['folder_list']]

        self.merge(tmp)
        if not os.path.exists( self.filename ):
            self.write()
            
        # not sure if this belongs here:
        # if mac app, and no unrar in path, add the one from the app bundle
        if getattr(sys, 'frozen', None) and  platform.system() == "Darwin":
            if which("unrar") is None:
                addtopath(AppFolders.appBase()) 
开发者ID:beville,项目名称:ComicStreamer,代码行数:42,代码来源:config.py

示例12: main

# 需要导入模块: import validate [as 别名]
# 或者: from validate import Validator [as 别名]
def main(args):
    configspec = ConfigObj(args.config_spec, raise_errors=True)
    config = ConfigObj(args.config_file,
                       configspec=configspec,
                       raise_errors=True,
                       file_error=True)
    # Validate to get all the default values.
    config.validate(Validator())
    if not os.path.exists(config['exp_dir']):
        # checkpoint directory.
        os.makedirs(os.path.join(config['exp_dir'], 'checkpoint'))
        # Tensorboard logs directory.
        os.makedirs(os.path.join(config['exp_dir'], 'logs'))
        # default output directory for this experiment.
        os.makedirs(os.path.join(config['exp_dir'], 'sample'))
    network_type = config['architecture']['network_arch']
    exp_name = config['exp_name']
    setproctitle.setproctitle('{}_{}_{}' \
                              .format(args.phase, network_type, exp_name))
    tfconfig = tf.ConfigProto(allow_soft_placement=True,
                              log_device_placement=False)
    tfconfig.gpu_options.allow_growth = True

    with tf.Session(config=tfconfig) as sess:
        model = MagNet3Frames(sess, exp_name, config['architecture'])
        checkpoint = config['training']['checkpoint_dir']
        if args.phase == 'train':
            train_config = config['training']
            if not os.path.exists(train_config['checkpoint_dir']):
                os.makedirs(train_config['checkpoint_dir'])
            model.train(train_config)
        elif args.phase == 'run':
            model.run(checkpoint,
                      args.vid_dir,
                      args.frame_ext,
                      args.out_dir,
                      args.amplification_factor,
                      args.velocity_mag)
        elif args.phase == 'run_temporal':
            model.run_temporal(checkpoint,
                               args.vid_dir,
                               args.frame_ext,
                               args.out_dir,
                               args.amplification_factor,
                               args.fl,
                               args.fh,
                               args.fs,
                               args.n_filter_tap,
                               args.filter_type)
        else:
            raise ValueError('Invalid phase argument. '
                             'Expected ["train", "run", "run_temporal"], '
                             'got ' + args.phase) 
开发者ID:12dmodel,项目名称:deep_motion_mag,代码行数:55,代码来源:main.py


注:本文中的validate.Validator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。