Example #1
0
    def __init__(self, match):
        """Construct a matcher.  The 'cidr' argument is a dict that conforms to
        an IPCIDRList as described in the pScheduler JSON Style Guide
        and Type Dictionary.
        """
        valid, message = json_validate(
            match, {
                "type": "object",
                "properties": {
                    "cidr": {
                        "$ref": "#/pScheduler/IPCIDRList"
                    },
                    "invert": {
                        "$ref": "#/pScheduler/Boolean"
                    },
                },
                "additionalProperties": False,
                "required": ["cidr"]
            })

        if not valid:
            raise ValueError("Invalid match: " + message)

        try:
            self.invert = match["invert"]
        except KeyError:
            self.invert = False

        self.cidr = match["cidr"]
Example #2
0
    def __init__(self, match):
        """Construct a matcher.  The 'match' argument is a dict that conforms to
        a StringMatch as described in the pScheduler JSON Style Guide
        and Type Dictionary.
        """

        # TODO: It seems clunky to have to do this when we should be
        # able to just say { "$ref": "#/pScheduler/StringMatch" } and
        # be done with it.

        valid, message = json_validate({"match": match}, {
            "type": "object",
            "properties": {
                "match": {
                    "$ref": "#/pScheduler/StringMatch"
                }
            },
            "additionalProperties": False
        })

        if not valid:
            raise ValueError("Invalid match: " + message)

        try:
            self.case_insensitive = match["case-insensitive"]
        except KeyError:
            self.case_insensitive = False

        try:
            self.invert = match["invert"]
        except KeyError:
            self.invert = False

        self.style = match["style"]

        if self.style == "regex":
            try:
                self.regex = re.compile(match["match"])
            except sre_constants.error as ex:
                print ex
                raise ValueError("Invalid regular expression: " + str(ex))
        else:
            self.match = match["match"]
            if self.case_insensitive:
                self.match = self.match.lower()
Example #3
0
    def __init__(self, match):

        """Construct a matcher.  The 'match' argument is a dict that conforms to
        a StringMatch as described in the pScheduler JSON Style Guide
        and Type Dictionary.
        """

        # TODO: It seems clunky to have to do this when we should be
        # able to just say { "$ref": "#/pScheduler/StringMatch" } and
        # be done with it.

        valid, message = json_validate({"match": match },
                                       { "type": "object",
                                         "properties": {
                                             "match": { "$ref": "#/pScheduler/StringMatch" }
                                         },
                                         "additionalProperties": False
                                         })

        if not valid:
            raise ValueError("Invalid match: " + message)

        try:
            self.case_insensitive = match["case-insensitive"]
        except KeyError:
            self.case_insensitive = False

        try:
            self.invert = match["invert"]
        except KeyError:
            self.invert = False

        self.style = match["style"]

        if self.style == "regex":
            try:
                self.regex = re.compile(match["match"])
            except sre_constants.error as ex:
                print ex
                raise ValueError("Invalid regular expression: " + str(ex))
        else:
            self.match = match["match"]
            if self.case_insensitive:
                self.match = self.match.lower()
Example #4
0
    def __init__(self, enum):

        """Construct a matcher.  The 'enum' argument is a dict that conforms to
        an EnumMatch as described in the pScheduler JSON Style Guide
        and Type Dictionary.
        """
        valid, message = json_validate({"enumeration": enum },
                                       { "type": "object",
                                         "properties": {
                                             "enumeration": { "$ref": "#/pScheduler/EnumMatch" }
                                         },
                                         "additionalProperties": False
                                         })

        if not valid:
            raise ValueError("Invalid match: " + message)

        try:
            self.invert = enum["invert"]
        except KeyError:
            self.invert = False

        self.enum = enum["enumeration"]
Example #5
0
    def __init__(self, enum):
        """Construct a matcher.  The 'enum' argument is a dict that conforms to
        an EnumMatch as described in the pScheduler JSON Style Guide
        and Type Dictionary.
        """
        valid, message = json_validate(
            enum, {
                "type": "object",
                "properties": {
                    "enumeration": {
                        "type": "array",
                        "items": {
                            "anyOf": [{
                                "type": "string"
                            }, {
                                "$ref": "#/pScheduler/Number"
                            }]
                        }
                    },
                    "invert": {
                        "$ref": "#/pScheduler/Boolean"
                    },
                },
                "additionalProperties": False,
                "required": ["enumeration"]
            })

        if not valid:
            raise ValueError("Invalid match: " + message)

        try:
            self.invert = enum["invert"]
        except KeyError:
            self.invert = False

        self.enum = enum["enumeration"]