Comments (9)
_reassign_linenums
also using the enumeration method to re-assign line numbers. I guess it could be said that after the initial parsing is done that you could call _reassign_linenums
but that seem bruteforce-ish. Would seem more logical to handle that in the insert/append functions?
from ciscoconfparse.
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
from ciscoconfparse.
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 factory
option)?
from ciscoconfparse.
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 (wc -l
)
from ciscoconfparse.
https://gist.github.com/CrackerJackMack/409b6b2f9e0f0caf0ced
make sure you download the raw as those spaces can be gobbled up in copy and paste
from ciscoconfparse.
Great bug report; thank you. This problem was introduced when I re-wrote the library in 0.9.x... then, I added the explicit ignore_blank_lines
option to resolve the concern in PR #3 (but the problem already seemed to exist at that time). BTW, your gist mentioned that loopback1's ipv6 address is missed; I'm not sure if you realized it, but loopback2's ipv4 address is broken too.
Your proposed modifications to iter_with_comments()
and iter_no_comments()
passes unit tests, but I'd like to take some time to consider the best way to fix this. The actual problem is that child assignments to parent objects break in the config you provided; specifically the second child never gets assigned to the parent, even if the first child is a comment. The problem seems to be triggered if there are two blank lines before a parent line.
I'm including a minimal, complete example to reproduce the problem in this bug report...
import os
from ciscoconfparse import CiscoConfParse
config = """!
!
router ospf
area 0
!
router isis
net 10.10.10.10.10
address-family ipv4 unicast
default-metric 10
exit-address-family
!
interface loopback 1
ip address 192.168.0.1/32
ipv6 address fe80::30/128
ipv6 enable
ipv6 router isis
!! BUG The "ipv6 address" line never has a parent assigned to it.
!! This problem happens for every 2nd child of a parent, if the config has two balnk
!! lines before the parent
!
interface loopback 2
port-name brocade config example
ip address 192.168.1.1/32
!! BUG The "ip address" line never has a parent assigned to it.
!
!
end
"""
cfg_list = config.split(os.linesep)
broken = CiscoConfParse(cfg_list, ignore_blank_lines=True)
for obj in broken.ConfigObjs:
print obj
from ciscoconfparse.
I just pushed 1.1.24, which should fix the problem. Can you test on your side and confirm?
from ciscoconfparse.
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 CiscoConfParse('/path/to/config', syntax='asa', factory=True)
... reduced a 20k-line ASA config parse from two minutes, forty seconds in 1.1.24, to 0.65 second in 1.2.0.
from ciscoconfparse.
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.
from ciscoconfparse.
Related Issues (20)
- "make pypi" should add the ciscoconfparse version tag before package upload HOT 1
- [Bug]: Terraform handling is broken HOT 1
- [Bug]: Remove `assert isinstance()` statements which are validating method input types HOT 2
- [Bug]: bad function argument + infinite recursion problem HOT 2
- [Bug]: Remove duplicated code from `CiscoConfParse()._bootstrap_from_text()` HOT 1
- [Bug]: Remove duplicated obj init code from CiscoConfParse()._bootstrap_obj_init_foo() HOT 1
- [Bug]: CiscoConfParse versions affecting threading HOT 8
- [Bug]: calculate_line_id() does not hash comments / whitespace HOT 1
- [Bug]: Failing to import CiscoConfParse on Read-Only File Systems such as AWS Lambda HOT 9
- [Bug]: The banner value was not parsed correctly in the Arista config file HOT 3
- Considering dual-license as GPLv3 and Apache2.0 HOT 1
- Github automated unit test failures (Python3.10) HOT 1
- [Bug]: IOSIntfLine object incorrectly parses an interface description containing a single character HOT 3
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 HOT 2
- [Bug]: CiscoConfParse cannot import dnspython during Github Automated test runs. HOT 2
- [Bug]: ModuleNotFoundError: No module named 'deprecat' HOT 1
- [Bug]: ModuleNotFoundError: No module named 'deprecat' persists on python 3.6 HOT 2
- Versions 1.7.21-1.7.23 are broken and should be yanked HOT 9
- [Feature]: IOS-XR Route-policy processed incorrectly HOT 4
- [Bug]: Seeing double entries on sync_diff() and order of negation reversed HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ciscoconfparse.