示例#1
0
    def __set__(self, instance, value):
        try:
            value = int(value)

            if 0 < value <= 65535:  # max port number is 65535
                self.display_value = str(value)
                self.value = value
            else:
                raise OptionValidationError(
                    "Invalid option. Port value should be between 0 and 65536."
                )
        except ValueError:
            raise OptionValidationError(
                "Invalid option. Cannot cast '{}' to integer.".format(value))
示例#2
0
 def __set__(self, instance, value):
     if not value or is_ipv4(value) or is_ipv6(value):
         self.value = self.display_value = value
     else:
         raise OptionValidationError(
             "Invalid address. Provided address is not valid IPv4 or IPv6 address."
         )
示例#3
0
 def __set__(self, instance, value):
     try:
         self.display_value = str(value)
         self.value = float(value)
     except ValueError:
         raise OptionValidationError(
             "Invalid option. Cannot cast '{}' to float.".format(value))
示例#4
0
    def __set__(self, instance, value):
        if value.startswith("file://"):
            path = value.replace("file://", "")
            if not os.path.exists(path):
                raise OptionValidationError(
                    "File '{}' does not exist.".format(path))

        self.value = self.display_value = value
示例#5
0
 def __set__(self, instance, value):
     regexp = r"^[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}:[a-f\d]{1,2}$"
     if re.match(regexp, value.lower()):
         self.value = self.display_value = value
     else:
         raise OptionValidationError(
             "Invalid option. '{}' is not a valid MAC address".format(
                 value))
示例#6
0
 def __set__(self, instance, value):
     if value == "true":
         self.value = True
         self.display_value = value
     elif value == "false":
         self.value = False
         self.display_value = value
     else:
         raise OptionValidationError(
             "Invalid value. It should be true or false.")
示例#7
0
    def __set__(self, instance, value):
        encoder = instance.get_encoder(value)

        if encoder:
            self.value = encoder
            self.display_value = value
        else:
            raise OptionValidationError(
                "Encoder not available. Check available encoders with `show encoders`."
            )
示例#8
0
    def __init__(self, default, description="", advanced=False):
        self.description = description

        if default:
            self.display_value = "true"
        else:
            self.display_value = "false"

        self.value = default

        try:
            self.advanced = bool(advanced)
        except ValueError:
            raise OptionValidationError(
                "Invalid value. Cannot cast '{}' to boolean.".format(advanced))
示例#9
0
    def __init__(self, default, description="", advanced=False):
        self.label = None
        self.description = description

        try:
            self.advanced = bool(advanced)
        except ValueError:
            raise OptionValidationError(
                "Invalid value. Cannot cast '{}' to boolean.".format(advanced))

        if default or default == 0:
            self.__set__("", default)
        else:
            self.display_value = ""
            self.value = ""