def canonical_name( cls ): """Canonical names for plugins are defined as, .. code-block:: <pkgname>.<plugin-class-name> where the entire string is lower-cased. This function is to be called only by PluginMeta class when a plugin class is about to be blue-printed. """ # TODO : This is a hack specific to tayra template file. Make it generic. mod = sys.modules.get( cls.__module__ ) f = getattr( mod, '_ttlfile', getattr(mod, '__file__', None) ) if f and isfile(f) : return (h.packagedin( abspath(f) ) + '.' + cls.__name__).lower() else : return cls.__name__.lower()
def canonical_name(cls): """Canonical names for plugins are defined as, .. code-block:: <pkgname>.<plugin-class-name> where the entire string is lower-cased. This function is to be called only by PluginMeta class when a plugin class is about to be blue-printed. """ # TODO : This is a hack specific to tayra template file. Make it generic. mod = sys.modules.get(cls.__module__) f = getattr(mod, '_ttlfile', getattr(mod, '__file__', None)) if f and isfile(f): return (h.packagedin(abspath(f)) + '.' + cls.__name__).lower() else: return cls.__name__.lower()
def implements( *interfaces ): """Plugin classes can use this function to declare ``interfaces`` that are implemented by them. This function can be called only inside the scope of a class deriving from :class:`Plugin`.""" frame = sys._getframe(1) if frame.f_code.co_name in core_classes : return # Skip # TODO : This is a hack specific to tayra template file. Make it generic. filen = frame.f_globals.get('_ttlfile', None) pkg = h.packagedin( abspath(filen) if filen else frame.f_code.co_filename ) nm = (pkg + '.' + frame.f_code.co_name).lower() for i in interfaces : if isinstance(i, str) : i = PluginMeta._interfmap[i]['cls'] if nm in list( PluginMeta._implementers.get(i, {}).keys() ) : raise Exception( 'Plugin %r implements interface %r twice' % (nm, i) ) PluginMeta._implementers.setdefault( i, {} ).setdefault( nm, '-na-' )
def implements(*interfaces): """Plugin classes can use this function to declare ``interfaces`` that are implemented by them. This function can be called only inside the scope of a class deriving from :class:`Plugin`.""" frame = sys._getframe(1) if frame.f_code.co_name in core_classes: return # Skip # TODO : This is a hack specific to tayra template file. Make it generic. filen = frame.f_globals.get('_ttlfile', None) pkg = h.packagedin(abspath(filen) if filen else frame.f_code.co_filename) nm = (pkg + '.' + frame.f_code.co_name).lower() for i in interfaces: if isinstance(i, str): i = PluginMeta._interfmap[i]['cls'] if nm in list(PluginMeta._implementers.get(i, {}).keys()): raise Exception('Plugin %r implements interface %r twice' % (nm, i)) PluginMeta._implementers.setdefault(i, {}).setdefault(nm, '-na-')