summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-09-08 18:11:53 +0000
committerZac Medico <zmedico@gentoo.org>2009-09-08 18:11:53 +0000
commit90ac42dc0dc21eebbd576a1a63fac9e72bdc1f90 (patch)
treec23e44d80cdd68585826e45daa87bd2b69eb94e0 /pym
parentf1479bd0ed1182f4a753e2732f1bf43140951ff0 (diff)
downloadportage-90ac42dc0dc21eebbd576a1a63fac9e72bdc1f90.tar.gz
portage-90ac42dc0dc21eebbd576a1a63fac9e72bdc1f90.tar.bz2
portage-90ac42dc0dc21eebbd576a1a63fac9e72bdc1f90.zip
simplify atom regex (winning even more performance) and turns it in verbose
mode with comments. Added more corner case tests. Thanks to Marat Radchenko <marat@slonopotamus.org> for this patch from bug #276813. svn path=/main/trunk/; revision=14219
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/dep.py24
-rw-r--r--pym/portage/tests/dep/test_isvalidatom.py3
2 files changed, 19 insertions, 8 deletions
diff --git a/pym/portage/dep.py b/pym/portage/dep.py
index 8c3317e67..df082eb70 100644
--- a/pym/portage/dep.py
+++ b/pym/portage/dep.py
@@ -833,32 +833,40 @@ def dep_getusedeps( depend ):
open_bracket = depend.find( '[', open_bracket+1 )
return tuple(use_list)
+# \w is [a-zA-Z0-9_]
+
# 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-].
# It must not begin with a hyphen or a dot.
-_cat = r'[A-Za-z0-9+_][A-Za-z0-9+_.-]*'
+_cat = r'[\w+][\w+.-]*'
# 2.1.2 A package name may contain any of the characters [A-Za-z0-9+_-].
# It must not begin with a hyphen,
# and must not end in a hyphen followed by one or more digits.
-_pkg = r'([A-Za-z+_]+[A-Za-z0-9+_]+|([A-Za-z0-9+_](' + \
- '[A-Za-z0-9+_-]?|' + \
- '([A-Za-z0-9+_-]*(([A-Za-z0-9+_][A-Za-z+_-]+)|([A-Za-z+_][A-Za-z0-9+_]+))))))'
+_pkg = \
+r'''([\w+](
+ -? # All other 2-char are handled by next
+ |[\w+]* # No hyphens - no problems
+ |[\w+-]+( # String with a hyphen...
+ [A-Za-z+_-] # ... must end in nondigit
+ |[A-Za-z+_][\w+]+ # ... or in nondigit and then nonhyphens
+ )
+))'''
# 2.1.3 A slot name may contain any of the characters [A-Za-z0-9+_.-].
# It must not begin with a hyphen or a dot.
-_slot = r'(:[A-Za-z0-9+_][A-Za-z0-9+_.-]*)?'
+_slot = r'(:[\w+][\w+.-]*)?'
_use = r'(\[.*\])?'
-_op = r'([=><~]|([><]=))'
+_op = r'([=~]|[><]=?)'
_cp = _cat + '/' + _pkg
_cpv = _cp + '-' + _version
-_cpv_re = re.compile('^' + _cpv + '$')
+_cpv_re = re.compile('^' + _cpv + '$', re.VERBOSE)
_atom_re = re.compile(r'^(' +
'(' + _op + _cpv + _slot + _use + ')|' +
'(=' + _cpv + r'\*' + _slot + _use + ')|' +
'(' + _cp + _slot + _use + ')' +
- ')$')
+ ')$', re.VERBOSE)
def isvalidatom(atom, allow_blockers=False):
"""
diff --git a/pym/portage/tests/dep/test_isvalidatom.py b/pym/portage/tests/dep/test_isvalidatom.py
index 7797025f9..9fa878e1f 100644
--- a/pym/portage/tests/dep/test_isvalidatom.py
+++ b/pym/portage/tests/dep/test_isvalidatom.py
@@ -78,6 +78,9 @@ class IsValidAtom(TestCase):
( "~games-strategy/ufo2000-0.1", True ),
( "=media-libs/x264-20060810", True ),
( "foo/b", True ),
+ ( "app-text/7plus", True ),
+ ( "foo/666", True ),
+ ( "=dev-libs/poppler-qt3-0.11*", True ),
]
for test in tests: