[entropy.tools] add is_valid_package_tag function

This commit is contained in:
Fabio Erculiani
2010-03-30 14:27:53 +02:00
parent 622c534350
commit a17aa4830f
2 changed files with 25 additions and 0 deletions
+17
View File
@@ -2116,6 +2116,23 @@ def compare_versions(ver1, ver2):
r2 = 0
return r1 - r2
tag_regexp = re.compile("^([A-Za-z0-9+_.-]+)?$")
def is_valid_package_tag(dep):
"""
docstring_title
@param dep:
@type dep:
@return:
@rtype:
"""
match = tag_regexp.match(dep)
if not match:
return False
if not match.groups():
return False
return True
def entropy_compare_package_tags(tag_a, tag_b):
"""
Compare two Entropy package tags using builtin cmp().
+8
View File
@@ -113,6 +113,14 @@ class ToolsTest(unittest.TestCase):
self.assert_(not et.is_valid_ascii(non_valid))
def test_valid_package_tag(self):
valid = "ciao"
invalids = ["òpl", "hello,hello", "#hello"]
self.assert_(et.is_valid_package_tag(valid))
for invalid in invalids:
self.assert_(not et.is_valid_package_tag(invalid))
def test_is_valid_unicode(self):
valid = "ciao"
valid2 = const_convert_to_unicode("òèàò", 'utf-8')