Skip to content

Commit

Permalink
Added storing of lines numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
KOLANICH committed Feb 17, 2018
1 parent e36c7b4 commit c2e1c47
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/configobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def _initialise(self):
self.default_values = {}
self.extra_values = []
self._created = False
self.source_map = {}


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


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

if line_range:
self.source_map[key] = line_range

def __delitem__(self, key):
"""Remove items from the sequence when deleting."""
Expand All @@ -582,6 +584,8 @@ def __delitem__(self, key):
self.sections.remove(key)
del self.comments[key]
del self.inline_comments[key]
if key in self.source_map:
del self.source_map[key]


def get(self, key, default=None):
Expand Down Expand Up @@ -1023,6 +1027,7 @@ def restore_defaults(self):
self[section].restore_defaults()



def _get_triple_quote(value):
"""Helper for triple-quoting round-trips."""
if ('"""' in value) and ("'''" in value):
Expand Down Expand Up @@ -1599,6 +1604,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 @@ -1662,7 +1668,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, line_range=(start_line, cur_index))
this_section.inline_comments[key] = comment
this_section.comments[key] = comment_list
continue
Expand Down

0 comments on commit c2e1c47

Please sign in to comment.