Skip to content

Commit

Permalink
Merge branch 'release/0.19.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Feb 27, 2017
2 parents 267791f + 90ea110 commit 6765a09
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
COMPLEX_SEARCH_CAPABILITY = "complex_search"
SERVER_CAPABILITIES = [COMPLEX_SEARCH_CAPABILITY, ]

__version__ = '0.19.2'
__version__ = '0.19.3'
3 changes: 2 additions & 1 deletion conans/model/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def create(settings, options, requires, indirect_requires, non_devs_requirements
@staticmethod
def loads(text):
parser = ConfigParser(text, ["settings", "full_settings", "options", "full_options",
"requires", "full_requires", "scope", "recipe_hash"])
"requires", "full_requires", "scope", "recipe_hash"],
raise_unexpected_field=False)

result = ConanInfo()
result.settings = Values.loads(parser.settings)
Expand Down
31 changes: 31 additions & 0 deletions conans/test/server/conf_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from conans.errors import ConanException
from conans.util.config_parser import ConfigParser
import unittest
from conans.util.files import save
import os
Expand Down Expand Up @@ -38,6 +40,35 @@ def setUp(self):
save(server_conf, fileconfig % self.storage_path)
self.environ = {}

def test_unexpected_section(self):
text = """
[one]
text=value
[two]
other=var
[three]
var
[moon]
var=walker
"""

self.assertRaises(ConanException, ConfigParser, text, ["one", "two", "three"])
conf = ConfigParser(text, ["one", "two", "three"], raise_unexpected_field=False)
self.assertEquals(conf.one, "text=value")
self.assertEquals(conf.two, "other=var")
self.assertEquals(conf.three, "var")
self.assertEquals(conf.moon, "var=walker")
with self.assertRaisesRegexp(ConanException, "Unrecognized field 'NOEXIST'"):
conf.NOEXIST

# IF an old config file is readed but the section is in the list, just return it empty
text = """
[one]
text=value
"""
conf = ConfigParser(text, ["one", "two", "three"], raise_unexpected_field=False)
self.assertEquals(conf.two, "")

def test_values(self):
config = ConanServerConfigParser(self.file_path, environment=self.environ)
self.assertEquals(config.jwt_secret, "mysecret")
Expand Down
4 changes: 2 additions & 2 deletions conans/util/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ConfigParser(object):
as parser.section
Currently used in ConanInfo and ConanFileTextLoader
"""
def __init__(self, text, allowed_fields=None, parse_lines=False):
def __init__(self, text, allowed_fields=None, parse_lines=False, raise_unexpected_field=True):
self._sections = {}
self._allowed_fields = allowed_fields or []
pattern = re.compile("^\[([a-z_]{2,50})\]")
Expand All @@ -43,7 +43,7 @@ def __init__(self, text, allowed_fields=None, parse_lines=False):
else:
raise ConanException("ConfigParser: Bad syntax '%s'" % line)
if field:
if self._allowed_fields and field not in self._allowed_fields:
if self._allowed_fields and field not in self._allowed_fields and raise_unexpected_field:
raise ConanException("ConfigParser: Unrecognized field '%s'" % field)
current_lines = []
self._sections[field] = current_lines
Expand Down

0 comments on commit 6765a09

Please sign in to comment.