Esempio n. 1
0
 def parse(self, message):
     assert is_string(message)
     try:
         form_code, tokens = self.form_code(message)
         submission, extra_data = self._parse_tokens(tokens, form_code)
     except SMSParserInvalidFormatException as ex:
         raise SMSParserInvalidFormatException(ex.data)
     except MultipleSubmissionsForSameCodeException as ex:
         raise MultipleSubmissionsForSameCodeException(ex.data[0])
     return form_code, submission, extra_data
Esempio n. 2
0
 def _parse_tokens(self, tokens):
     tokens = [token.strip() for token in tokens if token]
     submission = {}
     for token in tokens:
         if is_empty(token): continue
         field_code, answer = self._parse_token(token)
         if field_code in submission.keys():
             raise MultipleSubmissionsForSameCodeException(field_code)
         submission[field_code] = answer
     return submission
Esempio n. 3
0
    def _parse_tokens(self, tokens, form_code):
        tokens = self._handle_tokens_with_only_separators(tokens)
        submission = OrderedDict()
        question_codes, form_model = self.get_question_codes(form_code)
        extra_data = []

        for token in tokens:
            if is_empty(token): continue
            field_code, answer = self._parse_token(token)
            if field_code in submission.keys():
                raise MultipleSubmissionsForSameCodeException(field_code)
            submission[field_code] = answer
            if field_code not in question_codes:
                extra_data.append(answer)
        return submission, extra_data