Esempio n. 1
0
 def validate(self, options, arguments):
     if not options.has_key(urn_key):
         raise CHAPIv1ArgumentError('Option key missing: ' + self._urn_key)
     urns = options[self._urn_key]
     if urns.instanceof(types.StringType): urns = [urns]
     for urn in urns:
         if not is_valid_urn(urn):
             raise CHAPIv1ArgumentError("Invalid URN: " + urn)
Esempio n. 2
0
 def validate(self, options, arguments):
     if not options.has_key(urn_key):
         raise CHAPIv1ArgumentError('Option key missing: ' + self._urn_key)
     urns = options[self._urn_key]
     if urns.instanceof(types.StringType): urns = [urns]
     for urn in urns:
         if not is_valid_urn(urn):
             raise CHAPIv1ArgumentError("Invalid URN: " + urn)
Esempio n. 3
0
    def validateTypedField(self, field, field_type, value):

        properly_formed = True
        if field_type == "URN":
            if isinstance(value, list):
                for v in value:
                    if isinstance(v, basestring): v = str(v)  # Support UNICODE
                    if not is_valid_urn(v):
                        properly_formed = False
                        break
            else:
                if isinstance(value, basestring):
                    value = str(value)  # Support UNICODE
                properly_formed = is_valid_urn(value)
        elif field_type == "UID":
            try:
                if isinstance(value, list):
                    for v in value:
                        uuid.UUID(v)
                else:
                    uuid.UUID(value)
            except Exception as e:
                properly_formed = False
        elif field_type == "UID_OR_NULL":
            return value is None or \
                self.validateTypedField(field, 'UID', value)
        elif field_type == "STRING":
            pass  # Always true
        elif field_type == "INTEGER" or field_type == "POSITIVE":
            try:
                v = int(value)
                if field_type == "POSITIVE":
                    properly_formed = (v > 0)
            except Exception as e:
                properly_formed = False
        elif field_type == "DATETIME":
            properly_formed = False
            if value:
                try:
                    parsed_value = dateutil.parser.parse(value)
                    properly_formed = True
                except Exception, e:
                    pass
Esempio n. 4
0
    def validateTypedField(self, field, field_type, value):

        properly_formed = True
        if field_type == "URN":
            if isinstance(value, list):
                for v in value:
                    if isinstance(v, basestring): v = str(v) # Support UNICODE
                    if not is_valid_urn(v):
                        properly_formed = False
                        break
            else:
                if isinstance(value, basestring): value = str(value) # Support UNICODE
                properly_formed = is_valid_urn(value)
        elif field_type == "UID":
            try:
                if isinstance(value, list):
                    for v in value: uuid.UUID(v)
                else:
                    uuid.UUID(value)
            except Exception as e:
                properly_formed = False
        elif field_type == "UID_OR_NULL":
            return value is None or \
                self.validateTypedField(field, 'UID', value)
        elif field_type == "STRING":
            pass # Always true
        elif field_type == "INTEGER" or field_type == "POSITIVE":
            try:
                v = int(value)
                if field_type == "POSITIVE":
                    properly_formed = (v > 0)
            except Exception as e:
                properly_formed = False
        elif field_type == "DATETIME":
            properly_formed = False
            if value:
                try:
                    parsed_value = dateutil.parser.parse(value)
                    properly_formed = True
                except Exception, e:
                    pass