Michał Górny avatar Michał Górny committed b7bd88f

Migrate PMUseFlag to new StringCompat.

Comments (0)

Files changed (4)

gentoopm/basepm/pkg.py

 import os.path
 from abc import abstractmethod, abstractproperty
 
-from ..util import ABCObject, FillMissingComparisons, StringCompat2, \
+from ..util import ABCObject, FillMissingComparisons, StringCompat, \
 		EnumTuple, FillMissingNotEqual
 
 from .atom import PMAtom, PMPackageKey
 		"""
 		pass
 
-class PMUseFlag(ABCObject, StringCompat2):
+class PMUseFlag(ABCObject, StringCompat):
 	"""
 	A base class for a USE flag supported by a package.
 	"""
 
-	def __init__(self, usestr):
+	def __new__(self, usestr):
 		"""
 		Instantiate from an IUSE atom.
 
 		@param usestr: the IUSE atom (C{[+-]?flag})
 		@type usestr: string
 		"""
-		self._name = usestr.lstrip('+-')
+		return StringCompat.__new__(self, usestr.lstrip('+-'))
 
 	@property
 	def name(self):
 
 		@type: string
 		"""
-		return self._name
+		return str(self)
 
 	@abstractproperty
 	def enabled(self):
 		"""
 		pass
 
-	def __str__(self):
-		return self.name
-
 class PMPackage(PMAtom, FillMissingComparisons):
 	"""
 	An abstract class representing a single, uniquely-identified package

gentoopm/paludispm/pkg.py

 		return k.parse_value() if k is not None else None
 
 class PaludisChoice(PMUseFlag):
-	def __init__(self, choice):
-		self._c = choice
-
-	@property
-	def name(self):
-		return str(self._c.name_with_prefix)
+	def __new__(self, choice):
+		uf = PMUseFlag.__new__(self, str(choice.name_with_prefix))
+		uf._c = choice
+		return uf
 
 	@property
 	def enabled(self):

gentoopm/pkgcorepm/pkg.py

 			return None
 
 class PkgCoreUseFlag(PMUseFlag):
-	def __init__(self, s, enabled_use):
-		PMUseFlag.__init__(self, s)
-		self._enabled = self.name in enabled_use
+	def __new__(self, s, enabled_use):
+		uf = PMUseFlag.__new__(self, s)
+		uf._enabled = self.name in enabled_use
+		return uf
 
 	@property
 	def enabled(self):

gentoopm/portagepm/pkg.py

 		return None # XXX
 
 class PortageUseFlag(PMUseFlag):
-	def __init__(self, s, enabled_use):
-		PMUseFlag.__init__(self, s)
-		self._enabled = self.name in enabled_use
+	def __new__(self, s, enabled_use):
+		uf = PMUseFlag.__new__(self, s)
+		uf._enabled = self.name in enabled_use
+		return uf
 
 	@property
 	def enabled(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.