예제 #1
0
    def _control(self, value):
        """Control input value for dangerous characters or types, like "#"

        :param value: value to be controled
        """

        # ugly characters, only if string
        if type(value) != types.BooleanType:
            for char in self.restrictedCharacters:
                if value.find(char) > -1:
                    raise Exceptions.InvalidParameterValue(value)

        # type
        try:
            if self.dataType == types.FloatType:
                value = float(value)
            elif self.dataType == types.StringType:
                value = str(value)
            elif self.dataType == types.IntType:
                value = int(value)
            elif self.dataType == types.BooleanType:
                value = bool(value)
            #TODO other types missing
        except (ValueError), e:
            raise Exceptions.InvalidParameterValue(value)
예제 #2
0
파일: InAndOutputs.py 프로젝트: gkm4d/pywps
    def _control(self,value):
        """Control input value for dangerous characters or types, like "#"

        :param value: value to be controled
        """

         # ugly characters, only if string
        if  type(value)!= types.BooleanType:
            for char in self.restrictedCharacters:
                if value.find(char) > -1:
                    raise Exceptions.InvalidParameterValue("datainputs",
                        "Input [%s] has a value %s which contains unallowed characters." % (self.identifier, str(value)))

        # type
        try:
            if self.dataType == types.FloatType:
                value = float(value)
            elif self.dataType == types.StringType:
                value = str(value)
            elif self.dataType == types.IntType:
                value = int(value)
            elif self.dataType == types.BooleanType:
                value = bool(value)
            #TODO other types missing
        except (ValueError), e:
            raise Exceptions.InvalidParameterValue("datainputs",
                "Input [%s] has a value %s which is the wrong data type." % (self.identifier, str(value)))
예제 #3
0
class LiteralInput(Input):
    """Literal input type of input. 

    :param identifier: input identifier
    :param title: input title
    :param abstract: input description. Default: None
    :param uoms: List of string value units
    :param minOccurs: minimum number of occurrences. 
    :param maxOccurs: maximum number of occurrences. 
    :param allowedValues:  List of strings or lists of allowed values,
                which can be used with this input. You can set interval
                using list with two items, like::

                    (1,2,3,(5,9),10,"a",("d","g"))

                This will produce allowed values 1,2,3,10, "a" and
                any value between 5 and 9 or "d" and "g".

                If "*" is used, it means "any value"
    :param type: :class:`types.TypeType` value type, e.g. Integer, String, etc. you
                can uses the :mod:`types` module of python.
    :param default:  default value.
    :param spacing:

        .. note: PyWPS does not support spacing parameter yet

    .. attribute:: dataType

        :class:`types.TypeType` type of literal data. Default is integer

    .. attribute:: uoms

        list of units

    .. attribute: restrictedCharacters

        characters, which will be ommited in the input from security
        reasons

    .. attribute:: values

        allowed values
    
    .. attribute:: default

        default value

    ..  attribute:: spacing

        .. note:: this attribute is not used

    .. attribute:: uom
        
        units
    """

    dataType = None
    uoms = None
    restrictedCharacters = ['\\', "#", ";", "&", "!"]
    values = None
    default = None
    spacing = None
    uom = None

    def __init__(self,
                 identifier,
                 title,
                 abstract=None,
                 metadata=[],
                 minOccurs=1,
                 maxOccurs=1,
                 dataType=types.StringType,
                 uoms=(),
                 values=("*"),
                 spacing=None,
                 default=None):
        """Class constructor"""
        Input.__init__(self,
                       identifier,
                       title,
                       abstract=abstract,
                       metadata=metadata,
                       minOccurs=minOccurs,
                       maxOccurs=maxOccurs,
                       type="LiteralValue")

        self.dataType = dataType
        self.uoms = uoms
        self.restrictedCharacters = ['\\', "#", ";", "&", "!"]
        if type(values) == types.StringType:
            self.values = (values)
        elif type(values) == types.ListType:
            self.values = values
        self.default = default
        self.spacing = spacing
        self.uom = None
        return

    def setValue(self, input):
        """Set input value to this input
        
        :param input: input parsed by parsers
        :return: None or Error message
        """
        if type(input["value"]) == types.ListType:
            for inpt in input["value"]:
                resp = self._setValueWithOccurence(self.value,
                                                   self._control(inpt))
                if resp:
                    return resp
        else:
            resp = self._setValueWithOccurence(self.value,
                                               self._control(input["value"]))
            if resp:
                return resp

    def getValue(self):
        """Get the input value

        :returns: :attr:`value`
        """
        if self.value != None:
            return self.value
        elif self.default != None:
            return self.default
        else:
            return

    def _control(self, value):
        """Control input value for dangerous characters or types, like "#"

        :param value: value to be controled
        """

        # ugly characters, only if string
        if type(value) != types.BooleanType:
            for char in self.restrictedCharacters:
                if value.find(char) > -1:
                    raise Exceptions.InvalidParameterValue(value)

        # type
        try:
            if self.dataType == types.FloatType:
                value = float(value)
            elif self.dataType == types.StringType:
                value = str(value)
            elif self.dataType == types.IntType:
                value = int(value)
            elif self.dataType == types.BooleanType:
                value = bool(value)
            #TODO other types missing
        except (ValueError), e:
            raise Exceptions.InvalidParameterValue(value)

        # value list
        if "*" in self.values:
            return value

        for allowed in self.values:
            if type(allowed) == types.ListType:
                if allowed[0] <= value <= allowed[-1]:
                    if self.spacing:
                        if (value - allowed[0]) % spacing == 0:
                            return value
                    else:
                        return value

            else:
                if str(value) == str(allowed):
                    return value

        raise Exceptions.InvalidParameterValue(value)