summaryrefslogtreecommitdiff
path: root/src/buildstream/_loader/loader.py
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-04 10:23:48 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-06-05 15:15:23 +0000
commitb2b740167cfb5f4359aecbf114deb5ff1af73b04 (patch)
tree299d3644228df9dc1ef104e13eee46543b485380 /src/buildstream/_loader/loader.py
parent246571606853aef6da856d778f783b14339a2cea (diff)
downloadbuildstream-b2b740167cfb5f4359aecbf114deb5ff1af73b04.tar.gz
_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
Diffstat (limited to 'src/buildstream/_loader/loader.py')
-rw-r--r--src/buildstream/_loader/loader.py33
1 files changed, 2 insertions, 31 deletions
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