Exemple #1
0
def string_literal():
  whitespace()
  quote = one_of('\'"')
  commit()
  st = u''.join(many1(p(string_char, quote)))
  one_of(quote)
  return ('str', st)
Exemple #2
0
    def parse(cls):
        one_of('+')
        pico.one_of_strings('register', 'reg')

        result = {}

        @tri
        def ident():
            whitespace1()
            pico.hash()
            commit()
            return many1(any_token)

        @tri
        def number():
            whitespace1()
            return many1(partial(one_of, string.digits + ' -+()'))

        @tri
        def name():
            whitespace1()
            return pico.name()

        ident = optional(partial(choice, ident, number), None)
        if ident is not None:
            result['ident'] = re.sub('[ \-+()]', '', "".join(ident))
        else:
            name = optional(name, None)
            if name is not None:
                result['name'] = name

        return result
Exemple #3
0
    def parse(cls):
        one_of('+')
        caseless_string('echo')
        whitespace()

        return {
            'echo': "".join(remaining())
            }
Exemple #4
0
 def _ParseParam(self):
   """Consumes parameter keys for lookup in a parameter dictionary passed in with the query.
   Parameter keys may consist of letters, digits and underscores (_).
   Returns the value that the parameter key maps to.
   """
   one_of('{')
   param_name = ''.join(many_until1(p(one_of, letters + digits + '_'), p(one_of, '}'))[0])
   return Parameter(param_name)
def parenthetical():
    whitespace()
    one_of('(')
    commit()
    whitespace()
    v = expression()
    whitespace()
    one_of(')')
    whitespace()
    return ParentheticalNode(v)
Exemple #6
0
def parenthetical():
    whitespace()
    one_of('(')
    commit()
    whitespace()
    v = expression()
    whitespace()
    one_of(')')
    whitespace()
    return ParentheticalNode(v)
Exemple #7
0
 def _ParseParenthetical(self):
   """Consumes parenthetical expression."""
   whitespace()
   one_of('(')
   commit()
   whitespace()
   node = self._expr_parser()
   whitespace()
   one_of(')')
   whitespace()
   return Parenthetical(self._schema, node)
Exemple #8
0
 def _ParsePhrase(self):
   """Consumes a key range specification of the form <table>.<column>=<maybe
   quoted value>.
   """
   whitespace()
   table = self._token().lower()
   one_of('.')
   commit()
   column = self._token().lower()
   whitespace()
   one_of('=')
   whitespace()
   phrase = self._param_parser()
   node = PhraseNode(self._schema, table, column, phrase)
   whitespace()
   return node
Exemple #9
0
    def parse(cls):
        one_of('+')
        caseless_string('epi')

        aggregates = {}

        if whitespace():
            while peek():
                try:
                    code = "".join(pico.one_of_strings(*(
                        tuple(cls.TOKENS) + tuple(cls.ALIAS))))
                    code = code.upper()
                except:
                    raise FormatError(
                        "Expected an epidemiological indicator "
                        "such as TB or MA (got: %s)." % \
                        "".join(remaining()))

                # rewrite alias
                code = cls.ALIAS.get(code, code)

                if code in aggregates:
                    raise FormatError("Duplicate value for %s." % code)

                whitespace1()

                try:
                    minus = optional(partial(one_of, '-'), '')
                    value = int("".join([minus]+pico.digits()))
                except:
                    raise FormatError("Expected a value for %s." % code)

                if value < 0:
                    raise FormatError("Got %d for %s. You must "
                                      "report a positive value." % (
                        value, cls.TOKENS[code].lower()))

                aggregates[code] = value
                many(partial(one_of, ' ,;.'))

        return {
            'aggregates': aggregates
            }
Exemple #10
0
    def parse():
        one_of('+')
        one_of_strings('register', 'reg')

        result = {}

        @tri
        def ident():
            whitespace1()
            one_of('#')
            commit()
            result['ident'] = "".join(many1(partial(not_one_of, ',')))

        @tri
        def name():
            whitespace1()
            result['name'] = "".join(many1(partial(not_one_of, ',')))

        optional(partial(choice, ident, name), None)
        return result
Exemple #11
0
def char_spec_range():
    one_of("[")
    low = char_spec_range_char()
    one_of('-')
    high = char_spec_range_char()
    one_of("]")
    return partial(satisfies, lambda c: low <= c <= high)
Exemple #12
0
def char_spec_range():
    one_of("[")
    low = char_spec_range_char()
    one_of("-")
    high = char_spec_range_char()
    one_of("]")
    return partial(satisfies, lambda c: low <= c <= high)
Exemple #13
0
 def _ParsePhrase(self):
   """Reads one attribute col_name=value. Creates a DB update
   in self._updates.
   """
   col_name = self._token().lower()
   col_def = self._table.GetColumn(col_name)
   one_of('=')
   commit()
   phrase = self._phrase()
   if phrase:
     value = eval(phrase)
     if col_def.value_type == 'N':
       value = int(value)
     if self._raw:
       self._updates[col_def.key] = db_client.UpdateAttr(value, 'PUT')
     else:
       self._updates[col_name] = value
   else:
     if self._raw:
       self._updates[col_def.key] = db_client.UpdateAttr(None, 'DELETE')
     else:
       self._updates[col_name] = None
   return None
Exemple #14
0
 def _ParsePhrase(self):
     """Reads one attribute col_name=value. Creates a DB update
 in self._updates.
 """
     col_name = self._token().lower()
     col_def = self._table.GetColumn(col_name)
     one_of('=')
     commit()
     phrase = self._phrase()
     if phrase:
         value = eval(phrase)
         if col_def.value_type == 'N':
             value = int(value)
         if self._raw:
             self._updates[col_def.key] = db_client.UpdateAttr(value, 'PUT')
         else:
             self._updates[col_name] = value
     else:
         if self._raw:
             self._updates[col_def.key] = db_client.UpdateAttr(
                 None, 'DELETE')
         else:
             self._updates[col_name] = None
     return None
Exemple #15
0
def bracketed():
    one_of('[')
    v = expression()
    one_of(']')
    return ['bracket', v]
Exemple #16
0
def float_value():
    whole_part = digits()
    one_of('.')
    commit()
    decimal_part = digits()
    return float('%s.%s' % (whole_part, decimal_part))
Exemple #17
0
def entity():
    one_of('&')
    ent = choice(named_entity, numeric_entity)
    one_of(';')
    return ent
def float_value():
    whole_part = digits()
    one_of('.')
    commit()
    decimal_part = digits()
    return float('%s.%s' % (whole_part, decimal_part))
Exemple #19
0
    def parse(cls):
        result = {}

        prefix = optional(tri(identifier), None)
        if prefix is not None:
            result['patient_id'] = "".join(prefix)
            whitespace()

        one_of('+')
        caseless_string('muac')

        if prefix is None:
            try:
                whitespace1()
                part = optional(tri(identifier), None)
                if part is not None:
                    result['patient_id'] = "".join(part)
                else:
                    result['name'] = name()
            except:
                raise FormatError("Expected a patient id or name.")

        if 'name' in result:
            try:
                separator()
                result['sex'] = one_of('MmFf').upper()
            except:
                raise FormatError("Expected either M or F to indicate the patient's gender.")

            try:
                separator()
            except:
                raise FormatError("Expected age or birthdate of patient.")

            try:
                result['age'] = choice(*map(tri, (date, timedelta)))
            except:
                received, stop = many_until(any_token, comma)
                raise FormatError("Expected age or birthdate of patient, but "
                                 "received %s." % "".join(received))
        try:
            if prefix is None:
                separator()
            else:
                whitespace1()

            reading = choice(
                partial(one_of_strings, 'red', 'green', 'yellow', 'r', 'g', 'y'),
                digits)

            try:
                reading = int("".join(reading))
            except:
                reading = reading[0].upper()
            else:
                whitespace()
                unit = optional(partial(one_of_strings, 'mm', 'cm'), None)
                if unit is None:
                    reading = cls.get_reading_in_mm(reading)
                elif "".join(unit) == 'cm':
                    reading = reading * 10
            result['reading'] = reading
        except:
            raise FormatError(
                "Expected MUAC reading (either green, yellow or red), but "
                "received %s." % "".join(remaining()))

        if optional(separator, None):
            result['tags'] = tags()

        return result
Exemple #20
0
def braced():
    one_of('{')
    v = expression()
    one_of('}')
    return ['brace', v]
Exemple #21
0
def bracketed():
    one_of('[')
    v = expression()
    one_of(']')
    return ['bracket', v]
Exemple #22
0
def numeric_entity():
    one_of("#")
    return choice(hex_entity, dec_entity)
Exemple #23
0
def hex_entity():
    one_of("x")
    return unichr(hex_value())
Exemple #24
0
def entity():
    one_of("&")
    ent = choice(named_entity, numeric_entity)
    one_of(";")
    return ent
Exemple #25
0
def operator_char():
  return one_of(operator_chars)
Exemple #26
0
 def ident():
     whitespace1()
     one_of('#')
     commit()
     result['ident'] = "".join(many1(partial(not_one_of, ',')))
Exemple #27
0
def matched(start, stop, name):
    one_of(start)
    v = expression()
    one_of(stop)
    return [name, v]
Exemple #28
0
def braced():
    one_of('{')
    v = expression()
    one_of('}')
    return ['brace', v]
Exemple #29
0
def parse_tracking_id():
    return pico.digit() + pico.digit() + \
           one_of(TRACKING_ID_LETTERS) + \
           one_of(TRACKING_ID_LETTERS) + \
           pico.digit() + pico.digit()
Exemple #30
0
 def parse(cls):
     one_of('+')
     caseless_string('error')
     raise FormatError("error")
Exemple #31
0
def matched(start, stop, name):
    one_of(start)
    v = expression()
    one_of(stop)
    return [name, v]
Exemple #32
0
 def parse(cls):
     one_of('+')
     caseless_string('break')
Exemple #33
0
def numeric_entity():
    one_of('#')
    return choice(hex_entity, dec_entity)
Exemple #34
0
 def parse(cls):
     one_of('+')
     caseless_string('bad')
     from django.core.exceptions import ImproperlyConfigured
     raise ImproperlyConfigured("".join(remaining()))
Exemple #35
0
def hex_entity():
    one_of('x')
    return unichr(hex_value())
Exemple #36
0
 def parse(cls):
     one_of('+')
     caseless_string('hello')
Exemple #37
0
def parened():
    one_of('(')
    v = expression()
    one_of(')')
    return ['paren', v]
Exemple #38
0
def parened():
    one_of('(')
    v = expression()
    one_of(')')
    return ['paren', v]