[entropy.tools] add is_valid_package_tag function
This commit is contained in:
@@ -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().
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user