B u `n%@sdZddlZddlZddlZddlZddlZddlZddlmZdddZ dddZ dd d Z d d Z Gd dde ZGdddejZdddZdS)z$Decorator for deprecating functions.N)DeveloperErrorcCsz|dkr6t|rd}nt|r(d}nd}d|f}g}|rN|d|f|r`|d||rv|dd |7}|S) zcGenerate the default deprecation message. See deprecated() function for argument details. Nz classz functionzBThis%s has been deprecated and may be removed in a future release.zdeprecated in %szwill be removed in %sz (%s)z, )inspectisclass isfunctionappendjoin)Zuser_msgversion remove_infunc_objcommentr.wrap..wrapperzDEPRECATION WARNING: %sr)rz )r functoolswraps__doc__rrdedentr)r r,)r"r!r r )r r+rwrapgs zdeprecated..wrap)r)r!r"r r r1r)r"r!r r r deprecatedKsr2cCs@ddlm}|dd\}}td||f||dt|||S)Nr) import_module.z%the '%s' class has been moved to '%s')r r ) importlibr3rsplitr%getattr)nametargetr r r3modnameZ targetnamerrr_import_object{s    r<cs8eZdZdZfddZddZddZdd ZZS) _ModuleGetattrBackport_27aBackport for support of module.__getattr__ Beginning in Python 3.7, modules support the declaration of a module-scoped __getattr__ and __dir__ to allow for the dynamic resolution of module attributes. This class wraps the module class and implements `__getattr__`. As it declares no local attributes, all module attribute accesses incur a slight runtime penalty (one extra function call). cstt|d|dS)N_wrapped_module)superr= __setattr__)selfmodule) __class__rr__init__s z"_ModuleGetattrBackport_27.__init__cCs^y t|j|Stk rX|jj|d}|dk rRt|f|}t||||SYnXdS)N)r8r>AttributeError__relocated_attrs__getr<setattr)rAr9r$ target_objrrr __getattr__s  z%_ModuleGetattrBackport_27.__getattr__cCs t|jS)N)dirr>)rArrr__dir__sz!_ModuleGetattrBackport_27.__dir__cCst|j||dS)N)rHr>)rAr9valrrrr@sz%_ModuleGetattrBackport_27.__setattr__) r'r& __qualname__r/rDrJrLr@ __classcell__rr)rCrr=s    r=c@seZdZdZddZdS)_ModuleGetattrBackport_35aBackport for support of module.__getattr__ Beginning in Python 3.7, modules support the declaration of a module-scoped __getattr__ and __dir__ to allow for the dynamic resolution of module attributes. This class derives from types.ModuleType and implements `__getattr__`. As it is a direct replacement for types.ModuleType (i.e., we can reassign the already loaded module to this type, it is more efficient that the ModuleGetattrBackport_27 class which must wrap the already loaded module. cCsJ|j|d}|dk r4t|f|}t||||Std|j|fdS)Nz!module '%s' has no attribute '%s')rFrGr<rHrEr')rAr9r$rIrrrrJs z%_ModuleGetattrBackport_35.__getattr__N)r'r&rNr/rJrrrrrPs rPcstjtjjdtdsi_tjdkrZjt ddfdd}|_ n6tjdkr|j t j ksttt_ nttjj<|||fj|<dS) aProvide a deprecation path for moved / renamed module attributes This function declares that a local module attribute has been moved to another location. For Python 3.7+, it leverages a module.__getattr__ method to manage the deferred import of the object from the new location (on request), as well as emitting the deprecation warning. It contains backports of the __getattr__ functionality for earlier versions of Python (although the implementation for 3.5+ is more efficient that the implementation for 2.7+) Parameters ---------- local: str The original (local) name of the relocated attribute target: str The new absolute import name of the relocated attribute version: str The Pyomo version when this move was released (passed to deprecation_warning) remove_in: str The Pyomo version when this deprecation path will be removed (passed to deprecation_warning) r'rF)rJNcsX|d}|dk r2t|f|}t|||Sdk rB|Stdj|fdS)Nz!module '%s' has no attribute '%s')rGr<rHrEr')r9r$rI) _mod_getattr_module _relocatedrrrJs  z/relocated_module_attribute..__getattr__)rQ)sysmodulesrrrrhasattrrF version_infor8rJrCtypes ModuleTypeAssertionErrorrPr=r')localr:r r rJr)rSrTrUrrelocated_module_attributes     r_)N)rNNN)NrNN)N)r/rr-rrWrr[Zpyomo.common.errorsrrr%r2r<objectr=r\rPr_rrrr s    0#