Example #1
0
    def coerce(cls, value):
        """Coerce to a class

		Acceptable Values:
			Unicode/string class name
			a class
		"""
        if cls.check(value):
            return value
        if isinstance(value, unicode):
            value = str(value)
        if isinstance(value, str):
            try:
                return latebind.bind(value)
            except ImportError, error:
                raise ValueError("""ImportError loading class %r: %s""" %
                                 (value, error))

            except Exception, error:
                traceback.print_exc()
                raise ValueError("""%s loading class from specifier %r: %s""" %
                                 (
                                     error.__class__.__name__,
                                     value,
                                     error,
                                 ))
Example #2
0
	def getDriver( self ):
		"""Get driver instance for this specifier"""
		driver = self.drivername.value()
		from basictypes import latebind
		driverClass = latebind.bind( driver )
		driver = driverClass()
		return driver
Example #3
0
	def coerce( cls, value ):
		"""Coerce to a class

		Acceptable Values:
			Unicode/string class name
			a class
		"""
		if cls.check( value ):
			return value
		if isinstance( value, unicode ):
			value = str(value)
		if isinstance( value, str):
			try:
				return latebind.bind( value )
			except ImportError, error:
				raise ValueError(
					"""ImportError loading class %r: %s"""%(
						value, error
					)
				)
				
			except Exception, error:
				traceback.print_exc()
				raise ValueError(
					"""%s loading class from specifier %r: %s"""%(
						error.__class__.__name__, value, error,
					)
				)
Example #4
0
	def resolveBoundary( self, boundarySpecifier, property, client, value ):
		"""Resolve a particular boundary specifier into a boundary class"""
		try:
			return latebind.bind( boundarySpecifier )
		except (ImportError, AttributeError):
			raise BoundaryTypeError(
				property, self, client, value,
				"Class/type %s could not be imported"""%(boundarySpecifier,)
			)
Example #5
0
	def OnChoiceChanged( self, event=None ):
		"""Update description on property change"""
		className = self.value.drivername.value()
		if className:
			try:
				driver = latebind.bind( className )
			except Exception, err:
				log.warn( """Exception importing driver %s: %s""", className, err)
			else:
				if hasattr( driver, 'userDescription'):
					self.driverDescription.SetLabel( driver.userDescription)
Example #6
0
 def _get_baseType(self):
     """Get the baseType as an object/class"""
     base = getattr(self, "_baseType")
     if isinstance(base, type):
         return base
     if isinstance(base, unicode):
         base = str(base)
     if isinstance(base, (str, tuple)):
         new = latebind.bind(base)
         if isinstance(new, (tuple, list)):
             base = type(base)(new)
         else:
             base = new
     assert isinstance(base, (type, types.ClassType)) or (hasattr(base, "coerce") and hasattr(base, "check")), (
         """Specified base type %r for listof is not a class/type, and doesn't define both coerce and check methods"""
         % (base,)
     )
     setattr(self, "_baseType", base)
     return base
Example #7
0
 def _get_baseType(self):
     """Get the baseType as an object/class"""
     base = getattr(self, '_baseType')
     if isinstance(base, type):
         return base
     if isinstance(base, unicode):
         base = str(base)
     if isinstance(base, (str, tuple)):
         new = latebind.bind(base)
         if isinstance(new, (tuple, list)):
             base = type(base)(new)
         else:
             base = new
     assert (
         isinstance(base, (type, types.ClassType))
         or (hasattr(base, 'coerce') and hasattr(base, 'check'))
     ), """Specified base type %r for listof is not a class/type, and doesn't define both coerce and check methods""" % (
         base, )
     setattr(self, '_baseType', base)
     return base
Example #8
0
	def GetNext (self):
		"""Get the next page in this wizard

		This will be looking to retrieve a driver-specific
		page for setting up the driver-specific specifier
		details which are the database-related, as distinct
		from user and password related.
		"""
		# first things first, try to get a pointer to the driver
		currentValue = self.value.drivername
		className = currentValue.value()
		log.debug( """Driver name: %s""", className)
		try:
			driver = latebind.bind( className )
			self.value.driver = driver
			self.value.drivername = currentValue
			log.info( """Resolved driver: %s""", driver)
		except Exception, err:
			log.warn( """Exception importing driver %s: %s""", className, err)
			# should display a dialogue here
			return self
Example #9
0
	def getBaseType( self ):
		"""Get our base-type object or None if not set"""
		if isinstance(self.baseType, (str,unicode)):
			from basictypes import latebind
			self.baseType = latebind.bind( self.baseType )
		return registry.getDT( self.baseType )