<s> import sys <EOL> import imp <EOL> import marshal <EOL> from imp import PKG_DIRECTORY , PY_COMPILED , PY_SOURCE , PY_FROZEN <EOL> from distutils . version import StrictVersion <EOL> from setuptools import compat <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> class Require : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , requested_version , module , homepage = '<STR_LIT>' , <EOL> attribute = None , format = None ) : <EOL> if format is None and requested_version is not None : <EOL> format = StrictVersion <EOL> if format is not None : <EOL> requested_version = format ( requested_version ) <EOL> if attribute is None : <EOL> attribute = '<STR_LIT>' <EOL> self . __dict__ . update ( locals ( ) ) <EOL> del self . self <EOL> def full_name ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . requested_version is not None : <EOL> return '<STR_LIT>' % ( self . name , self . requested_version ) <EOL> return self . name <EOL> def version_ok ( self , version ) : <EOL> """<STR_LIT>""" <EOL> return self . attribute is None or self . format is None or str ( version ) != "<STR_LIT>" and version >= self . requested_version <EOL> def get_version ( self , paths = None , default = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if self . attribute is None : <EOL> try : <EOL> f , p , i = find_module ( self . module , paths ) <EOL> if f : f . close ( ) <EOL> return default <EOL> except ImportError : <EOL> return None <EOL> v = get_module_constant ( self . module , self . attribute , default , paths ) <EOL> if v is not None and v is not default and self . format is not None : <EOL> return self . format ( v ) <EOL> return v <EOL> def is_present ( self , paths = None ) : <EOL> """<STR_LIT>""" <EOL> return self . get_version ( paths ) is not None <EOL> def is_current ( self , paths = None ) : <EOL> """<STR_LIT>""" <EOL> version = self . get_version ( paths ) <EOL> if version is None : <EOL> return False <EOL> return self . version_ok ( version ) <EOL> def _iter_code ( code ) : <EOL> """<STR_LIT>""" <EOL> from array import array <EOL> from dis import HAVE_ARGUMENT , EXTENDED_ARG <EOL> bytes = array ( '<STR_LIT:b>' , code . co_code ) <EOL> eof = len ( code . co_code ) <EOL> ptr = <NUM_LIT:0> <EOL> extended_arg = <NUM_LIT:0> <EOL> while ptr < eof : <EOL> op = bytes [ ptr ] <EOL> if op >= HAVE_ARGUMENT : <EOL> arg = bytes [ ptr + <NUM_LIT:1> ] + bytes [ ptr + <NUM_LIT:2> ] * <NUM_LIT> + extended_arg <EOL> ptr += <NUM_LIT:3> <EOL> if op == EXTENDED_ARG : <EOL> extended_arg = arg * compat . long_type ( <NUM_LIT> ) <EOL> continue <EOL> else : <EOL> arg = None <EOL> ptr += <NUM_LIT:1> <EOL> yield op , arg <EOL> def find_module ( module , paths = None ) : <EOL> """<STR_LIT>""" <EOL> parts = module . split ( '<STR_LIT:.>' ) <EOL> while parts : <EOL> part = parts . pop ( <NUM_LIT:0> ) <EOL> f , path , ( suffix , mode , kind ) = info = imp . find_module ( part , paths ) <EOL> if kind == PKG_DIRECTORY : <EOL> parts = parts or [ '<STR_LIT>' ] <EOL> paths = [ path ] <EOL> elif parts : <EOL> raise ImportError ( "<STR_LIT>" % ( parts , module ) ) <EOL> return info <EOL> def get_module_constant ( module , symbol , default = - <NUM_LIT:1> , paths = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> f , path , ( suffix , mode , kind ) = find_module ( module , paths ) <EOL> except ImportError : <EOL> return None <EOL> try : <EOL> if kind == PY_COMPILED : <EOL> f . read ( <NUM_LIT:8> ) <EOL> code = marshal . load ( f ) <EOL> elif kind == PY_FROZEN : <EOL> code = imp . get_frozen_object ( module ) <EOL> elif kind == PY_SOURCE : <EOL> code = compile ( f . read ( ) , path , '<STR_LIT>' ) <EOL> else : <EOL> if module not in sys . modules : <EOL> imp . load_module ( module , f , path , ( suffix , mode , kind ) ) <EOL> return getattr ( sys . modules [ module ] , symbol , None ) <EOL> finally : <EOL> if f : <EOL> f . close ( ) <EOL> return extract_constant ( code , symbol , default ) <EOL> def extract_constant ( code , symbol , default = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if symbol not in code . co_names : <EOL> return None <EOL> name_idx = list ( code . co_names ) . index ( symbol ) <EOL> STORE_NAME = <NUM_LIT> <EOL> STORE_GLOBAL = <NUM_LIT> <EOL> LOAD_CONST = <NUM_LIT:100> <EOL> const = default <EOL> for op , arg in _iter_code ( code ) : <EOL> if op == LOAD_CONST : <EOL> const = code . co_consts [ arg ] <EOL> elif arg == name_idx and ( op == STORE_NAME or op == STORE_GLOBAL ) : <EOL> return const <EOL> else : <EOL> const = default <EOL> def _update_globals ( ) : <EOL> """<STR_LIT>""" <EOL> if not sys . platform . startswith ( '<STR_LIT>' ) and sys . platform != '<STR_LIT>' : <EOL> return <EOL> incompatible = '<STR_LIT>' , '<STR_LIT>' <EOL> for name in incompatible : <EOL> del globals ( ) [ name ] <EOL> __all__ . remove ( name ) <EOL> _update_globals ( ) </s>
