Example #1
0
 def from_yml_rep(cls, yml_rep):
     if not isinstance(yml_rep, int):
         raise TableEntryInvalidYmlRepresentationError("Could not parse value[{}] of type[{}] as integer".format(
             yml_rep, type(yml_rep).__name__))
     elif not_in_inclusive_range(yml_rep, (0, (1 << (8 * cls.size)) - 1)):
         raise TableEntryInvalidYmlRepresentationError("Value[{}] is not valid, must be in range [{},{}]".format(
             yml_rep, 0, (1 << (8 * cls.size)) - 1))
     else:
         return yml_rep
Example #2
0
    def from_yml_rep(cls, yml_rep):
        if not (isinstance(yml_rep, list) and all(isinstance(x, int) for x in yml_rep)):
            raise TableEntryInvalidYmlRepresentationError("Could not parse value[{}] to a list of integers"
                                                          .format(yml_rep))
        elif any(not_in_inclusive_range(x, (0, 0xff)) for x in yml_rep):
            raise TableEntryInvalidYmlRepresentationError("Byte list[{}] contains a value less than 0 or greater "
                                                          "than 255 (0xff)".format(yml_rep))

        return yml_rep
Example #3
0
 def from_yml_rep(cls, yml_rep):
     if not isinstance(yml_rep, int):
         raise TableEntryInvalidYmlRepresentationError(
             "Could not parse value[{}] of type[{}] as integer".format(
                 yml_rep,
                 type(yml_rep).__name__))
     elif not_in_inclusive_range(yml_rep, (0, (1 << (8 * cls.size)) - 1)):
         raise TableEntryInvalidYmlRepresentationError(
             "Value[{}] is not valid, must be in range [{},{}]".format(
                 yml_rep, 0, (1 << (8 * cls.size)) - 1))
     else:
         return yml_rep
Example #4
0
    def from_yml_rep(cls, yml_rep):
        if not (isinstance(yml_rep, list)
                and all(isinstance(x, int) for x in yml_rep)):
            raise TableEntryInvalidYmlRepresentationError(
                "Could not parse value[{}] to a list of integers".format(
                    yml_rep))
        elif any(not_in_inclusive_range(x, (0, 0xff)) for x in yml_rep):
            raise TableEntryInvalidYmlRepresentationError(
                "Byte list[{}] contains a value less than 0 or greater "
                "than 255 (0xff)".format(yml_rep))

        return yml_rep