Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Unable to use imports inside Name Sets #129

Closed
amyasnikov opened this issue Oct 7, 2024 Discussed in #128 · 0 comments · Fixed by #130
Closed

Bug: Unable to use imports inside Name Sets #129

amyasnikov opened this issue Oct 7, 2024 Discussed in #128 · 0 comments · Fixed by #130

Comments

@amyasnikov
Copy link
Owner

Discussed in #128

Originally posted by aascedu October 7, 2024
Hello Anton, hello everyone,

I am trying to use name sets to help with complience tests.
I want to use the re module.

import re

def find_deny_rule(device, target):
    normalized_target = re.sub(r'\s+', ' ', target).strip()
    
    for rule in device.config["access-lists"]["98"]["rules"]:
        if "source" in rule and "mode" in rule:
            normalized_rule = re.sub(r'\s+', ' ', rule).strip()
            if normalized_rule == normalized_target:
                return True
    return False

__all__ = ['find_deny_rule', 're']

Is not allowed in the GUI since the import re is not a from-import.
However how do I import the module re then ? I tried this then :

from re import sub

def find_deny_rule(device, target):
    normalized_target = sub(r'\s+', ' ', target).strip()
    
    for rule in device.config["access-lists"]["98"]["rules"]:
        if "source" in rule and "mode" in rule:
            normalized_rule = sub(r'\s+', ' ', rule).strip()
            if normalized_rule == normalized_target:
                return True
    return False

__all__ = ['find_deny_rule', 'sub']

And I get this error : NameError: name 'sub' is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant