Skip to content

Commit

Permalink
Added lines numbers storing
Browse files Browse the repository at this point in the history
  • Loading branch information
KOLANICH committed Feb 17, 2018
1 parent 7a0f1e0 commit 0689f60
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 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,7 @@ def __delitem__(self, key):
self.sections.remove(key)
del self.comments[key]
del self.inline_comments[key]
del self.source_map[key]


def get(self, key, default=None):
Expand Down Expand Up @@ -1031,6 +1034,14 @@ def _get_triple_quote(value):
return tsquot if "'''" in value else tdquot


def _get_triple_quote(value):
"""Helper for triple-quoting round-trips."""
if ('"""' in value) and ("'''" in value):
raise ConfigObjError('Value cannot be safely quoted: {0!r}'.format(value))

return tsquot if "'''" in value else tdquot


class ConfigObj(Section):
"""An object to read, create, and write config files."""

Expand Down Expand Up @@ -1599,6 +1610,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 +1674,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 Expand Up @@ -2448,3 +2460,4 @@ def get_extra_values(conf, _prepend=()):


"""*A programming language is a medium of expression.* - Paul Graham"""
ium of expression.* - Paul Graham"""

0 comments on commit 0689f60

Please sign in to comment.