def _label_constraints_check()

in src/dfcx_scrapi/builders/intents.py [0:0]


    def _label_constraints_check(self, key: str, value: str):
        """Check constraints for the label's key and value
        and raise an error if needed.

        Args:
          key (str):
            Label's key.
          value (str):
            Label's value.
        """
        allowed_chars = ascii_lowercase + digits + "-_"
        # TODO Add International characteres to allowed_chars
        allowed_char_error_msg = (
            "Key and Value can only contain lowercase letters,"
            " numeric characters, underscores and dashes."
        )
        if not(isinstance(key, str) and isinstance(value, str)):
            raise ValueError(
                "Key and value should be string."
            )
        if len(key) > 63 or len(value) > 63:
            raise ValueError(
                "Key and value can be no longer than 63 characters"
            )
        if key.startswith("sys-") and key not in ["sys-head", "sys-contextual"]:
            raise ValueError(
                "Prefix `sys-` is reserved for Dialogflow defined labels."
            )
        if key[0] not in ascii_lowercase:
            raise ValueError("Key must start with a lowercase letter.")
        for s in key:
            if s not in allowed_chars:
                raise ValueError(allowed_char_error_msg)
        for s in value:
            if s not in allowed_chars:
                raise ValueError(allowed_char_error_msg)