Retrieve all QGIS Expressions provided by InaSAFE.

    :return: Dictionary of expression name and the expression itself.
    :rtype: dict
974117
def qgis_expressions():
    
    all_expressions = {
        fct[0]: fct[1] for fct in getmembers(generic_expressions)
        if fct[1].__class__.__name__ == 'QgsExpressionFunction'}
    all_expressions.update({
        fct[0]: fct[1] for fct in getmembers(infographic)
        if fct[1].__class__.__name__ == 'QgsExpressionFunction'})
    all_expressions.update({
        fct[0]: fct[1] for fct in getmembers(map_report)
        if fct[1].__class__.__name__ == 'QgsExpressionFunction'})
    all_expressions.update({
        fct[0]: fct[1] for fct in getmembers(html_report)
        if fct[1].__class__.__name__ == 'QgsExpressionFunction'})
    return all_expressions
145719
def _config(self) -> ExtensionConfig:
        
        return dict(pattern=self.__pattern__, search_in_keys=True, search_in_values=False)
1120817
def root_directory(self):
        
        if not QgsApplication.qgisSettingsDirPath() or (
                QgsApplication.qgisSettingsDirPath() == ''):
            self._root_directory = None
        else:
            # noinspection PyArgumentList
            self._root_directory = os.path.join(
                QgsApplication.qgisSettingsDirPath(),
                'inasafe')

        return self._root_directory
653845
def find_abbreviations(self, kwargs):
        
        new_kwargs = []
        try:
            sig = self.signature()
        except (ValueError, TypeError):
            # can't inspect, no info from function; only use kwargs
            return [ (key, value, value) for key, value in kwargs.items() ]

        for param in sig.parameters.values():
            for name, value, default in _yield_abbreviations_for_parameter(param, kwargs):
                if value is empty:
                    raise ValueError('cannot find widget or abbreviation for argument: {!r}'.format(name))
                new_kwargs.append((name, value, default))
        return new_kwargs
1121794
def expr(self, items):
        
        return Expression({(self, name): value for name, value in items})
809978
def get_all(self):
        
        with mutex:
            items = self.values.items()

        result = []
        for k, v in items:
            # Check if is a single value dict (custom empty key)
            if not k or k == MetricDict.EMPTY_KEY:
                key = None
            else:
                key = decoder.decode(k)
            result.append((key, self.get(k)))

        return result
518058
def translate(self):
        
        expressions = []
        varnames = set()
        funcnames = set()
        for part in self.parts:
            if isinstance(part, str):
                expressions.append(ex_literal(part))
            else:
                e, v, f = part.translate()
                expressions.extend(e)
                varnames.update(v)
                funcnames.update(f)
        return expressions, varnames, funcnames
1225693
def get_context(self, arr, expr, context):
        

        expression_names = [x for x in self.get_expression_names(expr) if x not in set(context.keys()).union(['i'])]

        if len(expression_names) != 1:
            raise ValueError('The expression must have exactly one variable.')

        return {expression_names[0]: arr}
950603
def get_filter_list(p_expression):
    
    result = []
    for arg in p_expression:
        # when a word starts with -, it should be negated
        is_negated = len(arg) > 1 and arg[0] == '-'
        arg = arg[1:] if is_negated else arg

        argfilter = None
        for match, _filter in MATCHES:
            if re.match(match, arg):
                argfilter = _filter(arg)
                break

        if not argfilter:
            argfilter = GrepFilter(arg)

        if is_negated:
            argfilter = NegationFilter(argfilter)

        result.append(argfilter)

    return result
330329
def get_symbols_list(self):
        ''''''
        slist = []
        rc, nSymb, nElem = gdxcc.gdxSystemInfo(self.gdx_handle)
        assert rc, 'Unable to retrieve "%s" info' % self.filename
        self.number_symbols = nSymb
        self.number_elements = nElem
        slist = [None]*(nSymb+1)
        for j in range(0,nSymb+1):
            sinfo = self.get_sid_info(j)
            if j==0:
                sinfo['name'] = 'universal_set'
            slist[j] = GdxSymb(self,sinfo)
        return slist
