def incoming(self, ident, text, time=None): """Return list of messages that result from this request. This method is invoked by message transports when they receive an incoming message. Since individual parsers may choose to parse only a fragment of the provided text, multiple messages may result. Signals are provided to monitor the flow of operations of this method: :data:`pre_parse`, :data:`post_parse`, :data:`pre_handle` and :data:`post_handle`. Note that not all signals may be fired; the exact conditions are described in the documentation of each signal. When the system runs in debug mode (with the ``DEBUG`` setting set to a true value), all exceptions are let through to the calling method. Otherwise a warning is logged with the full traceback while the exception is suppressed. """ remaining = unicode(text) time = time or datetime.now() messages = [] try: while True: text = remaining.strip() message = Incoming(text=text, time=time) pre_parse.send(sender=message) text = tuple(message.text) or ("",) error = None result = None remaining = "" for model in self.models: try: result, remaining = run_parser(model.parse, text) except NoMatch: continue except FormatError, error: pass except Exception, exc: # pragma: NOCOVER # backwards compatible with older version of # picoparse; this is equivalent to not # matching if "Commit / cut called" in str(exc): continue raise
def parse(*args): args = list(args) text = args.pop() text = tuple(text) or ("", ) try: result, remaining = run_parser(partial(parser, *args), text) except NoMatch: return None, "" except Exception, exc: # pragma: NOCOVER # backwards compatible with older version of # picoparse; this is equivalent to not # matching if 'Commit / cut called' in str(exc): return None, "" raise
def parse(*args, **kwargs): try: text = kwargs.pop(name) or ("\n", ) except KeyError: raise KeyError( "Expected key: '%s' in arguments (got: %s)." % ( name, repr(kwargs))) try: result, remaining = run_parser(partial(parser, *args, **kwargs), text) except NoMatch: return except Exception, exc: # pragma: NOCOVER # backwards compatible with older version of # picoparse; this is equivalent to not # matching if 'Commit / cut called' in unicode(exc): return raise
def parse(parser, text): return "".join(run_parser(parser, tuple(text))[0])
def _epi(text): from ..models import Epi from picoparse import run_parser return run_parser(Epi.parse, text)[0]
def _muac(text): from ..models import Muac from picoparse import run_parser return run_parser(Muac.parse, text)[0]
def run_parser(self, parser, input): return run_parser(parser, input)
def _parse(text): from .models import Registration from picoparse import run_parser return run_parser(Registration.parse, text)[0]
def run_text_parser(parser, input): return run_parser(parser, input, TextDiagnostics())
def xml_char_spec(spec, extra_choices=[]): parsers, remainder = run_parser(xml_char_spec_parser, spec.strip()) return partial(choice, *(extra_choices + parsers))