a [dgb@sddlZddlZddlZddlZddlmZddlmZmZm Z m Z ddl mZgdZ GdddZ d d Zdd d ZdddZddZedS)N) StrictVersion) find_module PY_COMPILED PY_FROZEN PY_SOURCE)_imp)Requirerget_module_constantextract_constantc@sHeZdZdZdddZddZdd Zdd d Zdd dZdddZ dS)r z7A prerequisite to building or installing a distributionNcCsF|dur|durt}|dur0||}|dur0d}|jt|`dS)N __version__)r__dict__updatelocalsself)rnamerequested_versionmoduleZhomepage attributeformatrReturn true if dependency is present and up-to-date on 'paths'NF)r'r)rr!rrrr is_currentLs zRequire.is_current)r NN)Nr)N)N) __name__ __module__ __qualname____doc__rrrr'r(r)rrrrr s   r cCs"tjdd}|s|St|S)Ncss dVdS)NrrrrremptyUszmaybe_close..empty) contextlibcontextmanagerclosing)r#r.rrr maybe_closeTs  r2c Cszt||\}}\}}}} Wnty2YdS0t||tkr\|dt|} nX|tkrrt ||} nB|t krt ||d} n(t ||| } t | |dWdSWdn1s0Yt| ||S)zFind 'module' by searching 'paths', and extract 'symbol' Return 'None' if 'module' does not exist on 'paths', or it does not define 'symbol'. If the module defines 'symbol' as a constant, return the constant. Otherwise, return 'default'.Nexec)rr r2rreadmarshalloadrrget_frozen_objectrcompileZ get_modulegetattrr ) rsymbolr"r!r#pathsuffixmodekindinfocodeZimportedrrrr _s    8r c Cs||jvrdSt|j|}d}d}d}|}t|D]H}|j} |j} | |kr\|j| }q8| |kr|| |kst| |kr||S|}q8dS)aExtract the constant value of 'symbol' from 'code' If the name 'symbol' is bound to a constant value by the Python code object 'code', return that value. If 'symbol' is bound to an expression, return 'default'. Otherwise, return 'None'. Return value is based on the first assignment to 'symbol'. 'symbol' must be a global, or at least a non-"fast" local in the code block. That is, only 'STORE_NAME' and 'STORE_GLOBAL' opcodes are checked, and 'symbol' must be present in 'code.co_names'. NZad)co_nameslistindexdisZBytecodeZopcodearg co_consts) rBr<r"Zname_idxZ STORE_NAMEZ STORE_GLOBALZ LOAD_CONSTconstZ byte_codeoprJrrrr |s  r cCs>tjdstjdkrdSd}|D]}t|=t|q"dS)z Patch the globals to remove the objects not available on some platforms. XXX it'd be better to test assertions about bytecode instead. javaZcliN)r r )sysplatform startswithglobals__all__remove)Z incompatiblerrrr_update_globalss rU)r3N)r3)rOr7r/rIZdistutils.versionrrrrrrr rSr r2r r rUrrrrs  D  $