py-visage

Loosely coupled Python Interface Registry
Download

py-visage Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Freely Distributable
  • Price:
  • FREE
  • Publisher Name:
  • James William Pye
  • Publisher web site:
  • http://python.projects.postgresql.org/

py-visage Tags


py-visage Description

visage is a Python module that provides a registry for loose coupling of interfaces and implementations.visage is heavily based on Python's abstract base classes for allowing isinstance checks in the presence of an interface definition. However, in the absence of an interface definition, registry-level checks can be performed in order to evaluate a given implementation's declaration of interface support.Sample usage:import abcimport visage.lib@visage.lib.interface('company.com/interface/Shapes')def Interface(metaclass=abc.ABCMeta): pass@visage.lib.implementation('company.com/interface/Shapes')def Implementation(object): passInstance = Implementation()assert visage.lib.isinstance(Instance, 'company.com/interface/Shapes')assert visage.lib.hasinterface(Implementation, 'company.com/interface/Shapes')assert visage.lib.isdefinition(Interface, 'company.com/interface/Shapes')However, the declaration of the interface is not necessary for an implementation to be declared. Implementations are fully functional without an interface, and identifier based checks can be easily used.When the Interface object is present, it can be used to do checks using the builtins that work with classes:assert isinstance(Instance, Interface)assert issubclass(Implementation, Interface)Product's homepage


py-visage Related Software