def wrapper(cls): # Make the API exceptions available for name in errors.API_EXCEPTION_NAMES: base = getattr(Utils.this_module(), name) setattr(cls, name, base) # The type constructors provided by the driver module should # be accessible as (static) methods of the database's # connection objects. for ctor_name in API_TYPE_CTOR_NAMES: if hasattr(cls, ctor_name): # There already is an implementation of this # particular ctor in this class, probably for a good # reason (e.g. the driver module doesn't supply this # type ctor); skip to next ctor. continue f = getattr(module, ctor_name) setattr(cls, ctor_name, staticmethod(f)) # Likewise we copy the driver-specific type objects to the # connection object's class. for type_name in API_TYPE_NAMES: if hasattr(cls, type_name): # Already present as attribute; skip. continue type_obj = getattr(module, type_name) setattr(cls, type_name, type_obj) # make the real db module available as db-mod cls._db_mod = module return cls
def wrapper(cls): # Make the API exceptions available for name in API_EXCEPTION_NAMES: base = getattr(Utils.this_module(), name) setattr(cls, name, base) # The type constructors provided by the driver module should # be accessible as (static) methods of the database's # connection objects. for ctor_name in API_TYPE_CTOR_NAMES: if hasattr(cls, ctor_name): # There already is an implementation of this # particular ctor in this class, probably for a good # reason (e.g. the driver module doesn't supply this # type ctor); skip to next ctor. continue f = getattr(module, ctor_name) setattr(cls, ctor_name, staticmethod(f)) # Likewise we copy the driver-specific type objects to the # connection object's class. for type_name in API_TYPE_NAMES: if hasattr(cls, type_name): # Already present as attribute; skip. continue type_obj = getattr(module, type_name) setattr(cls, type_name, type_obj) # Set up a "bind parameter converter" suitable for the driver # module's `paramstyle' constant. if getattr(cls, 'param_converter', None) is None: cls.param_converter = get_converter(module.paramstyle) # make the real db module available as db-mod cls._db_mod = module return cls
def this_module_test(): """ Utils.this_module reports correct module. """ me = sys.modules[this_module_test.__module__] assert Utils.this_module() is me assert Utils.this_module() == me