Create a config object from an instance dictionary
769138
def from_instance(instance, default_ca_certs=None):
    
    method = instance.get('method', 'get')
    data = instance.get('data', {})
    tags = instance.get('tags', [])
    ntlm_domain = instance.get('ntlm_domain')
    username = instance.get('username')
    password = instance.get('password')
    client_cert = instance.get('client_cert')
    client_key = instance.get('client_key')
    http_response_status_code = str(instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
    timeout = int(instance.get('timeout', 10))
    config_headers = instance.get('headers', {})
    default_headers = is_affirmative(instance.get("include_default_headers", True))
    if default_headers:
        headers = agent_headers({})
    else:
        headers = {}
    headers.update(config_headers)
    url = instance.get('url')
    if url is not None:
        url = ensure_unicode(url)
    content_match = instance.get('content_match')
    if content_match is not None:
        content_match = ensure_unicode(content_match)
    reverse_content_match = is_affirmative(instance.get('reverse_content_match', False))
    response_time = is_affirmative(instance.get('collect_response_time', True))
    if not url:
        raise ConfigurationError("Bad configuration. You must specify a url")
    if not url.startswith("http"):
        raise ConfigurationError("The url {} must start with the scheme http or https".format(url))
    include_content = is_affirmative(instance.get('include_content', False))
    disable_ssl_validation = is_affirmative(instance.get('disable_ssl_validation', True))
    ssl_expire = is_affirmative(instance.get('check_certificate_expiration', True))
    instance_ca_certs = instance.get('ca_certs', default_ca_certs)
    weakcipher = is_affirmative(instance.get('weakciphers', False))
    ignore_ssl_warning = is_affirmative(instance.get('ignore_ssl_warning', False))
    check_hostname = is_affirmative(instance.get('check_hostname', True))
    skip_proxy = is_affirmative(instance.get('skip_proxy', instance.get('no_proxy', False)))
    allow_redirects = is_affirmative(instance.get('allow_redirects', True))
    stream = is_affirmative(instance.get('stream', False))

    return Config(
        url,
        ntlm_domain,
        username,
        password,
        client_cert,
        client_key,
        method,
        data,
        http_response_status_code,
        timeout,
        include_content,
        headers,
        response_time,
        content_match,
        reverse_content_match,
        tags,
        disable_ssl_validation,
        ssl_expire,
        instance_ca_certs,
        weakcipher,
        check_hostname,
        ignore_ssl_warning,
        skip_proxy,
        allow_redirects,
        stream,
    )
909090
def instance(*args, **kwargs):
        

        if not hasattr(Config, "_instance") or Config._instance is None:
            Config._instance = Config(*args, **kwargs)
        return Config._instance
944470
def as_dict(self):
        """"""
        return {config_name: getattr(self, config_name)
                for config_name, _ in self._iter_config_props()}
492541
def from_dict(cls, parameters):
        
        instance = cls()
        instance.fitted = parameters['fitted']
        instance.constant_value = parameters['constant_value']

        if instance.fitted and instance.constant_value is None:
            instance.model = scipy.stats.truncnorm(parameters['a'], parameters['b'])

        return instance
281004
def config_conf(obj):
    ""
    # If we ever want to add some default options this is where to do that
    cfg = {}
    for name in dir(obj):
        if name in CONFIG_PARSER_CFG: # argument of ConfigParser
            cfg[name] = getattr(obj, name)
    return cfg
484323
def get_instance(in_memory=False, config_path=None, config_name=None):
  
  global __conf

  if __conf is None:
    __conf = Configuration(in_memory=in_memory, custom_cfg_path=config_path, config_name=config_name)

  return __conf
265805
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'environment_id' in _dict:
            args['environment_id'] = _dict.get('environment_id')
        if 'collection_id' in _dict:
            args['collection_id'] = _dict.get('collection_id')
        if 'queries' in _dict:
            args['queries'] = [
                TrainingQuery._from_dict(x) for x in (_dict.get('queries'))
            ]
        return cls(**args)
333932
def _construct_instance(cls, values):
        
        # we're going to take the values, which is from the DB as a dict
        # and translate that into our local fields
        # the db_map is a db_field -> model field map
        items = values.items()
        field_dict = dict([(cls._db_map.get(k, k),v) for k,v in items])

        if cls._is_polymorphic:
            poly_key = field_dict.get(cls._polymorphic_column_name)

            if poly_key is None:
                raise PolyMorphicModelException('polymorphic key was not found in values')

            poly_base = cls if cls._is_polymorphic_base else cls._polymorphic_base

            klass = poly_base._get_model_by_polymorphic_key(poly_key)
            if klass is None:
                poly_base._discover_polymorphic_submodels()
                klass = poly_base._get_model_by_polymorphic_key(poly_key)
                if klass is None:
                    raise PolyMorphicModelException(
                        'unrecognized polymorphic key {} for class {}'.format(poly_key, poly_base.__name__)
                    )

            if not issubclass(klass, cls):
                raise PolyMorphicModelException(
                    '{} is not a subclass of {}'.format(klass.__name__, cls.__name__)
                )

            field_dict = {k: v for k, v in field_dict.items() if k in klass._columns.keys()}

        else:
            klass = cls

        instance = klass(**field_dict)
        instance._is_persisted = True
        return instance
1193754
def from_dict(cls, d):
        
        result = OptionHandler(cls.new_instance(d["class"]))
        result.options = split_options(d["options"])
        return result
1113777
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'customization_id' in _dict:
            args['customization_id'] = _dict.get('customization_id')
        else:
            raise ValueError(
                'Required property \'customization_id\' not present in VoiceModel JSON'
            )
        if 'name' in _dict:
            args['name'] = _dict.get('name')
        if 'language' in _dict:
            args['language'] = _dict.get('language')
        if 'owner' in _dict:
            args['owner'] = _dict.get('owner')
        if 'created' in _dict:
            args['created'] = _dict.get('created')
        if 'last_modified' in _dict:
            args['last_modified'] = _dict.get('last_modified')
        if 'description' in _dict:
            args['description'] = _dict.get('description')
        if 'words' in _dict:
            args['words'] = [Word._from_dict(x) for x in (_dict.get('words'))]
        return cls(**args)
1374828
def from_config(config):
    
    matrix = {}
    variables = config.keys()
    for entries in product(*config.values()):
        combination = dict(zip(variables, entries))
        include = True
        for value in combination.values():
            for reducer in value.reducers:
                if reducer.pattern == '-':
                    match = not combination[reducer.variable].value
                else:
                    match = fnmatch(combination[reducer.variable].value, reducer.pattern)
                if match if reducer.is_exclude else not match:
                    include = False
        if include:
            key = '-'.join(entry.alias for entry in entries if entry.alias)
            data = dict(
                zip(variables, (entry.value for entry in entries))
            )
            if key in matrix and data != matrix[key]:
                raise DuplicateEnvironment(key, data, matrix[key])
            matrix[key] = data
    return matrix
603327
def from_config(config):
        
        result = Parameters()
        
        if config == None or len(config) == 0:
            return result
        
        for (key, value) in config.items():
            result.put(key, value)
        
        return result
1260264
def use_settings_dict(self, settings_dict):
        '''
        
        '''
        class SettingsDictModule:
            __slots__ = tuple(key.upper() for key in settings_dict.keys())
        settings_obj = SettingsDictModule()
        for key, value in settings_dict.items():
            setattr(settings_obj, key.upper(), value)
        self.use_settings(settings_obj)
43610
def from_dictionary(cls, dictionary):
        """"""
        if not isinstance(dictionary, dict):
            raise TypeError('dictionary has to be a dict type, got: {}'.format(type(dictionary)))

        return cls(dictionary)
1039791
def from_object(updates):
    ""
    import sys
    config = sys.modules[__name__]
    
    prefix = config.__name__.split('.')[0].upper()
    keys = [k for k in config.__dict__ if \
        k != from_object.__name__ and not k.startswith('_')]
    get_value = lambda c, k: hasattr(c, k) and getattr(c, k) or None
    for key in keys:
        prefix_key = '%s_%s' % (prefix, key)
        value = get_value(updates, prefix_key) or get_value(updates, key)
        if value: setattr(config, key, value)
587550
def from_dict(cls, d):
        
        instance = super(Simulation, cls).from_dict(d)
        #  The instance's input_files and cmd_line_args members still point to data structures in the original
        #  dictionary.  Copy them to avoid surprises if they are changed in the original dictionary.
        instance.input_files = dict(instance.input_files)
        instance.cmd_line_args = list(instance.cmd_line_args)
        return instance
791606
def create_from_dictionary(self, datas):
        
        configuration = ObjectConfiguration()

        if "uri" in datas:
            configuration.uri = str(datas["uri"])
        if "title" in datas:
            configuration.title = str(datas["title"])
        if "description" in datas:
            configuration.description = str(datas["description"])

        return configuration