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, ))
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
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, ) )
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,) )
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)
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
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
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
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 )