Support for parsecontext config

This commit is contained in:
Jørgen Kvalsvik
2016-11-25 16:33:45 +01:00
parent 25a3007a1e
commit 321ef1d194
4 changed files with 55 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
from .sunbeam import parse
from .libsunbeam import action
__version__ = '0.0.1'
__license__ = 'GNU General Public License version 3'

View File

@@ -15,6 +15,14 @@ py::class_< EclipseState >( "EclipseState", py::no_init )
.add_property( "title", &EclipseState::getTitle )
;
void (ParseContext::*ctx_update)(const std::string&, InputError::Action) = &ParseContext::update;
py::class_< ParseContext >( "ParseContext" )
.def( "update", ctx_update )
;
py::enum_< InputError::Action >( "action" )
.value( "throw", InputError::Action::THROW_EXCEPTION )
.value( "warn", InputError::Action::WARN )
.value( "ignore", InputError::Action::IGNORE )
;
}

View File

@@ -3,5 +3,27 @@ import libsunbeam as lib
class EclipseState(lib.EclipseState):
pass
def parse(path):
return lib.parse(path, lib.ParseContext())
def _parse_context(actions):
ctx = lib.ParseContext()
if actions is None:
return ctx
# this might be a single tuple, in which case we unpack it and repack it
# into a list. If it's not a tuple we assume it's an iterable and just
# carry on
try:
key, action = actions
except ValueError:
pass
else:
actions = [(key, action)]
for key, action in actions:
ctx.update(key, action)
return ctx
def parse(path, actions = None):
return lib.parse(path, _parse_context(actions))