-
Notifications
You must be signed in to change notification settings - Fork 221
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
Config parsing breaks with ignore_blank_lines=True
(object parent assignments are missed)
#13
Comments
|
This seems to fix it for my use case (without changing the default) but could be breaking a public API. /me shrugs def iter_with_comments(self, begin_index=0):
- for idx, obj in enumerate(self._list):
- if (idx>=begin_index):
+ for obj in self._list:
+ if obj.linenum >= begin_index:
yield obj
def iter_no_comments(self, begin_index=0):
- for idx, obj in enumerate(self._list):
- if (idx>=begin_index) and (not obj.is_comment):
+ for obj in self._list:
+ if obj.linenum >= begin_index and not obj.is_comment:
yield obj
|
Hi Kevin, please add an example config which shows how status quo is broken; perhaps the best way to do this is as a python triple-quoted string. Also include how you are parsing (i.e. with the |
I was using all defaults on ciscoconfparse==1.1.23 passing in the filename as config. I'm trying to sanitize a reproducible config, this one is 4101 lines long ( |
https://gist.github.com/CrackerJackMack/409b6b2f9e0f0caf0ced make sure you download the raw as those spaces can be gobbled up in copy and paste |
ignore_blank_lines=True
(object parent assignments are missed)
Great bug report; thank you. This problem was introduced when I re-wrote the library in 0.9.x... then, I added the explicit Your proposed modifications to I'm including a minimal, complete example to reproduce the problem in this bug report...
|
I just pushed 1.1.24, which should fix the problem. Can you test on your side and confirm? |
FYI... I also pushed 1.2.0 this morning, which includes optimizations giving me between 25% and 24,000% parsing speed improvement (depending on python version and the type of configs)... if you have Cisco ASAs, it goes into beast-mode when you parse as |
I updated to 1.2.1 as you asked and removed all but the config filename. Noticed not only the huge speedups but my original issue has been fixed as well. Thanks for working on this! This project has really been a life saver. |
I was struggling with an issue for a good while today why the first line of every section of my config was being truncated. Turns out it's really a fatal flaw in many of the routines. In many places there is
for idx, obj in enumerate(self._list):
where it is expected thatidx == obj.linenum
. Especially during__init__
. I say this because many functions calliter_with_comments
oriter_no_comments
and pass inobj.linenum
as the thebegin_index
parameter. Thus creating the relationship between list index and the config line number.I'm submitting this as an issue instead of a pull request directly since I'm not sure of the intended use of the
iter_*_comments
functions (they are public api). So it is a conundrum on fixing this issue. Wasn't sure the best way to go about fixing it, but am willing to do so with some guidance on the matter.The text was updated successfully, but these errors were encountered: