Beispiel #1
0
    def parse_datetime(self, content):
        value = None
        if content:
            try:
                value = date_parser.parse(content)
            except ValueError:
                raise ParseError("Can't parse '%s' as a datetime." % content)

        return value
Beispiel #2
0
    def parse_int(self, content):
        value = None
        if content != '' and content is not None:
            try:
                value = int(content)
            except ValueError:
                raise ParseError("Can't parse '%s' as an int." % content)

        return value
Beispiel #3
0
    def parse_decimal(self, content):
        value = None
        if content != '' and content is not None:
            try:
                value = Decimal(content)
            except InvalidOperation:
                raise ParseError("Can't parse '%s' as a decimal." % content)

        return value
Beispiel #4
0
    def parse_bool(self, content):
        if content == '' and content is not None:
            value = None
        elif content == '1':
            value = True
        elif content == '0':
            value = False
        else:
            raise ParseError("Can't parse '%s' as a bool." % content)

        return value