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

Incorrect handling of multiline strings in MIB files during conversion to Python #463

Open
vyual opened this issue Sep 7, 2024 · 2 comments

Comments

@vyual
Copy link

vyual commented Sep 7, 2024

PySNMP incorrectly processes multiline strings when converting MIB files to Python scripts. This results in a SyntaxError due to unterminated string literals in the generated Python file.

Specifically, when a MIB file contains a multiline string (common in fields like CONTACT-INFO), the generated Python script fails to properly format these strings, leading to syntax errors when the script is executed.

Example of problematic MIB content:

CONTACT-INFO
    "Company
    company.com

    Postal: Company.
    123123 City
    Street
    Country

    Phone: +1 123 123 12 12
    EMail: [email protected]"

This results in a SyntaxError in the generated Python file:

SyntaxError: unterminated string literal (detected at line 15)

Expected behavior:
The multiline strings in MIB files should be correctly converted to valid Python multiline strings or concatenated string literals.

Actual behavior:
The conversion process results in invalid Python syntax, causing errors when attempting to use the generated Python modules.

This issue significantly impacts the usability of PySNMP for parsing and working with MIB files containing multiline strings.

@vyual
Copy link
Author

vyual commented Sep 7, 2024

maybe we need to add a call code somewhere

def preprocess_mib(file_path):
    with open(file_path, "r") as file:
        content = file.read()

    # change multiline to oneline
    content = re.sub(r'"\s*\n\s*"', " ", content)
    with open(file_path, "w") as file:
        file.write(content)

@lextm
Copy link

lextm commented Sep 7, 2024

  1. This is only related to PySMI, not PySNMP.
  2. Which version of PySMI are you talking about?

Please read #429 to see why this repo is no longer in use.

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

No branches or pull requests

2 participants