From b2b740167cfb5f4359aecbf114deb5ff1af73b04 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Tue, 4 Jun 2019 10:23:48 +0100 Subject: _loader/loader: cythonize valid_chars_name - Create a new _loader/utils.pyx cython module for functions cythonized in the loader module. - Move valid_chars_name from loader to utils and cythonize. This function is called extensively, and easy to extract --- src/buildstream/_loader/loader.py | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'src/buildstream/_loader/loader.py') diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py index 752883d96..5435e0d41 100644 --- a/src/buildstream/_loader/loader.py +++ b/src/buildstream/_loader/loader.py @@ -27,6 +27,7 @@ from ..element import Element from .._profile import Topics, PROFILER from .._includes import Includes +from ._loader import valid_chars_name from .types import Symbol from .loadelement import LoadElement, _extract_depends_from_node from .metaelement import MetaElement @@ -759,7 +760,7 @@ class Loader(): for filename in elements: if not filename.endswith(".bst"): invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX].append(filename) - if not self._valid_chars_name(filename): + if not valid_chars_name(filename): invalid_elements[CoreWarnings.BAD_CHARACTERS_IN_NAME].append(filename) if invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX]: @@ -771,33 +772,3 @@ class Loader(): self._warn("Target elements '{}' have invalid characerts in their name." .format(invalid_elements[CoreWarnings.BAD_CHARACTERS_IN_NAME]), warning_token=CoreWarnings.BAD_CHARACTERS_IN_NAME) - - # Check if given filename containers valid characters. - # - # Args: - # name (str): Name of the file - # - # Returns: - # (bool): True if all characters are valid, False otherwise. - # - def _valid_chars_name(self, name): - for char in name: - char_val = ord(char) - - # 0-31 are control chars, 127 is DEL, and >127 means non-ASCII - if char_val <= 31 or char_val >= 127: - return False - - # Disallow characters that are invalid on Windows. The list can be - # found at https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file - # - # Note that although : (colon) is not allowed, we do not raise - # warnings because of that, since we use it as a separator for - # junctioned elements. - # - # We also do not raise warnings on slashes since they are used as - # path separators. - if char in r'<>"|?*': - return False - - return True -- cgit v1.2.1