646339
def clean_inasafe_fields(layer):
    
    fields = []
    # Exposure
    if layer.keywords['layer_purpose'] == layer_purpose_exposure['key']:
        fields = get_fields(
            layer.keywords['layer_purpose'], layer.keywords['exposure'])

    # Hazard
    elif layer.keywords['layer_purpose'] == layer_purpose_hazard['key']:
        fields = get_fields(
            layer.keywords['layer_purpose'], layer.keywords['hazard'])

    # Aggregation
    elif layer.keywords['layer_purpose'] == layer_purpose_aggregation['key']:
        fields = get_fields(
            layer.keywords['layer_purpose'])

    # Add displaced_field definition to expected_fields
    # for minimum needs calculator.
    # If there is no displaced_field keyword, then pass
    try:
        if layer.keywords['inasafe_fields'][displaced_field['key']]:
            fields.append(displaced_field)
    except KeyError:
        pass

    expected_fields = {field['key']: field['field_name'] for field in fields}

    # Convert the field name and sum up if needed
    new_keywords = {}
    for key, val in list(layer.keywords.get('inasafe_fields').items()):
        if key in expected_fields:
            if isinstance(val, str):
                val = [val]
            sum_fields(layer, key, val)
            new_keywords[key] = expected_fields[key]

    # Houra, InaSAFE keywords match our concepts !
    layer.keywords['inasafe_fields'].update(new_keywords)

    to_remove = []
    # Remove unnecessary fields (the one that is not in the inasafe_fields)
    for field in layer.fields().toList():
        if field.name() not in list(layer.keywords['inasafe_fields'].values()):
            to_remove.append(field.name())
    remove_fields(layer, to_remove)
    LOGGER.debug(
        'Fields which have been removed from %s : %s'
        % (layer.keywords['layer_purpose'], ' '.join(to_remove)))
774204
def _get_expr_variables(expression: z3.ExprRef) -> List[z3.ExprRef]:
    
    result = []
    if not expression.children() and not isinstance(expression, z3.BitVecNumRef):
        result.append(expression)
    for child in expression.children():
        c_children = _get_expr_variables(child)
        result.extend(c_children)
    return result
676778
def _all(self, *args, **kwargs):
        '''
        
        '''
        data = dict()
        data['software'] = self._software(**kwargs)
        data['system'] = self._system(**kwargs)
        data['services'] = self._services(**kwargs)
        try:
            data['configuration'] = self._configuration(**kwargs)
        except InspectorQueryException as ex:
            data['configuration'] = 'N/A'
            log.error(ex)
        data['payload'] = self._payload(**kwargs) or 'N/A'

        return data
725223
def get_expr(self, ctx):
        
        varname = ctx.lookup_variable(self.varname)
        if varname is None:
            val = ctx.lookup_constant(self.varname)
            if val:
                try:
                    return val.generate_code(ctx)
                except AttributeError:
                    return val
            raise MuvError(
                "Undeclared identifier '%s'." % self.varname,
                position=self.position
            )
        if len(self.indexing) == 0:
            return "{var} @".format(
                var=varname,
            )
        if len(self.indexing) == 1:
            return "{var} @ {idx} []".format(
                var=varname,
                idx=self.indexing[0],
            )
        return (
            "{var} @ {{ {idx} }}list array_nested_get".format(
                var=varname,
                idx=" ".join(str(x) for x in self.indexing),
            )
        )
323690
def fill_hazard_class(layer):
    
    hazard_field = layer.keywords['inasafe_fields'][hazard_class_field['key']]

    expression = '"%s" is NULL OR  "%s" = \'\'' % (hazard_field, hazard_field)
    index = layer.fields().lookupField(hazard_field)
    request = QgsFeatureRequest().setFilterExpression(expression)
    layer.startEditing()

    for feature in layer.getFeatures(request):
        layer.changeAttributeValue(
            feature.id(),
            index,
            not_exposed_class['key'])
    layer.commitChanges()

    return layer
1329169
def get_regex_strings(self, regular_expressions):
        
        str_list = []
        if regular_expressions.count is None:
            return None
        for i in self.get_strings():
            if re.match(regular_expressions, i):
                str_list.append(i)
        return str_list
1062571
def notation(self):
        
        return dict((nd.name, nd.value) for nd in self._signature.subpackets['NotationData'])