Expand hazardlib source attribute (defined through list of values)
    into dictionary of shapefile parameters.
515723
def expand_src_param(values, shp_params):
    
    if values is None:
        return dict([(key, None) for key, _ in shp_params])
    else:
        num_values = len(values)
        return dict(
            [(key, float(values[i]) if i < num_values else None)
                for i, (key, _) in enumerate(shp_params)])
583245
def extend(self, *args, **kwargs):
        """"""
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))

        iterable = args[0] if args else None
        if iterable:
            if isinstance(iterable, Mapping) or hasattr(iterable, 'items'):
                for key, value in iterable.items():
                    self.append(key, value)
            elif hasattr(iterable, 'keys'):
                for key in iterable.keys():
                    self.append(key, iterable[key])
            else:
                for key, value in iterable:
                    self.append(key, value)

        for key, value in kwargs.items():
            self.append(key, value)
1291059
def convert_values(args_list):
    
    rate_map = get_rates(map(itemgetter(1, 2), args_list))
    value_map = {}
    for value, source, target in args_list:
        args = (value, source, target)
        if source == target:
            value_map[args] = value
        else:
            value_map[args] = value * rate_map[(source, target)]

    return value_map
142356
def load_parameters(self, source):
        """"""
        with open(source) as parameters_source:
            loaded = yaml.safe_load(parameters_source.read())
            for k, v in loaded.items():
                if isinstance(v, str):
                    loaded[k] = "'"+v+"'"
            return loaded
902278
def _pys2attributes(self, line):
        """"""

        splitline = self._split_tidy(line)

        selection_data = map(ast.literal_eval, splitline[:5])
        selection = Selection(*selection_data)

        tab = int(splitline[5])

        attrs = {}
        for col, ele in enumerate(splitline[6:]):
            if not (col % 2):
                # Odd entries are keys
                key = ast.literal_eval(ele)

            else:
                # Even cols are values
                attrs[key] = ast.literal_eval(ele)

        self.code_array.cell_attributes.append((selection, tab, attrs))
622203
def _ProcessGrepSource(self, source):
    """"""
    attributes = source.base_source.attributes
    paths = artifact_utils.InterpolateListKbAttributes(
        attributes["paths"], self.knowledge_base,
        self.ignore_interpolation_errors)
    regex = utils.RegexListDisjunction(attributes["content_regex_list"])
    condition = rdf_file_finder.FileFinderCondition.ContentsRegexMatch(
        regex=regex, mode="ALL_HITS")
    file_finder_action = rdf_file_finder.FileFinderAction.Stat()
    request = rdf_file_finder.FileFinderArgs(
        paths=paths,
        action=file_finder_action,
        conditions=[condition],
        follow_links=True)
    action = file_finder.FileFinderOSFromClient

    yield action, request
298697
def add_attrs(self, symbol, **kwargs):
        
        for key, val in kwargs.items():
            symbol.add_extension_attribute(self.extension_name, key, val)
464811
def extract_source_params(src):
    
    tags = get_taglist(src)
    data = []
    for key, param, vtype in BASE_PARAMS:
        if key in src.attrib:
            if vtype == "c":
                data.append((param, src.attrib[key]))
            elif vtype == "f":
                data.append((param, float(src.attrib[key])))
            else:
                data.append((param, None))
        elif key in tags:
            if vtype == "c":
                data.append((param, src.nodes[tags.index(key)].text))
            elif vtype == "f":
                data.append((param, float(src.nodes[tags.index(key)].text)))
            else:
                data.append((param, None))
        else:
            data.append((param, None))
    return dict(data)
1104105
def map(cls, sources, *, transform_args=None):
    
    for idx, source in enumerate(sources):
      try:
        yield cls.create(source, transform_args=transform_args)
      except Exception as ex:
        raise Exception("An error occurred with item {0}".format(idx)) from ex
659523
def prefix_list(self, prefix, values):
        
        return list(map(lambda value: prefix + " " + value, values))
824125
def loads( source ):
    
    source = source.strip()
    assert source.startswith( '{' )
    assert source.endswith( '}' )
    source = source[1:-1]
    result = {}
    for match in attr.finditer( source ):
        key = match.group('key')
        if match.group( 'list' ) is not None:
            value = [ 
                int(x) 
                for x in match.group( 'list' ).strip().replace(',',' ').split() 
            ]
        elif match.group( 'int' ) is not None:
            value = int( match.group( 'int' ))
        elif match.group( 'string' ) is not None:
            def deescape( match ):
                return unichr( int( match.group(0)[2:], 16 ))
            value = match.group('string').decode( 'utf-8' )
            value = escape.sub( 
                deescape,
                value,
            )
            value = simple_escape.sub(
                lambda x: x.group(1),
                value,
            )
        else:
            raise RuntimeError( "Matched something we don't know how to process:", match.groupdict() )
        result[key] = value
    return result
643492
def expand_models(self, target, data):
        
        if isinstance(data, dict):
            data = data.values()
        for chunk in data:
            if target in chunk:
                yield self.init_target_object(target, chunk)
            else:
                for key, item in chunk.items():
                    yield self.init_single_object(key, item)
1130774
def concatenate_fields(fields, dim):
    ''
    if len(fields) == 0:
        raise ValueError('fields cannot be an empty list')
    
    if len(set((f.name, f.shape, f.dtype) for f in fields)) != 1:
        raise ValueError('fields should have homogeneous name, shape and dtype')
    tpl = fields[0]
    attr = InstanceAttribute(tpl.name, shape=tpl.shape, dtype=tpl.dtype, 
                             dim=dim, alias=None)
    
    attr.value = np.array([f.value for f in fields], dtype=tpl.dtype)
    return attr
539497
def source_attr(attr_name):
    

    def source_attr(_value, context, **_params):
        value = getattr(context["model"].source, attr_name)
        return _attr(value)

    return source_attr
1098459
def extend(self, attributes, prefix):
        

        self._contents += [Attribute(attr, prefix) for attr in attributes]
1241331
def _extract_parameters_from_properties(properties):
    """"""
    new_properties = {}
    parameters = []
    for key, value in six.iteritems(properties):
        if key.startswith(_PARAMETER_PREFIX):
            parameters.append((key.replace(_PARAMETER_PREFIX, ""), value))
        else:
            new_properties[key] = value

    return new_properties, sorted(parameters)
288992
def _add_source(model):
    
    ignored_keys = {"author_tags", "original_xml", "additional_info"}

    # convert all values to source strings
    source = "Aleph"
    for key, val in model.get_mapping().iteritems():
        if key in ignored_keys:
            continue

        if type(val) in [list, tuple]:
            ss_val = [
                SourceString(item, source).to_dict()
                for item in val
            ]
        else:
            ss_val = [SourceString(val, source).to_dict()]

        setattr(model, key, ss_val)

    return model