Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 203406 Details for
Bug 276813
sys-apps/portage Performance improvement
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
implements isvalidatom using regex
regex_isvalidatom.patch (text/plain), 5.26 KB, created by
Marat Radchenko
on 2009-09-07 20:25:43 UTC
(
hide
)
Description:
implements isvalidatom using regex
Filename:
MIME Type:
Creator:
Marat Radchenko
Created:
2009-09-07 20:25:43 UTC
Size:
5.26 KB
patch
obsolete
>diff --git a/pym/portage/dep.py b/pym/portage/dep.py >index 71dc758..5ef169a 100644 >--- a/pym/portage/dep.py >+++ b/pym/portage/dep.py >@@ -3,7 +3,6 @@ > # Distributed under the terms of the GNU General Public License v2 > # $Id$ > >- > # DEPEND SYNTAX: > # > # 'use?' only affects the immediately following word! >@@ -24,7 +23,7 @@ from itertools import chain > import portage.exception > from portage.exception import InvalidData, InvalidAtom > from portage.localization import _ >-from portage.versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify >+from portage.versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify, _version > import portage.cache.mappings > > def cpvequal(cpv1, cpv2): >@@ -309,7 +308,6 @@ def use_reduce(deparray, uselist=[], masklist=[], matchall=0, excludeall=[]): > > return rlist > >- > def dep_opconvert(deplist): > """ > Iterate recursively through a list of deps, if the >@@ -834,94 +832,66 @@ def dep_getusedeps( depend ): > open_bracket = depend.find( '[', open_bracket+1 ) > return tuple(use_list) > >-_valid_category = re.compile("^\w[\w-]*") >-_invalid_atom_chars_regexp = re.compile("[()|@]") >- >+# 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+_.-]*' >+ >+# 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. >+# FIXME: this regex doesn't check 'must not end in' clause. >+_pkg = r'[A-Za-z0-9+_][A-Za-z0-9+_-]*' >+ >+# 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+_.-]*)?' >+ >+_use = r'(\[.*\])?' >+_op = r'([=><~]|([><]=))' >+_cp = _cat + '/' + _pkg >+_cpv = _cp + '-' + _version >+ >+_atom = re.compile(r'^(' + >+ '(' + _op + _cpv + _slot + _use + ')|' + >+ '(=' + _cpv + r'\*' + _slot + _use + ')|' + >+ '(' + _cp + _slot + _use + ')' + >+ ')$') > def isvalidatom(atom, allow_blockers=False): > """ > Check to see if a depend atom is valid > > Example usage: > >>> isvalidatom('media-libs/test-3.0') >- 0 >+ False > >>> isvalidatom('>=media-libs/test-3.0') >- 1 >+ True > > @param atom: The depend atom to check against >- @type atom: String >- @rtype: Integer >+ @type atom: String or Atom >+ @rtype: Boolean > @return: One of the following: >- 1) 0 if the atom is invalid >- 2) 1 if the atom is valid >+ 1) False if the atom is invalid >+ 2) True if the atom is valid > """ > existing_atom = Atom._atoms.get(atom) > if existing_atom is not None: > atom = existing_atom > if isinstance(atom, Atom): >- if atom.blocker and not allow_blockers: >- return 0 >- return 1 >- global _invalid_atom_chars_regexp >- if _invalid_atom_chars_regexp.search(atom): >- return 0 >- if allow_blockers and atom[:1] == "!": >- if atom[1:2] == "!": >+ return allow_blockers or not atom.blocker >+ if allow_blockers and atom[0] == '!': >+ if atom[1] == '!': > atom = atom[2:] > else: > atom = atom[1:] >- >- if dep_getslot(atom) == "": >- # empty slot is invalid (None is valid) >- return 0 >- >+ if not _atom.match(atom): >+ return False > try: > use = dep_getusedeps(atom) > if use: > use = _use_dep(use) >+ return True > except InvalidAtom: >- return 0 >- >- cpv = dep_getcpv(atom) >- cpv_catsplit = catsplit(cpv) >- without_slot = remove_slot(atom) >- mycpv_cps = None >- if cpv: >- if len(cpv_catsplit) == 2: >- if _valid_category.match(cpv_catsplit[0]) is None: >- return 0 >- if cpv_catsplit[0] == "null": >- # "null" category is valid, missing category is not. >- mycpv_cps = catpkgsplit(cpv.replace("null/", "cat/", 1)) >- if mycpv_cps: >- mycpv_cps = list(mycpv_cps) >- mycpv_cps[0] = "null" >- if not mycpv_cps: >- mycpv_cps = catpkgsplit(cpv) >- if mycpv_cps is None and cpv != without_slot: >- return 0 >- >- operator = get_operator(atom) >- if operator: >- if operator[0] in "<>" and without_slot[-1:] == "*": >- return 0 >- if mycpv_cps: >- if len(cpv_catsplit) == 2: >- # >=cat/pkg-1.0 >- return 1 >- else: >- return 0 >- else: >- # >=cat/pkg or >=pkg-1.0 (no category) >- return 0 >- if mycpv_cps: >- # cat/pkg-1.0 >- return 0 >- >- if len(cpv_catsplit) == 2: >- # cat/pkg >- return 1 >- else: >- return 0 >+ return False > > def isjustname(mypkg): > """ >diff --git a/pym/portage/tests/dep/test_isvalidatom.py b/pym/portage/tests/dep/test_isvalidatom.py >index e74ec8f..3535f3d 100644 >--- a/pym/portage/tests/dep/test_isvalidatom.py >+++ b/pym/portage/tests/dep/test_isvalidatom.py >@@ -69,6 +69,7 @@ class IsValidAtom(TestCase): > ( "=foo/bar-baz---1-r1", True ), > ( "=foo/bar-baz---1", True ), > ( "=foo/bar-baz-1--r1", False ), >+ ( "~foo/bar-1-0.5", False ), > ] > > for test in tests: >diff --git a/pym/portage/versions.py b/pym/portage/versions.py >index f434ff7..20cdfc2 100644 >--- a/pym/portage/versions.py >+++ b/pym/portage/versions.py >@@ -5,7 +5,9 @@ > > import re > >-ver_regexp = re.compile("^(cvs\\.)?(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$") >+_version = r'(cvs\.)?(\d+)((\.\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\d*)*)(-r(\d+))?' >+ >+ver_regexp = re.compile("^" + _version + "$") > suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$") > suffix_value = {"pre": -2, "p": 0, "alpha": -4, "beta": -3, "rc": -1} > endversion_keys = ["pre", "p", "alpha", "beta", "rc"]
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 276813
:
196987
|
197434
|
197437
|
197827
|
198253
|
203267
|
203269
|
203406
|
203509
|
203512
|
203515
|
203519
|
204572
|
204597
|
204673
|
204685
|
204770
|
204883
|
204996
|
205039