How to use the pathvalidate.error.InvalidCharError function in pathvalidate

To help you get started, we’ve selected a few pathvalidate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pathvalidate / pathvalidate / _filepath.py View on Github external
def __validate_unix_filepath(self, unicode_filepath: str) -> None:
        match = _RE_INVALID_PATH.findall(unicode_filepath)
        if match:
            raise InvalidCharError(
                self._ERROR_MSG_TEMPLATE.format(
                    invalid=findall_to_str(match), value=repr(unicode_filepath)
                )
github thombashi / pathvalidate / pathvalidate / _filename.py View on Github external
def __validate_win_filename(self, unicode_filename: str) -> None:
        match = _RE_INVALID_WIN_FILENAME.findall(unicode_filename)
        if match:
            raise InvalidCharError(
                self._ERROR_MSG_TEMPLATE.format(
                    invalid=findall_to_str(match), value=repr(unicode_filename)
                ),
                platform=Platform.WINDOWS,
            )

        if unicode_filename in (".", ".."):
            return

        if unicode_filename[-1] in (" ", "."):
            raise InvalidCharError(
                self._ERROR_MSG_TEMPLATE.format(
                    invalid=re.escape(unicode_filename[-1]), value=repr(unicode_filename)
                ),
                platform=Platform.WINDOWS,
                description="Do not end a file or directory name with a space or a period",
github thombashi / pathvalidate / pathvalidate / variable / _base.py View on Github external
unicode_var_name = preprocess(value)

        if self._is_reserved_keyword(unicode_var_name):
            raise InvalidReservedNameError(
                "{:s} is a reserved keyword by python".format(unicode_var_name)
            )

        match = self._invalid_var_name_re.search(unicode_var_name)
        if match is not None:
            raise InvalidCharError(
                "invalid char found in the variable name: '{}'".format(re.escape(match.group()))
            )

        match = self._invalid_var_name_head_re.search(unicode_var_name)
        if match is not None:
            raise InvalidCharError(
                "the first character of the variable name is invalid: '{}'".format(
                    re.escape(match.group())
                )
github thombashi / pathvalidate / pathvalidate / _filename.py View on Github external
def __validate_unix_filename(self, unicode_filename: str) -> None:
        match = _RE_INVALID_FILENAME.findall(unicode_filename)
        if match:
            raise InvalidCharError(
                self._ERROR_MSG_TEMPLATE.format(
                    invalid=findall_to_str(match), value=repr(unicode_filename)
                )
github thombashi / pathvalidate / pathvalidate / _symbol.py View on Github external
def validate_symbol(text: str) -> None:
    """
    Verifying whether symbol(s) included in the ``text`` or not.

    Args:
        text:
            Input text to validate.

    Raises:
        ValidationError (ErrorReason.INVALID_CHARACTER):
            If symbol(s) included in the ``text``.
    """

    match_list = __RE_SYMBOL.findall(preprocess(text))
    if match_list:
        raise InvalidCharError("invalid symbols found: {}".format(match_list))
github thombashi / pathvalidate / pathvalidate / variable / _base.py View on Github external
def _validate(self, value):
        self._validate_null_string(value)

        unicode_var_name = preprocess(value)

        if self._is_reserved_keyword(unicode_var_name):
            raise InvalidReservedNameError(
                "{:s} is a reserved keyword by python".format(unicode_var_name)
            )

        match = self._invalid_var_name_re.search(unicode_var_name)
        if match is not None:
            raise InvalidCharError(
                "invalid char found in the variable name: '{}'".format(re.escape(match.group()))
            )

        match = self._invalid_var_name_head_re.search(unicode_var_name)
        if match is not None:
            raise InvalidCharError(
                "the first character of the variable name is invalid: '{}'".format(
                    re.escape(match.group())
                )
github thombashi / pathvalidate / pathvalidate / _filename.py View on Github external
def __validate_win_filename(self, unicode_filename: str) -> None:
        match = _RE_INVALID_WIN_FILENAME.findall(unicode_filename)
        if match:
            raise InvalidCharError(
                self._ERROR_MSG_TEMPLATE.format(
                    invalid=findall_to_str(match), value=repr(unicode_filename)
                ),
                platform=Platform.WINDOWS,
            )

        if unicode_filename in (".", ".."):
            return

        if unicode_filename[-1] in (" ", "."):
            raise InvalidCharError(
                self._ERROR_MSG_TEMPLATE.format(
                    invalid=re.escape(unicode_filename[-1]), value=repr(unicode_filename)
                ),
                platform=Platform.WINDOWS,
                description="Do not end a file or directory name with a space or a period",
            )
github thombashi / pathvalidate / pathvalidate / _sqlite.py View on Github external
:param str name: Name to validate.
    :raises pathvalidate.NullNameError: If the ``name`` is empty.
    :raises pathvalidate.InvalidCharError:
        If the ``name`` includes unprintable character(s).
    :raises pathvalidate.InvalidReservedNameError:
        |raises_sqlite_keywords|
        And invalid as a table name.
    :raises pathvalidate.ValidReservedNameError:
        |raises_sqlite_keywords|
        However, valid as a table name.
    """

    validate_null_string(name)

    if __RE_INVALID_CHARS.search(name):
        raise InvalidCharError("unprintable character found")

    if name.upper() in __SQLITE_INVALID_RESERVED_KEYWORDS_TABLE:
        raise InvalidReservedNameError("'{:s}' is a reserved keyword by sqlite".format(name))

    if name.upper() in __SQLITE_VALID_RESERVED_KEYWORDS_TABLE:
        raise ValidReservedNameError("'{:s}' is a reserved keyword by sqlite".format(name))
github thombashi / pathvalidate / pathvalidate / _app.py View on Github external
If the ``sheet_name`` is longer than 31 characters.
    """

    validate_null_string(sheet_name)

    if len(sheet_name) > __MAX_SHEET_NAME_LEN:
        raise InvalidLengthError(
            "sheet name is too long: expected<={:d}, actual={:d}".format(
                __MAX_SHEET_NAME_LEN, len(sheet_name)
            )
        )

    unicode_sheet_name = preprocess(sheet_name)
    match = __RE_INVALID_EXCEL_SHEET_NAME.search(unicode_sheet_name)
    if match is not None:
        raise InvalidCharError(
            "invalid char found in the sheet name: '{:s}'".format(re.escape(match.group()))
        )