-
Notifications
You must be signed in to change notification settings - Fork 0
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
The consistency of string during each process may not be well-concerned. #3
Labels
invalid
This doesn't seem right
Comments
That's almost the same as the original string, but the double quotes around policy 168 became single quotes. It's acceptable though. But when it comes to lines[10]
|
This one may work, but we need to test more.
Output:
|
thejimmylin
added
enhancement
New feature or request
invalid
This doesn't seem right
and removed
enhancement
New feature or request
labels
Aug 6, 2020
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider a Fortigate config like
(This is a .conf, like a plain text file)
Say the file is living in /conf/, named firewall_policy.conf.
We want to get it into python so then we can do all the data-processing things around it, So we do
Now, let's look deeper into it.
We'll want something like
If we simply use
Then we will get
Obviously that is not we want.
If we try shlex — Simple lexical analysis, a module in The Python Standard Library
Then we will get
That's great, and we can join them back together by
That's almost the same as the original string, but the double quotes around policy 168 became single quotes. It's acceptable though.
But when it comes to lines[10]
The double quotes just disappear, because ALL is not a string containing space, and shlex doesn't think it is needed to add quotes around it.
I looked up the shlex documentation and it is a parameter called posix to use with.
And we can simply use the built-in join to turn it back.
But when it comes to lines[11], that is not the case.
I think that is the different way of parsing a string between Forti devices and the shlex module.
Forti device is seeing something like
set comments ""customer": "Jimmy Lin""
and shlex is seeing something like
If we use .replace('\"', '''), it will seem better
But this is a dirty way, if there are more escape characters or more complicated nested things, I think it may fail, and the join part also not correct
Is there a solution to make these parsing process correct and clean.
Am I missing something?
The text was updated successfully, but these errors were encountered: