* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/
@ 2012-05-12 9:38 Zac Medico
0 siblings, 0 replies; 4+ messages in thread
From: Zac Medico @ 2012-05-12 9:38 UTC (permalink / raw
To: gentoo-commits
commit: f75f2f3169a63e8b39cea1087e099e176d90e20e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat May 12 09:25:39 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat May 12 09:32:31 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f75f2f31
Add a _pkg_str class to cache catpkgsplit results
This will compensate for the removal of the catpkgsplit cache in commit
68888b0450b1967cb70673a5f06b04c167ef879c.
---
pym/_emerge/BlockerCache.py | 7 ++++-
pym/portage/dbapi/bintree.py | 6 +++-
pym/portage/dbapi/porttree.py | 4 +-
pym/portage/dbapi/vartree.py | 12 +++++++---
pym/portage/dep/__init__.py | 8 +++++-
pym/portage/versions.py | 44 ++++++++++++++++++++++++++++++++++++++++-
6 files changed, 68 insertions(+), 13 deletions(-)
diff --git a/pym/_emerge/BlockerCache.py b/pym/_emerge/BlockerCache.py
index 06598a4..3ec63ce 100644
--- a/pym/_emerge/BlockerCache.py
+++ b/pym/_emerge/BlockerCache.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import errno
@@ -16,6 +16,9 @@ except ImportError:
if sys.hexversion >= 0x3000000:
basestring = str
long = int
+ _unicode = str
+else:
+ _unicode = unicode
class BlockerCache(portage.cache.mappings.MutableMapping):
"""This caches blockers of installed packages so that dep_check does not
@@ -159,7 +162,7 @@ class BlockerCache(portage.cache.mappings.MutableMapping):
@param blocker_data: An object with counter and atoms attributes.
@type blocker_data: BlockerData
"""
- self._cache_data["blockers"][cpv] = \
+ self._cache_data["blockers"][_unicode(cpv)] = \
(blocker_data.counter, tuple(str(x) for x in blocker_data.atoms))
self._modified.add(cpv)
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index 810163d..52b85b8 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -16,7 +16,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.util:atomic_ofstream,ensure_dirs,normalize_path,' + \
'writemsg,writemsg_stdout',
'portage.util.listdir:listdir',
- 'portage.versions:best,catpkgsplit,catsplit',
+ 'portage.versions:best,catpkgsplit,catsplit,_pkg_str',
)
from portage.cache.mappings import slot_dict_class
@@ -236,7 +236,7 @@ def _pkgindex_cpv_map_latest_build(pkgindex):
if other_btime and (not btime or other_btime > btime):
continue
- cpv_map[cpv] = d
+ cpv_map[_pkg_str(cpv)] = d
return cpv_map
@@ -658,6 +658,7 @@ class binarytree(object):
if mycpv in pkg_paths:
# discard duplicates (All/ is preferred)
continue
+ mycpv = _pkg_str(mycpv)
pkg_paths[mycpv] = mypath
# update the path if the package has been moved
oldpath = d.get("PATH")
@@ -733,6 +734,7 @@ class binarytree(object):
(mycpv, self.settings["PORTAGE_CONFIGROOT"]),
noiselevel=-1)
continue
+ mycpv = _pkg_str(mycpv)
pkg_paths[mycpv] = mypath
self.dbapi.cpv_inject(mycpv)
update_pkgindex = True
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
index f348a15..663b62d 100644
--- a/pym/portage/dbapi/porttree.py
+++ b/pym/portage/dbapi/porttree.py
@@ -14,7 +14,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.package.ebuild.doebuild:doebuild',
'portage.util:ensure_dirs,shlex_split,writemsg,writemsg_level',
'portage.util.listdir:listdir',
- 'portage.versions:best,catpkgsplit,_pkgsplit@pkgsplit,ver_regexp',
+ 'portage.versions:best,catpkgsplit,_pkgsplit@pkgsplit,ver_regexp,_pkg_str',
)
from portage.cache import volatile
@@ -708,7 +708,7 @@ class portdbapi(dbapi):
writemsg(_("\nInvalid ebuild version: %s\n") % \
os.path.join(oroot, mycp, x), noiselevel=-1)
continue
- d[mysplit[0]+"/"+pf] = None
+ d[_pkg_str(mysplit[0]+"/"+pf)] = None
if invalid_category and d:
writemsg(_("\n!!! '%s' has a category that is not listed in " \
"%setc/portage/categories\n") % \
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 158fc4a..fe352c5 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -31,7 +31,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry',
'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap',
'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,pkgcmp,' + \
- '_pkgsplit@pkgsplit',
+ '_pkgsplit@pkgsplit,_pkg_str',
'subprocess',
'tarfile',
)
@@ -87,6 +87,9 @@ except ImportError:
if sys.hexversion >= 0x3000000:
basestring = str
long = int
+ _unicode = str
+else:
+ _unicode = unicode
class vardbapi(dbapi):
@@ -386,7 +389,7 @@ class vardbapi(dbapi):
continue
if len(mysplit) > 1:
if ps[0] == mysplit[1]:
- returnme.append(mysplit[0]+"/"+x)
+ returnme.append(_pkg_str(mysplit[0]+"/"+x))
self._cpv_sort_ascending(returnme)
if use_cache:
self.cpcache[mycp] = [mystat, returnme[:]]
@@ -680,7 +683,8 @@ class vardbapi(dbapi):
cache_data.update(metadata)
for aux_key in cache_these:
cache_data[aux_key] = mydata[aux_key]
- self._aux_cache["packages"][mycpv] = (mydir_mtime, cache_data)
+ self._aux_cache["packages"][_unicode(mycpv)] = \
+ (mydir_mtime, cache_data)
self._aux_cache["modified"].add(mycpv)
if _slot_re.match(mydata['SLOT']) is None:
@@ -1059,7 +1063,7 @@ class vardbapi(dbapi):
counter = int(counter)
except ValueError:
counter = 0
- return (cpv, counter, mtime)
+ return (_unicode(cpv), counter, mtime)
class _owners_db(object):
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index 2e3444d..de8d1c4 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -43,7 +43,7 @@ from portage.eapi import eapi_has_slot_deps, eapi_has_src_uri_arrows, \
from portage.exception import InvalidAtom, InvalidData, InvalidDependString
from portage.localization import _
from portage.versions import catpkgsplit, catsplit, \
- pkgcmp, vercmp, ververify, _cp, _cpv
+ pkgcmp, vercmp, ververify, _cp, _cpv, _pkg_str
import portage.cache.mappings
if sys.hexversion >= 0x3000000:
@@ -1137,7 +1137,11 @@ class Atom(_atom_base):
else:
raise AssertionError(_("required group not found in atom: '%s'") % self)
self.__dict__['cp'] = cp
- self.__dict__['cpv'] = cpv
+ try:
+ self.__dict__['cpv'] = _pkg_str(cpv)
+ except InvalidData:
+ # plain cp, wildcard, or something
+ self.__dict__['cpv'] = cpv
self.__dict__['repo'] = repo
self.__dict__['slot'] = slot
self.__dict__['operator'] = op
diff --git a/pym/portage/versions.py b/pym/portage/versions.py
index e2761b5..de2fe70 100644
--- a/pym/portage/versions.py
+++ b/pym/portage/versions.py
@@ -9,13 +9,21 @@ __all__ = [
]
import re
+import sys
import warnings
+if sys.hexversion < 0x3000000:
+ _unicode = unicode
+else:
+ _unicode = str
+
import portage
portage.proxy.lazyimport.lazyimport(globals(),
'portage.util:cmp_sort_key'
)
+from portage import _unicode_decode
from portage.eapi import eapi_allows_dots_in_PN
+from portage.exception import InvalidData
from portage.localization import _
# \w is [a-zA-Z0-9_]
@@ -303,7 +311,10 @@ def catpkgsplit(mydata, silent=1, eapi=None):
2. If cat is not specificed in mydata, cat will be "null"
3. if rev does not exist it will be '-r0'
"""
-
+ try:
+ return mydata.cpv_split
+ except AttributeError:
+ pass
mysplit = mydata.split('/', 1)
p_split=None
if len(mysplit)==1:
@@ -318,6 +329,33 @@ def catpkgsplit(mydata, silent=1, eapi=None):
retval = (cat, p_split[0], p_split[1], p_split[2])
return retval
+class _pkg_str(_unicode):
+ """
+ This class represents a cpv. It inherits from str (unicode in python2) and
+ has attributes that cache results for use by functions like catpkgsplit and
+ cpv_getkey which are called frequently (especially in match_from_list).
+ Instances are typically created in dbapi.cp_list() or the Atom contructor,
+ and propagate from there. Generally, code that pickles these objects will
+ manually convert them to a plain unicode object first.
+ """
+
+ def __new__(cls, cpv, eapi=None):
+ return _unicode.__new__(cls, cpv)
+
+ def __init__(self, cpv, eapi=None):
+ if not isinstance(cpv, _unicode):
+ # Avoid TypeError from _unicode.__init__ with PyPy.
+ cpv = _unicode_decode(cpv)
+ _unicode.__init__(cpv)
+ self.__dict__['cpv_split'] = catpkgsplit(cpv, eapi=eapi)
+ if self.cpv_split is None:
+ raise InvalidData(cpv)
+ self.__dict__['cp'] = self.cpv_split[0] + '/' + self.cpv_split[1]
+
+ def __setattr__(self, name, value):
+ raise AttributeError("_pkg_str instances are immutable",
+ self.__class__, name, value)
+
def pkgsplit(mypkg, silent=1, eapi=None):
"""
@param mypkg: either a pv or cpv
@@ -337,6 +375,10 @@ def pkgsplit(mypkg, silent=1, eapi=None):
def cpv_getkey(mycpv, eapi=None):
"""Calls catpkgsplit on a cpv and returns only the cp."""
+ try:
+ return mycpv.cp
+ except AttributeError:
+ pass
mysplit = catpkgsplit(mycpv, eapi=eapi)
if mysplit is not None:
return mysplit[0] + '/' + mysplit[1]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/
@ 2012-05-13 8:36 Zac Medico
0 siblings, 0 replies; 4+ messages in thread
From: Zac Medico @ 2012-05-13 8:36 UTC (permalink / raw
To: gentoo-commits
commit: f31320b67c9f593a2a8592e1a4e547f5f641943a
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May 13 08:36:25 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May 13 08:36:25 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f31320b6
_pkg_str: add version attribute for comparisons
This attribute can be passed directly into vercmp, avoiding the need to
generate this string many times.
---
pym/_emerge/Package.py | 14 +++++++-------
pym/portage/dbapi/__init__.py | 14 +++++++-------
pym/portage/dbapi/virtual.py | 10 ++++++++--
pym/portage/dep/__init__.py | 18 +++++++++++-------
pym/portage/versions.py | 1 +
5 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
index 69739ac..84a2cbc 100644
--- a/pym/_emerge/Package.py
+++ b/pym/_emerge/Package.py
@@ -28,7 +28,7 @@ class Package(Task):
"root_config", "type_name",
"category", "counter", "cp", "cpv_split",
"inherited", "invalid", "iuse", "masks", "mtime",
- "pf", "pv_split", "root", "slot", "slot_atom", "visible",) + \
+ "pf", "root", "slot", "slot_atom", "version", "visible",) + \
("_raw_metadata", "_use",)
metadata_keys = [
@@ -71,8 +71,8 @@ class Package(Task):
"IUSE contains defaults, but EAPI doesn't allow them")
self.slot_atom = portage.dep.Atom("%s%s%s" % (self.cp, _slot_separator, slot))
self.category, self.pf = portage.catsplit(self.cpv)
- self.cpv_split = portage.catpkgsplit(self.cpv)
- self.pv_split = self.cpv_split[1:]
+ self.cpv_split = self.cpv.cpv_split
+ self.version = self.cpv.version
if self.inherited is None:
self.inherited = frozenset()
@@ -532,28 +532,28 @@ class Package(Task):
def __lt__(self, other):
if other.cp != self.cp:
return False
- if portage.pkgcmp(self.pv_split, other.pv_split) < 0:
+ if portage.vercmp(self.version, other.version) < 0:
return True
return False
def __le__(self, other):
if other.cp != self.cp:
return False
- if portage.pkgcmp(self.pv_split, other.pv_split) <= 0:
+ if portage.vercmp(self.version, other.version) <= 0:
return True
return False
def __gt__(self, other):
if other.cp != self.cp:
return False
- if portage.pkgcmp(self.pv_split, other.pv_split) > 0:
+ if portage.vercmp(self.version, other.version) > 0:
return True
return False
def __ge__(self, other):
if other.cp != self.cp:
return False
- if portage.pkgcmp(self.pv_split, other.pv_split) >= 0:
+ if portage.vercmp(self.version, other.version) >= 0:
return True
return False
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
index a835d4d..7a4c823 100644
--- a/pym/portage/dbapi/__init__.py
+++ b/pym/portage/dbapi/__init__.py
@@ -46,7 +46,12 @@ class dbapi(object):
def cp_list(self, cp, use_cache=1):
raise NotImplementedError(self)
- def _cpv_sort_ascending(self, cpv_list):
+ @staticmethod
+ def _cmp_cpv(cpv1, cpv2):
+ return vercmp(cpv1.version, cpv2.version)
+
+ @staticmethod
+ def _cpv_sort_ascending(cpv_list):
"""
Use this to sort self.cp_list() results in ascending
order. It sorts in place and returns None.
@@ -55,12 +60,7 @@ class dbapi(object):
# If the cpv includes explicit -r0, it has to be preserved
# for consistency in findname and aux_get calls, so use a
# dict to map strings back to their original values.
- ver_map = {}
- for cpv in cpv_list:
- ver_map[cpv] = '-'.join(catpkgsplit(cpv)[2:])
- def cmp_cpv(cpv1, cpv2):
- return vercmp(ver_map[cpv1], ver_map[cpv2])
- cpv_list.sort(key=cmp_sort_key(cmp_cpv))
+ cpv_list.sort(key=cmp_sort_key(dbapi._cmp_cpv))
def cpv_all(self):
"""Return all CPVs in the db
diff --git a/pym/portage/dbapi/virtual.py b/pym/portage/dbapi/virtual.py
index 84b6b93..da15983 100644
--- a/pym/portage/dbapi/virtual.py
+++ b/pym/portage/dbapi/virtual.py
@@ -4,7 +4,7 @@
from portage.dbapi import dbapi
from portage.dbapi.dep_expand import dep_expand
-from portage import cpv_getkey
+from portage.versions import cpv_getkey, _pkg_str
class fakedbapi(dbapi):
"""A fake dbapi that allows consumers to inject/remove packages to/from it
@@ -74,7 +74,13 @@ class fakedbapi(dbapi):
@param metadata: dict
"""
self._clear_cache()
- mycp = cpv_getkey(mycpv)
+ if not hasattr(mycpv, 'cp'):
+ if metadata is None:
+ mycpv = _pkg_str(mycpv)
+ else:
+ mycpv = _pkg_str(mycpv, slot=metadata.get('SLOT'),
+ repo=metadata.get('repository'))
+ mycp = mycpv.cp
self.cpvdict[mycpv] = metadata
myslot = None
if self._exclusive_slots and metadata:
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index d4888e0..240e223 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -1141,9 +1141,11 @@ class Atom(_atom_base):
self.__dict__['cp'] = cp
try:
self.__dict__['cpv'] = _pkg_str(cpv)
+ self.__dict__['version'] = self.cpv.version
except InvalidData:
# plain cp, wildcard, or something
self.__dict__['cpv'] = cpv
+ self.__dict__['version'] = None
self.__dict__['repo'] = repo
self.__dict__['slot'] = slot
self.__dict__['operator'] = op
@@ -2003,15 +2005,17 @@ def match_from_list(mydep, candidate_list):
mylist.append(x)
elif operator in [">", ">=", "<", "<="]:
- mysplit = ["%s/%s" % (cat, pkg), ver, rev]
for x in candidate_list:
- xs = getattr(x, "cpv_split", None)
- if xs is None:
- xs = catpkgsplit(remove_slot(x))
- xcat, xpkg, xver, xrev = xs
- xs = ["%s/%s" % (xcat, xpkg), xver, xrev]
+ if not hasattr(x, 'cp'):
+ try:
+ x = _pkg_str(remove_slot(x))
+ except InvalidData:
+ continue
+
+ if x.cp != mydep.cp:
+ continue
try:
- result = pkgcmp(xs, mysplit)
+ result = vercmp(x.version, mydep.version)
except ValueError: # pkgcmp may return ValueError during int() conversion
writemsg(_("\nInvalid package name: %s\n") % x, noiselevel=-1)
raise
diff --git a/pym/portage/versions.py b/pym/portage/versions.py
index 33c7159..35385e4 100644
--- a/pym/portage/versions.py
+++ b/pym/portage/versions.py
@@ -351,6 +351,7 @@ class _pkg_str(_unicode):
if self.cpv_split is None:
raise InvalidData(cpv)
self.__dict__['cp'] = self.cpv_split[0] + '/' + self.cpv_split[1]
+ self.__dict__['version'] = "-".join(self.cpv_split[2:])
# for match_from_list introspection
self.__dict__['cpv'] = self
if slot is not None:
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/
@ 2012-05-13 23:40 Zac Medico
0 siblings, 0 replies; 4+ messages in thread
From: Zac Medico @ 2012-05-13 23:40 UTC (permalink / raw
To: gentoo-commits
commit: 528990c3279dcb2b37062f447cfda80730ead6b7
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May 13 23:40:29 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May 13 23:40:29 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=528990c3
_pkg_str: validate repo (move code from Package)
---
pym/_emerge/Package.py | 17 +++++++----------
pym/portage/dbapi/__init__.py | 2 --
pym/portage/dep/__init__.py | 4 +---
pym/portage/versions.py | 8 +++++++-
4 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py
index 84a2cbc..c04fa1f 100644
--- a/pym/_emerge/Package.py
+++ b/pym/_emerge/Package.py
@@ -8,12 +8,10 @@ from portage import _encodings, _unicode_decode, _unicode_encode
from portage.cache.mappings import slot_dict_class
from portage.const import EBUILD_PHASES
from portage.dep import Atom, check_required_use, use_reduce, \
- paren_enclose, _slot_re, _slot_separator, _repo_separator, \
- _unknown_repo
-from portage.versions import _pkg_str
+ paren_enclose, _slot_re, _slot_separator, _repo_separator
+from portage.versions import _pkg_str, _unknown_repo
from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
from portage.exception import InvalidDependString
-from portage.repository.config import _gen_valid_repo
from _emerge.Task import Task
if sys.hexversion >= 0x3000000:
@@ -58,12 +56,11 @@ class Package(Task):
# Avoid an InvalidAtom exception when creating slot_atom.
# This package instance will be masked due to empty SLOT.
slot = '0'
- repo = _gen_valid_repo(self.metadata.get('repository', ''))
- if not repo:
- repo = self.UNKNOWN_REPO
- self.metadata['repository'] = repo
- self.cpv = _pkg_str(self.cpv, slot=slot, repo=repo)
+ self.cpv = _pkg_str(self.cpv, slot=slot,
+ repo=self.metadata.get('repository', ''))
self.cp = self.cpv.cp
+ # sync metadata with validated repo (may be UNKNOWN_REPO)
+ self.metadata['repository'] = self.cpv.repo
if (self.iuse.enabled or self.iuse.disabled) and \
not eapi_has_iuse_defaults(self.metadata["EAPI"]):
if not self.installed:
@@ -87,7 +84,7 @@ class Package(Task):
self._hash_key = Package._gen_hash_key(cpv=self.cpv,
installed=self.installed, onlydeps=self.onlydeps,
- operation=self.operation, repo_name=repo,
+ operation=self.operation, repo_name=self.cpv.repo,
root_config=self.root_config,
type_name=self.type_name)
self._hash_value = hash(self._hash_key)
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
index 7a4c823..a1c5c56 100644
--- a/pym/portage/dbapi/__init__.py
+++ b/pym/portage/dbapi/__init__.py
@@ -160,8 +160,6 @@ class dbapi(object):
try:
metadata = dict(zip(aux_keys,
self.aux_get(cpv, aux_keys, myrepo=atom.repo)))
- if not metadata["repository"]:
- del metadata["repository"]
except KeyError:
continue
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index 3838217..55ed481 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -43,7 +43,7 @@ from portage.eapi import eapi_has_slot_deps, eapi_has_src_uri_arrows, \
from portage.exception import InvalidAtom, InvalidData, InvalidDependString
from portage.localization import _
from portage.versions import catpkgsplit, catsplit, \
- pkgcmp, vercmp, ververify, _cp, _cpv, _pkg_str
+ vercmp, ververify, _cp, _cpv, _pkg_str, _unknown_repo
import portage.cache.mappings
if sys.hexversion >= 0x3000000:
@@ -54,8 +54,6 @@ if sys.hexversion >= 0x3000000:
# stable keywords, make these warnings unconditional.
_internal_warnings = False
-_unknown_repo = "__unknown__"
-
def cpvequal(cpv1, cpv2):
"""
diff --git a/pym/portage/versions.py b/pym/portage/versions.py
index 298b7aa..db14e99 100644
--- a/pym/portage/versions.py
+++ b/pym/portage/versions.py
@@ -19,13 +19,16 @@ else:
import portage
portage.proxy.lazyimport.lazyimport(globals(),
- 'portage.util:cmp_sort_key'
+ 'portage.repository.config:_gen_valid_repo',
+ 'portage.util:cmp_sort_key',
)
from portage import _unicode_decode
from portage.eapi import eapi_allows_dots_in_PN
from portage.exception import InvalidData
from portage.localization import _
+_unknown_repo = "__unknown__"
+
# \w is [a-zA-Z0-9_]
# 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-].
@@ -347,6 +350,9 @@ class _pkg_str(_unicode):
if slot is not None:
self.__dict__['slot'] = slot
if repo is not None:
+ repo = _gen_valid_repo(repo)
+ if not repo:
+ repo = _unknown_repo
self.__dict__['repo'] = repo
def __setattr__(self, name, value):
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/
@ 2012-09-22 22:05 Zac Medico
0 siblings, 0 replies; 4+ messages in thread
From: Zac Medico @ 2012-09-22 22:05 UTC (permalink / raw
To: gentoo-commits
commit: 0d5b0fbd79ba8b2e7dd5d2f2db7d69cad3e56766
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Sep 22 21:52:35 2012 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Sep 22 22:05:31 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0d5b0fbd
Use re.UNICODE for category/package name regexes.
This only affects r'\w' with Python 2.x, since Python 3 already
defaults to re.UNICODE behavior when compiling unicode str objects
(unless re.ASCII is specified). If a repository wants to ban unicode
categore/package names then we can add a layout.conf setting for that,
as discussed in bug #435934.
---
pym/_emerge/is_valid_package_atom.py | 4 ++--
pym/portage/dbapi/__init__.py | 2 +-
pym/portage/dep/__init__.py | 10 +++++-----
pym/portage/manifest.py | 16 +++++++++++++++-
pym/portage/versions.py | 4 ++--
5 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/pym/_emerge/is_valid_package_atom.py b/pym/_emerge/is_valid_package_atom.py
index 7cb2a5b..a1e4294 100644
--- a/pym/_emerge/is_valid_package_atom.py
+++ b/pym/_emerge/is_valid_package_atom.py
@@ -1,11 +1,11 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import re
from portage.dep import isvalidatom
def insert_category_into_atom(atom, category):
- alphanum = re.search(r'\w', atom)
+ alphanum = re.search(r'\w', atom, re.UNICODE)
if alphanum:
ret = atom[:alphanum.start()] + "%s/" % category + \
atom[alphanum.start():]
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
index ad22f39..fc7c7eb 100644
--- a/pym/portage/dbapi/__init__.py
+++ b/pym/portage/dbapi/__init__.py
@@ -21,7 +21,7 @@ from portage.exception import InvalidData
from portage.localization import _
class dbapi(object):
- _category_re = re.compile(r'^\w[-.+\w]*$')
+ _category_re = re.compile(r'^\w[-.+\w]*$', re.UNICODE)
_categories = None
_use_mutable = False
_known_keys = frozenset(x for x in auxdbkeys
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index b4b240d..6e03004 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -72,7 +72,7 @@ def _get_slot_re(eapi_attrs):
else:
slot_re = _slot
- slot_re = re.compile('^' + slot_re + '$', re.VERBOSE)
+ slot_re = re.compile('^' + slot_re + '$', re.VERBOSE | re.UNICODE)
_slot_re_cache[cache_key] = slot_re
return slot_re
@@ -90,7 +90,7 @@ def _get_slot_dep_re(eapi_attrs):
else:
slot_re = _slot
- slot_re = re.compile('^' + slot_re + '$', re.VERBOSE)
+ slot_re = re.compile('^' + slot_re + '$', re.VERBOSE | re.UNICODE)
_slot_dep_re_cache[cache_key] = slot_re
return slot_re
@@ -123,7 +123,7 @@ def _get_atom_re(eapi_attrs):
'(?P<star>=' + cpv_re + r'\*)|' +
'(?P<simple>' + cp_re + '))' +
'(' + _slot_separator + _slot_loose + ')?' +
- _repo + ')(' + _use + ')?$', re.VERBOSE)
+ _repo + ')(' + _use + ')?$', re.VERBOSE | re.UNICODE)
_atom_re_cache[cache_key] = atom_re
return atom_re
@@ -145,7 +145,7 @@ def _get_atom_wildcard_re(eapi_attrs):
_extended_cat + r')/(' + pkg_re + r'))' + \
'|(?P<star>=((' + _extended_cat + r')/(' + pkg_re + r'))-(?P<version>\*\d+\*)))' + \
'(:(?P<slot>' + _slot_loose + r'))?(' +
- _repo_separator + r'(?P<repo>' + _repo_name + r'))?$')
+ _repo_separator + r'(?P<repo>' + _repo_name + r'))?$', re.UNICODE)
_atom_wildcard_re_cache[cache_key] = atom_re
return atom_re
@@ -1585,7 +1585,7 @@ def extended_cp_match(extended_cp, other_cp):
extended_cp_re = _extended_cp_re_cache.get(extended_cp)
if extended_cp_re is None:
extended_cp_re = re.compile("^" + re.escape(extended_cp).replace(
- r'\*', '[^/]*') + "$")
+ r'\*', '[^/]*') + "$", re.UNICODE)
_extended_cp_re_cache[extended_cp] = extended_cp_re
return extended_cp_re.match(other_cp) is not None
diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py
index b2f1ff2..25886bb 100644
--- a/pym/portage/manifest.py
+++ b/pym/portage/manifest.py
@@ -4,6 +4,7 @@
import errno
import io
import re
+import sys
import warnings
import portage
@@ -24,6 +25,11 @@ from portage.const import (MANIFEST1_HASH_FUNCTIONS, MANIFEST2_HASH_DEFAULTS,
MANIFEST2_HASH_FUNCTIONS, MANIFEST2_IDENTIFIERS, MANIFEST2_REQUIRED_HASH)
from portage.localization import _
+if sys.hexversion >= 0x3000000:
+ _unicode = str
+else:
+ _unicode = unicode
+
# Characters prohibited by repoman's file.name check.
_prohibited_filename_chars_re = re.compile(r'[^a-zA-Z0-9._\-+:]')
@@ -108,6 +114,14 @@ class Manifest2Entry(ManifestEntry):
def __ne__(self, other):
return not self.__eq__(other)
+ if sys.hexversion < 0x3000000:
+
+ __unicode__ = __str__
+
+ def __str__(self):
+ return _unicode_encode(self.__unicode__(),
+ encoding=_encodings['repo.content'], errors='strict')
+
class Manifest(object):
parsers = (parseManifest2,)
def __init__(self, pkgdir, distdir, fetchlist_dict=None,
@@ -289,7 +303,7 @@ class Manifest(object):
# thin manifests with no DIST entries, myentries is
# non-empty for all currently known use cases.
write_atomic(self.getFullname(), "".join("%s\n" %
- str(myentry) for myentry in myentries))
+ _unicode(myentry) for myentry in myentries))
else:
# With thin manifest, there's no need to have
# a Manifest file if there are no DIST entries.
diff --git a/pym/portage/versions.py b/pym/portage/versions.py
index 242623f..a9b7e64 100644
--- a/pym/portage/versions.py
+++ b/pym/portage/versions.py
@@ -79,7 +79,7 @@ def _get_pv_re(eapi_attrs):
else:
pv_re = _pv['dots_disallowed_in_PN']
- pv_re = re.compile('^' + pv_re + '$', re.VERBOSE)
+ pv_re = re.compile(_unicode_decode('^' + pv_re + '$'), re.VERBOSE | re.UNICODE)
_pv_re_cache[cache_key] = pv_re
return pv_re
@@ -292,7 +292,7 @@ def _pkgsplit(mypkg, eapi=None):
return (m.group('pn'), m.group('ver'), rev)
-_cat_re = re.compile('^%s$' % _cat)
+_cat_re = re.compile('^%s$' % _cat, re.UNICODE)
_missing_cat = 'null'
def catpkgsplit(mydata, silent=1, eapi=None):
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-22 22:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-13 8:36 [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/portage/dep/, pym/_emerge/ Zac Medico
-- strict thread matches above, loose matches on Subject: below --
2012-09-22 22:05 Zac Medico
2012-05-13 23:40 Zac Medico
2012-05-12 9:38 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox