Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lines storing #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/configobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,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 @@ -520,7 +521,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 @@ -577,7 +578,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 @@ -588,6 +590,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 @@ -1029,6 +1033,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 @@ -1602,6 +1607,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 ({!r}) (matched as neither section nor keyword)'.format(line),
Expand Down Expand Up @@ -1665,7 +1671,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