Commits

Michał Górny committed c49daeb

Migrate package versions to new StringCompat.

  • Participants
  • Parent commits 61e764b

Comments (0)

Files changed (4)

File gentoopm/basepm/atom.py

 from abc import abstractmethod, abstractproperty
 
 from ..util import ABCObject, StringCompat, StringifiedComparisons, \
-		FillMissingComparisons, StringCompat2
+		FillMissingComparisons
 
 class PMPackageKey(ABCObject, StringCompat):
 	"""
 	def package(self):
 		return str(self)
 
-class PMPackageVersion(ABCObject, StringCompat2):
+class PMPackageVersion(ABCObject, FillMissingComparisons, StringCompat):
 	"""
 	A base class for a package version.
 	"""
 
+	def __new__(self, ver):
+		"""
+		Instantiate.
+
+		@param ver: complete package version
+		@type ver: string
+		"""
+		return StringCompat.__new__(self, ver)
+
 	@abstractproperty
 	def without_revision(self):
 		"""
 		pass
 
 	@abstractmethod
-	def __str__(self):
-		"""
-		Return the stringified package version.
-
-		@return: Stringified package version.
-		@rtype: string
-		"""
-		pass
-
-	@abstractmethod
 	def __lt__(self, other):
 		pass
 

File gentoopm/paludispm/atom.py

 		return PMIncompletePackageKey.__new__(self, str(key))
 
 class PaludisPackageVersion(PMPackageVersion):
-	def __init__(self, ver):
-		self._v = ver
+	def __new__(self, ver):
+		v = PMPackageVersion.__new__(self, str(ver))
+		v._v = ver
+		return v
 
 	@property
 	def without_revision(self):
 		assert(rs.startswith('r'))
 		return int(rs[1:])
 
-	def __str__(self):
-		return str(self._v)
-
 	def __lt__(self, other):
 		return self._v < other._v
 

File gentoopm/pkgcorepm/atom.py

 		return PMIncompletePackageKey.__new__(self, pd.restriction.exact)
 
 class PkgCorePackageVersion(PMPackageVersion):
-	def __init__(self, atom):
+	def __new__(self, atom):
 		if atom.version is None:
 			raise AssertionError('Empty version in atom')
-		self._atom = atom
+		v = PMPackageVersion.__new__(self, atom.fullver)
+		v._atom = atom
+		return v
 
 	@property
 	def without_revision(self):
 	def revision(self):
 		return self._atom.revision or 0
 
-	def __str__(self):
-		return self._atom.fullver
-
 	def __lt__(self, other):
 		if self._atom.key != other._atom.key:
 			raise NotImplementedError('Unable to compare versions of distinct packages')
 		return self._atom < other._atom
 
 class PkgCoreIncompletePackageVersion(PMPackageVersion):
-	def __init__(self, r):
-		self._r = _find_res(r, VersionMatch)
-		if self._r is None:
+	def __new__(self, r):
+		vm = _find_res(r, VersionMatch)
+		if vm is None:
 			raise AssertionError('No VersionMatch in restrictions.')
+		v = PMPackageVersion.__new__(self, str(vm).split()[-1]) # XXX
+		v._r = vm
+		return v
 
 	@property
 	def without_revision(self):
 	def __lt__(self, other):
 		raise NotImplementedError('Unable to compare versions of incomplete atoms')
 
-	def __str__(self):
-		# XXX: ugly?
-		return str(self._r).split()[-1]
-
 class PkgCoreAtom(PMAtom):
 	def __init__(self, s):
 		if isinstance(s, atom):

File gentoopm/portagepm/atom.py

 		return PMIncompletePackageKey.__new__(self, catsplit(key)[1])
 
 class PortagePackageVersion(PMPackageVersion):
-	def __init__(self, cpv):
-		self._cpv = cpv
+	def __new__(self, cpv):
+		v = PMPackageVersion.__new__(self, cpv_getversion(cpv))
+		v._cpv = cpv
+		return v
 
 	@property
 	def without_revision(self):
 		assert(rs.startswith('r'))
 		return int(rs[1:])
 
-	def __str__(self):
-		return cpv_getversion(self._cpv)
-
 	def __lt__(self, other):
 		return vercmp(str(self), str(other)) < 0