Skip to content

Commit 02b6206

Browse files
KOLANICHdfgdsgfd
authored andcommitted
Added lines storing
1 parent 9b9df87 commit 02b6206

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/configobj/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ def _initialise(self):
472472
self.default_values = {}
473473
self.extra_values = []
474474
self._created = False
475+
# for lines
476+
self.lines = {}
475477

476478

477479
def _interpolate(self, key, value):
@@ -514,7 +516,7 @@ def _check(entry):
514516
return val
515517

516518

517-
def __setitem__(self, key, value, unrepr=False):
519+
def __setitem__(self, key, value, unrepr=False, lines=None):
518520
"""
519521
Correctly set a value.
520522
@@ -571,7 +573,8 @@ def __setitem__(self, key, value, unrepr=False):
571573
else:
572574
raise TypeError('Value is not a string "%s".' % value)
573575
dict.__setitem__(self, key, value)
574-
576+
if(lines != None):
577+
self.lines[key]=lines
575578

576579
def __delitem__(self, key):
577580
"""Remove items from the sequence when deleting."""
@@ -582,6 +585,7 @@ def __delitem__(self, key):
582585
self.sections.remove(key)
583586
del self.comments[key]
584587
del self.inline_comments[key]
588+
del self.lines[key]
585589

586590

587591
def get(self, key, default=None):
@@ -1591,6 +1595,7 @@ def _parse(self, infile):
15911595
# it's not a section marker,
15921596
# so it should be a valid ``key = value`` line
15931597
mat = self._keyword.match(line)
1598+
start_line=cur_index
15941599
if mat is None:
15951600
self._handle_error(
15961601
'Invalid line ({0!r}) (matched as neither section nor keyword)'.format(line),
@@ -1654,7 +1659,7 @@ def _parse(self, infile):
16541659
# add the key.
16551660
# we set unrepr because if we have got this far we will never
16561661
# be creating a new section
1657-
this_section.__setitem__(key, value, unrepr=True)
1662+
this_section.__setitem__(key, value, unrepr=True, lines=(start_line,cur_index))
16581663
this_section.inline_comments[key] = comment
16591664
this_section.comments[key] = comment_list
16601665
continue

0 commit comments

Comments
 (0)