예제 #1
0
    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
예제 #2
0
파일: pico.py 프로젝트: malthe/ugandasms
 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
예제 #3
0
파일: pico.py 프로젝트: djangosms/core
        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
예제 #4
0
파일: pico.py 프로젝트: djangosms/core
def parse(parser, text):
    return "".join(run_parser(parser, tuple(text))[0])
예제 #5
0
 def _epi(text):
     from ..models import Epi
     from picoparse import run_parser
     return run_parser(Epi.parse, text)[0]
예제 #6
0
 def _muac(text):
     from ..models import Muac
     from picoparse import run_parser
     return run_parser(Muac.parse, text)[0]
예제 #7
0
 def run_parser(self, parser, input):
     return run_parser(parser, input)
예제 #8
0
 def _parse(text):
     from .models import Registration
     from picoparse import run_parser
     return run_parser(Registration.parse, text)[0]
예제 #9
0
def run_text_parser(parser, input):
    return run_parser(parser, input, TextDiagnostics())
예제 #10
0
파일: text.py 프로젝트: mgautierfr/ediap
def run_text_parser(parser, input):
    return run_parser(parser, input, TextDiagnostics())
예제 #11
0
def xml_char_spec(spec, extra_choices=[]):
    parsers, remainder = run_parser(xml_char_spec_parser, spec.strip())
    return partial(choice, *(extra_choices + parsers))
예제 #12
0
파일: xml.py 프로젝트: stjordanis/picoparse
def xml_char_spec(spec, extra_choices=[]):
    parsers, remainder = run_parser(xml_char_spec_parser, spec.strip())
    return partial(choice, *(extra_choices + parsers))