From c35b50fadc448d7a1222bec10ad8979bd77893cd Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 26 Feb 2011 17:53:13 +0100 Subject: [PATCH] [entropy.tools] introduce validate_repository_id() --- libraries/entropy/tools.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index 25e4123ba..935b827df 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -2382,6 +2382,20 @@ def expand_plain_package_mirror(mirror, product, repository_id): return None return mirror + os.path.sep + product + os.path.sep + repository_id +_repo_re = re.compile("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$", re.IGNORECASE) +def validate_repository_id(repository_id): + """ + Validate Entropy repository identifier string. + + @param repository_id: entropy repository identifier + @type repository_id: string + @return: True if repository_id is a valid string, False otherwise + @rtype: bool + """ + if _repo_re.match(repository_id): + return True + return False + def is_entropy_package_file(entropy_package_path): """ Determine whether given package path is a valid Entropy package file.