[AIRFLOW-3990] Compile regular expressions. (#4813)
This commit is contained in:
Родитель
3e29f05fae
Коммит
717ddaf737
|
@ -304,7 +304,7 @@ def list_py_file_paths(directory, safe_mode=True,
|
|||
with open(ignore_file, 'r') as f:
|
||||
# If we have new patterns create a copy so we don't change
|
||||
# the previous list (which would affect other subdirs)
|
||||
patterns = patterns + [p for p in f.read().split('\n') if p]
|
||||
patterns += [re.compile(p) for p in f.read().split('\n') if p]
|
||||
|
||||
# If we can ignore any subdirs entirely we should - fewer paths
|
||||
# to walk is better. We have to modify the ``dirs`` array in
|
||||
|
@ -312,7 +312,7 @@ def list_py_file_paths(directory, safe_mode=True,
|
|||
dirs[:] = [
|
||||
d
|
||||
for d in dirs
|
||||
if not any(re.search(p, os.path.join(root, d)) for p in patterns)
|
||||
if not any(p.search(os.path.join(root, d)) for p in patterns)
|
||||
]
|
||||
|
||||
# We want patterns defined in a parent folder's .airflowignore to
|
||||
|
|
|
@ -45,6 +45,8 @@ DEFAULT_TIME_TO_WAIT_AFTER_SIGTERM = configuration.conf.getint(
|
|||
'core', 'KILLED_TASK_CLEANUP_TIME'
|
||||
)
|
||||
|
||||
KEY_REGEX = re.compile(r'^[\w\-\.]+$')
|
||||
|
||||
|
||||
def validate_key(k, max_length=250):
|
||||
if not isinstance(k, basestring):
|
||||
|
@ -52,7 +54,7 @@ def validate_key(k, max_length=250):
|
|||
elif len(k) > max_length:
|
||||
raise AirflowException(
|
||||
"The key has to be less than {0} characters".format(max_length))
|
||||
elif not re.match(r'^[A-Za-z0-9_\-\.]+$', k):
|
||||
elif not KEY_REGEX.match(k):
|
||||
raise AirflowException(
|
||||
"The key ({k}) has to be made of alphanumeric characters, dashes, "
|
||||
"dots and underscores exclusively".format(**locals()))
|
||||
|
|
|
@ -209,6 +209,9 @@ def json_response(obj):
|
|||
mimetype="application/json")
|
||||
|
||||
|
||||
ZIP_REGEX = re.compile(r'((.*\.zip){})?(.*)'.format(re.escape(os.sep)))
|
||||
|
||||
|
||||
def open_maybe_zipped(f, mode='r'):
|
||||
"""
|
||||
Opens the given file. If the path contains a folder with a .zip suffix, then
|
||||
|
@ -217,8 +220,7 @@ def open_maybe_zipped(f, mode='r'):
|
|||
:return: a file object, as in `open`, or as in `ZipFile.open`.
|
||||
"""
|
||||
|
||||
_, archive, filename = re.search(
|
||||
r'((.*\.zip){})?(.*)'.format(re.escape(os.sep)), f).groups()
|
||||
_, archive, filename = ZIP_REGEX.search(f).groups()
|
||||
if archive and zipfile.is_zipfile(archive):
|
||||
return zipfile.ZipFile(archive, mode=mode).open(filename)
|
||||
else:
|
||||
|
|
Загрузка…
Ссылка в новой задаче