File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -282,10 +282,15 @@ def set_value(self, data):
282
282
else :
283
283
self .add (EmptyLine ())
284
284
285
+ def get_line_number (self ):
286
+ return self .contents [0 ].line_number if self .contents else None
287
+
285
288
name = property (get_name , set_name )
286
289
287
290
value = property (get_value , set_value )
288
291
292
+ line_number = property (get_line_number )
293
+
289
294
def __str__ (self ):
290
295
s = [x .__str__ () for x in self .contents ]
291
296
return '\n ' .join (s )
@@ -568,7 +573,6 @@ def _readfp(self, fp):
568
573
569
574
line_obj = self ._parse (line )
570
575
line_count += 1
571
-
572
576
if not cur_section and not isinstance (line_obj , (CommentLine , EmptyLine , SectionLine )):
573
577
if self ._parse_exc :
574
578
raise MissingSectionHeaderError (fname , line_count , line )
@@ -644,6 +648,9 @@ def _readfp(self, fp):
644
648
if isinstance (line_obj , EmptyLine ):
645
649
pending_empty_lines = True
646
650
651
+ if line_obj :
652
+ line_obj .line_number = line_count
653
+
647
654
self ._data .extend (pending_lines )
648
655
if line and line [- 1 ] == '\n ' :
649
656
self ._data .add (EmptyLine ())
Original file line number Diff line number Diff line change @@ -201,10 +201,15 @@ class TestIni(unittest.TestCase):
201
201
def test_basic (self ):
202
202
sio = StringIO (self .s1 )
203
203
p = ini .INIConfig (sio )
204
- self .assertEqual (str (p ), self .s1 )
205
- self .assertEqual (p ._data .find ('section1' ).find ('but' ).value , 'also me' )
206
- self .assertEqual (p ._data .find ('section1' ).find ('help' ).value , 'yourself' )
207
- self .assertEqual (p ._data .find ('section2' ).find ('just' ).value , 'kidding' )
204
+ section1_but = p ._data .find ('section1' ).find ('but' )
205
+ self .assertEqual (section1_but .value , 'also me' )
206
+ self .assertEqual (section1_but .line_number , 14 )
207
+ section1_help = p ._data .find ('section1' ).find ('help' )
208
+ self .assertEqual (section1_help .value , 'yourself' )
209
+ self .assertEqual (section1_help .line_number , 13 )
210
+ section2_just = p ._data .find ('section2' ).find ('just' )
211
+ self .assertEqual (section2_just .value , 'kidding' )
212
+ self .assertEqual (section2_just .line_number , 10 )
208
213
209
214
itr = p ._data .finditer ('section1' )
210
215
v = next (itr )
You can’t perform that action at this time.
0 commit comments