Commit 99755692 authored by Yuya Nishihara's avatar Yuya Nishihara

wconfig: translate ParsingError of iniparse to error.ParseError (refs #1512)

Because wconfig is a kind of Mercurial's config object, it should hide
iniparse behavior.

With this change, ParsingError can be caught at global exception handler.

--HG--
branch : stable
parent 67c50247f6ee
......@@ -2,7 +2,7 @@ import os, tempfile, shutil
from nose.tools import *
from nose.plugins.skip import SkipTest
from StringIO import StringIO
from mercurial import config
from mercurial import config, error
from tortoisehg.util import wconfig
def setup():
......@@ -225,6 +225,14 @@ def check_read_write():
c.read(path='foo', fp=StringIO(s))
assert_equals(s, written(c).rstrip())
@with_wconfig
@raises(error.ParseError)
def check_read_write_parse_error():
c = newwconfig()
s = 'bar = baz' # missing header
c.read(path='foo', fp=StringIO(s))
c.write(StringIO())
@with_wconfig
def check_write_after_dict_setitem():
c = newwconfig({'foo.bar': 'x'})
......
......@@ -7,7 +7,8 @@
import os
import cStringIO
from mercurial import util, config as config_mod
import ConfigParser
from mercurial import error, util, config as config_mod
try:
from iniparse import INIConfig
......@@ -178,8 +179,12 @@ class _wconfig(object):
raise NotImplementedError("wconfig does not support read() more than once")
def newini(fp=None):
# TODO: optionxformvalue isn't used by INIConfig ?
return INIConfig(fp=fp, optionxformvalue=None)
try:
# TODO: optionxformvalue isn't used by INIConfig ?
return INIConfig(fp=fp, optionxformvalue=None)
except ConfigParser.ParsingError, err:
raise error.ParseError(err.message.splitlines()[0],
'%s:%d' % (err.filename, err.lineno))
if not self._readfiles:
return newini()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment