Пример #1
0
def _ast_convert_call(call_ast):
    # type: (ast.Call) -> SNMPDetectSpec
    if isinstance(call_ast.func, ast.Name):
        if call_ast.func.id == 'bool':
            assert _is_oid_function(call_ast.args[0])
            return exists(_ast_convert_to_str(call_ast.args[0]))
        if call_ast.func.id in (
                'has_ifHCInOctets',
                'is_fsc',
                '_is_ucd',
                '_is_fsc_or_windows',
                'scan_ricoh_printer',
                'is_netapp_filer',
                '_has_table_2',
                '_is_cisco',
                '_is_cisco_nexus',
        ):
            return _explicit_conversions(call_ast.func.id)

        if call_ast.func.id in (
                'if64_disabled',
                'scan_f5_bigip_cluster_status_pre_11_2',
                'scan_f5_bigip_cluster_status_11_2_upwards',
                'scan_cisco_mem_asa64',
        ):
            raise NotImplementedError(call_ast.func.id)

    if isinstance(call_ast.func, ast.Attribute):
        assert _is_oid_function(call_ast.func.value)
        assert len(call_ast.args) == 1
        if call_ast.func.attr == 'startswith':
            return startswith(
                _ast_convert_to_str(call_ast.func.value),
                _ast_convert_to_str(call_ast.args[0]),
            )
        if call_ast.func.attr == 'endswith':
            return endswith(
                _ast_convert_to_str(call_ast.func.value),
                _ast_convert_to_str(call_ast.args[0]),
            )
        if isinstance(call_ast.func.value,
                      ast.Name) and call_ast.func.value.id == 're':
            assert call_ast.func.attr == 'match'
            raise NotImplementedError("regular expression")

    if _is_oid_function(call_ast):
        return exists(_ast_convert_to_str(call_ast))

    raise ValueError(ast.dump(call_ast))
Пример #2
0
def _ast_convert_call(call_ast: ast.Call) -> SNMPDetectSpecification:
    if isinstance(call_ast.func, ast.Name):
        if call_ast.func.id == "bool":
            assert _is_oid_function(call_ast.args[0])
            return exists(_ast_convert_to_str(call_ast.args[0]))
        if call_ast.func.id in (
                "is_fsc",
                "_is_ucd",
                "_is_fsc_or_windows",
                "scan_ricoh_printer",
                "is_netapp_filer",
                "_has_table_2",
                "_is_cisco",
                "_is_cisco_nexus",
        ):
            return _explicit_conversions(call_ast.func.id)

        if call_ast.func.id in (
                "scan_f5_bigip_cluster_status_pre_11_2",
                "scan_f5_bigip_cluster_status_11_2_upwards",
                "scan_cisco_mem_asa64",
        ):
            raise NotImplementedError(call_ast.func.id)

    if isinstance(call_ast.func, ast.Attribute):
        assert _is_oid_function(call_ast.func.value)
        assert len(call_ast.args) == 1
        if call_ast.func.attr == "startswith":
            return startswith(
                _ast_convert_to_str(call_ast.func.value),
                _ast_convert_to_str(call_ast.args[0]),
            )
        if call_ast.func.attr == "endswith":
            return endswith(
                _ast_convert_to_str(call_ast.func.value),
                _ast_convert_to_str(call_ast.args[0]),
            )
        if isinstance(call_ast.func.value,
                      ast.Name) and call_ast.func.value.id == "re":
            assert call_ast.func.attr == "match"
            raise NotImplementedError("regular expression")

    if _is_oid_function(call_ast):
        return exists(_ast_convert_to_str(call_ast))

    raise ValueError(ast.dump(call_ast))