Skip to content

Commit

Permalink
Added lines storing
Browse files Browse the repository at this point in the history
  • Loading branch information
KOLANICH authored and dfgdsgfd committed Dec 26, 2016
1 parent 9b9df87 commit 02b6206
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/configobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ def _initialise(self):
self.default_values = {}
self.extra_values = []
self._created = False
# for lines
self.lines = {}


def _interpolate(self, key, value):
Expand Down Expand Up @@ -514,7 +516,7 @@ def _check(entry):
return val


def __setitem__(self, key, value, unrepr=False):
def __setitem__(self, key, value, unrepr=False, lines=None):
"""
Correctly set a value.
Expand Down Expand Up @@ -571,7 +573,8 @@ def __setitem__(self, key, value, unrepr=False):
else:
raise TypeError('Value is not a string "%s".' % value)
dict.__setitem__(self, key, value)

if(lines != None):
self.lines[key]=lines

def __delitem__(self, key):
"""Remove items from the sequence when deleting."""
Expand All @@ -582,6 +585,7 @@ def __delitem__(self, key):
self.sections.remove(key)
del self.comments[key]
del self.inline_comments[key]
del self.lines[key]


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

0 comments on commit 02b6206

Please sign in to comment.