public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/, gentoopm/basepm/
Date: Wed, 20 Jul 2011 16:41:36 +0000 (UTC)	[thread overview]
Message-ID: <120c2eca0d78fac4fa4c57132dcd826c049bfe4a.mgorny@gentoo> (raw)

commit:     120c2eca0d78fac4fa4c57132dcd826c049bfe4a
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 20 16:38:42 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Jul 20 16:38:42 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=120c2eca

Provide a str compat for string-like properties.

---
 gentoopm/basepm/atom.py |    8 ++++----
 gentoopm/basepm/pkg.py  |    4 ++--
 gentoopm/util.py        |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/gentoopm/basepm/atom.py b/gentoopm/basepm/atom.py
index 76e4e10..bc63325 100644
--- a/gentoopm/basepm/atom.py
+++ b/gentoopm/basepm/atom.py
@@ -5,9 +5,9 @@
 
 from abc import abstractmethod, abstractproperty
 
-from gentoopm.util import ABCObject, StringifiedComparisons
+from gentoopm.util import ABCObject, StringCompat, StringifiedComparisons
 
-class PMPackageKey(ABCObject, StringifiedComparisons):
+class PMPackageKey(ABCObject, StringCompat):
 	"""
 	A base class for a package key (CP/qualified package name).
 	"""
@@ -56,7 +56,7 @@ class PMIncompletePackageKey(PMPackageKey):
 	def __str__(self):
 		return self.package
 
-class PMPackageVersion(ABCObject, StringifiedComparisons):
+class PMPackageVersion(ABCObject, StringCompat):
 	"""
 	A base class for a package version.
 	"""
@@ -127,7 +127,7 @@ class PMAtom(ABCObject, StringifiedComparisons):
 
 	def __repr__(self):
 		if self.complete:
-			s = repr(self.__str__())
+			s = repr(str(self))
 		else:
 			s = '<incomplete>'
 		return '%s(%s)' % (self.__class__.__name__, s)

diff --git a/gentoopm/basepm/pkg.py b/gentoopm/basepm/pkg.py
index 4d7d01b..91081df 100644
--- a/gentoopm/basepm/pkg.py
+++ b/gentoopm/basepm/pkg.py
@@ -8,9 +8,9 @@ from abc import abstractmethod, abstractproperty
 
 from gentoopm.basepm.atom import PMAtom
 from gentoopm.basepm.environ import PMPackageEnvironment
-from gentoopm.util import ABCObject, FillMissingComparisons
+from gentoopm.util import ABCObject, FillMissingComparisons, StringCompat
 
-class PMPackageDescription(ABCObject):
+class PMPackageDescription(ABCObject, StringCompat):
 	"""
 	Description of a package.
 	"""

diff --git a/gentoopm/util.py b/gentoopm/util.py
index 4ad8bb6..38c9ccc 100644
--- a/gentoopm/util.py
+++ b/gentoopm/util.py
@@ -69,3 +69,45 @@ class BoolCompat(object):
 
 	def __nonzero__(self):
 		return self.__bool__()
+
+class StringCompat(StringifiedComparisons):
+	"""
+	A helper class providing objects with compatibility string functions,
+	working on stringified form of objects. In other words, it lets you use
+	objects like strings.
+	"""
+
+	def __hasattr__(self, k):
+		return hasattr(str, k)
+
+	def __getattr__(self, k):
+		return getattr(str(self), k)
+
+	# other useful special methods
+	def __add__(self, other):
+		return str(self) + other
+
+	def __contains__(self, h):
+		# XXX: might be useful to override this
+		return h in str(self)
+
+	def __format__(self, spec):
+		return format(str(self), spec)
+
+	def __getitem__(self, k):
+		return str(self)[k]
+
+	def __getslice__(self, a, b):
+		return str(self)[a:b]
+
+	def __len__(self):
+		return len(str(self))
+
+	def __mul__(self, other):
+		return str(self) * other
+
+	def __rmod__(self, other):
+		return other % str(self)
+
+	def __rmul__(self, other):
+		return other * str(self)



             reply	other threads:[~2011-07-20 16:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-20 16:41 Michał Górny [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-08-12 20:07 [gentoo-commits] proj/gentoopm:master commit in: gentoopm/, gentoopm/basepm/ Michał Górny
2011-08-13 11:33 Michał Górny
2011-08-14 22:34 Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=120c2eca0d78fac4fa4c57132dcd826c049bfe4a.mgorny@gentoo \
    --to=mgorny@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox