diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-09-15 19:39:00 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-09-15 19:39:00 -0700 |
commit | 32684ef519daea00ce8eefe48fe15893a5a886bf (patch) | |
tree | 2de58809abcef1e7978b592d9fdde03826c2dcf7 | |
parent | 8bb3ef148772b6c3cfdbe88807779871d38700b7 (diff) | |
download | portage-32684ef519daea00ce8eefe48fe15893a5a886bf.tar.gz portage-32684ef519daea00ce8eefe48fe15893a5a886bf.tar.bz2 portage-32684ef519daea00ce8eefe48fe15893a5a886bf.zip |
Implement DependencyArg __equals__, __hash__, and __unicode__ methods.
-rw-r--r-- | pym/_emerge/DependencyArg.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/pym/_emerge/DependencyArg.py b/pym/_emerge/DependencyArg.py index 3bcaabefe..31cd882b5 100644 --- a/pym/_emerge/DependencyArg.py +++ b/pym/_emerge/DependencyArg.py @@ -1,11 +1,33 @@ -# Copyright 1999-2009 Gentoo Foundation +# Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import sys + +from portage import _encodings, _unicode_encode, _unicode_decode + class DependencyArg(object): def __init__(self, arg=None, root_config=None): self.arg = arg self.root_config = root_config + def __equals__(self, other): + if self.__class__ is not other.__class__: + return False + return self.arg == other.arg and \ + self.root_config.root == other.root_config.root + + def __hash__(self): + return hash((self.arg, self.root_config.root)) + def __str__(self): - return str(self.arg) + # Force unicode format string for python-2.x safety, + # ensuring that self.arg.__unicode__() is used + # when necessary. + return _unicode_decode("%s") % (self.arg,) + + if sys.hexversion < 0x3000000: + + __unicode__ = __str__ + def __str__(self): + return _unicode_encode(self.__unicode__(), encoding=_encodings['content']) |