<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import inspect , re , sys , os . path , imp <EOL> from epydoc . apidoc import * <EOL> from types import * <EOL> from epydoc import log <EOL> from epydoc . util import * <EOL> import epydoc . docparser <EOL> import __builtin__ <EOL> from epydoc . compat import * <EOL> _valuedoc_cache = { } <EOL> """<STR_LIT>""" <EOL> _introspected_values = { } <EOL> """<STR_LIT>""" <EOL> def clear_cache ( ) : <EOL> """<STR_LIT>""" <EOL> _valuedoc_cache . clear ( ) <EOL> _introspected_values . clear ( ) <EOL> def introspect_docs ( value = None , name = None , filename = None , context = None , <EOL> is_script = False , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> if value is None and name is not None and filename is None : <EOL> value = get_value_from_name ( DottedName ( name ) ) <EOL> elif value is None and name is None and filename is not None : <EOL> if is_script : <EOL> value = get_value_from_scriptname ( filename ) <EOL> else : <EOL> value = get_value_from_filename ( filename , context ) <EOL> elif name is None and filename is None : <EOL> pass <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> pyid = id ( value ) <EOL> if pyid in _introspected_values : <EOL> if is_script and filename is not None : <EOL> _valuedoc_cache [ pyid ] . canonical_name = DottedName ( <EOL> munge_script_name ( str ( filename ) ) ) <EOL> return _valuedoc_cache [ pyid ] <EOL> val_doc = _get_valuedoc ( value ) <EOL> _introspected_values [ pyid ] = True <EOL> introspect_func = _get_introspecter ( value ) <EOL> introspect_func ( value , val_doc , module_name = module_name ) <EOL> if val_doc . canonical_name is UNKNOWN and name is not None : <EOL> val_doc . canonical_name = DottedName ( name ) <EOL> if is_script and filename is not None : <EOL> val_doc . canonical_name = DottedName ( munge_script_name ( str ( filename ) ) ) <EOL> if val_doc . canonical_name is UNKNOWN and filename is not None : <EOL> shadowed_name = DottedName ( value . __name__ ) <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % shadowed_name ) <EOL> val_doc . canonical_name = DottedName ( str ( shadowed_name ) + "<STR_LIT:'>" ) <EOL> return val_doc <EOL> def _get_valuedoc ( value ) : <EOL> """<STR_LIT>""" <EOL> pyid = id ( value ) <EOL> val_doc = _valuedoc_cache . get ( pyid ) <EOL> if val_doc is None : <EOL> try : canonical_name = get_canonical_name ( value , strict = True ) <EOL> except DottedName . InvalidDottedName : canonical_name = UNKNOWN <EOL> val_doc = ValueDoc ( pyval = value , canonical_name = canonical_name , <EOL> docs_extracted_by = '<STR_LIT>' ) <EOL> _valuedoc_cache [ pyid ] = val_doc <EOL> if inspect . ismodule ( value ) : <EOL> introspect_module ( value , val_doc , preliminary = True ) <EOL> val_doc . defining_module = val_doc <EOL> else : <EOL> module_name = str ( get_containing_module ( value ) ) <EOL> module = sys . modules . get ( module_name ) <EOL> if module is not None and inspect . ismodule ( module ) : <EOL> val_doc . defining_module = _get_valuedoc ( module ) <EOL> return val_doc <EOL> UNDOCUMENTED_MODULE_VARS = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def introspect_module ( module , module_doc , module_name = None , preliminary = False ) : <EOL> """<STR_LIT>""" <EOL> module_doc . specialize_to ( ModuleDoc ) <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> module_doc . docformat = unicode ( module . __docformat__ ) <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> try : module_doc . filename = unicode ( module . __file__ ) <EOL> except KeyboardInterrupt : raise <EOL> except : pass <EOL> if module_doc . filename is not UNKNOWN : <EOL> try : module_doc . filename = py_src_filename ( module_doc . filename ) <EOL> except ValueError : pass <EOL> module_doc . variables = { } <EOL> if preliminary : return <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> module_doc . docstring = get_docstring ( module ) <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> module_doc . is_package = True <EOL> try : module_doc . path = [ unicode ( p ) for p in module . __path__ ] <EOL> except KeyboardInterrupt : raise <EOL> except : pass <EOL> else : <EOL> module_doc . is_package = False <EOL> dotted_name = module_doc . canonical_name <EOL> if dotted_name is UNKNOWN : <EOL> dotted_name = DottedName ( module . __name__ ) <EOL> name_without_primes = DottedName ( str ( dotted_name ) . replace ( "<STR_LIT:'>" , "<STR_LIT>" ) ) <EOL> if len ( dotted_name ) > <NUM_LIT:1> : <EOL> package_name = str ( dotted_name . container ( ) ) <EOL> package = sys . modules . get ( package_name ) <EOL> if package is not None : <EOL> module_doc . package = introspect_docs ( package ) <EOL> else : <EOL> module_doc . package = None <EOL> module_doc . submodules = [ ] <EOL> if module_doc . package not in ( None , UNKNOWN ) : <EOL> module_doc . package . submodules . append ( module_doc ) <EOL> public_names = None <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> try : <EOL> public_names = set ( [ str ( name ) for name in module . __all__ ] ) <EOL> except KeyboardInterrupt : raise <EOL> except : pass <EOL> module_doc . variables = { } <EOL> for child_name in dir ( module ) : <EOL> if child_name in UNDOCUMENTED_MODULE_VARS : continue <EOL> child = getattr ( module , child_name ) <EOL> container = get_containing_module ( child ) <EOL> if ( ( container is not None and <EOL> container == name_without_primes ) or <EOL> ( public_names is not None and <EOL> child_name in public_names ) ) : <EOL> child_val_doc = introspect_docs ( child , context = module_doc , <EOL> module_name = dotted_name ) <EOL> child_var_doc = VariableDoc ( name = child_name , <EOL> value = child_val_doc , <EOL> is_imported = False , <EOL> container = module_doc , <EOL> docs_extracted_by = '<STR_LIT>' ) <EOL> elif container is None or module_doc . canonical_name is UNKNOWN : <EOL> if is_future_feature ( child ) : continue <EOL> child_val_doc = introspect_docs ( child , context = module_doc ) <EOL> child_var_doc = VariableDoc ( name = child_name , <EOL> value = child_val_doc , <EOL> container = module_doc , <EOL> docs_extracted_by = '<STR_LIT>' ) <EOL> else : <EOL> child_val_doc = _get_valuedoc ( child ) <EOL> child_var_doc = VariableDoc ( name = child_name , <EOL> value = child_val_doc , <EOL> is_imported = True , <EOL> container = module_doc , <EOL> docs_extracted_by = '<STR_LIT>' ) <EOL> if public_names is not None : <EOL> if child_name in public_names : <EOL> child_var_doc . is_public = True <EOL> if not isinstance ( child_var_doc , ModuleDoc ) : <EOL> child_var_doc . is_imported = False <EOL> else : <EOL> child_var_doc . is_public = False <EOL> module_doc . variables [ child_name ] = child_var_doc <EOL> return module_doc <EOL> UNDOCUMENTED_CLASS_VARS = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def introspect_class ( cls , class_doc , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> class_doc . specialize_to ( ClassDoc ) <EOL> class_doc . docstring = get_docstring ( cls ) <EOL> public_names = None <EOL> if hasattr ( cls , '<STR_LIT>' ) : <EOL> try : <EOL> public_names = set ( [ str ( name ) for name in cls . __all__ ] ) <EOL> except KeyboardInterrupt : raise <EOL> except : pass <EOL> class_doc . subclasses = [ ] <EOL> base_children = { } <EOL> if hasattr ( cls , '<STR_LIT>' ) : <EOL> try : bases = list ( cls . __bases__ ) <EOL> except : <EOL> bases = None <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % getattr ( cls , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if bases is not None : <EOL> class_doc . bases = [ ] <EOL> for base in bases : <EOL> basedoc = introspect_docs ( base ) <EOL> class_doc . bases . append ( basedoc ) <EOL> basedoc . subclasses . append ( class_doc ) <EOL> bases . reverse ( ) <EOL> for base in bases : <EOL> if hasattr ( base , '<STR_LIT>' ) : <EOL> base_children . update ( base . __dict__ ) <EOL> if module_name is None and class_doc . defining_module not in ( None , UNKNOWN ) : <EOL> module_name = class_doc . defining_module . canonical_name <EOL> class_doc . variables = { } <EOL> if hasattr ( cls , '<STR_LIT>' ) : <EOL> private_prefix = '<STR_LIT>' % getattr ( cls , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for child_name , child in cls . __dict__ . items ( ) : <EOL> if ( child_name in base_children <EOL> and base_children [ child_name ] == child ) : <EOL> continue <EOL> if child_name . startswith ( private_prefix ) : <EOL> child_name = child_name [ len ( private_prefix ) - <NUM_LIT:2> : ] <EOL> if child_name in UNDOCUMENTED_CLASS_VARS : continue <EOL> val_doc = introspect_docs ( child , context = class_doc , <EOL> module_name = module_name ) <EOL> var_doc = VariableDoc ( name = child_name , value = val_doc , <EOL> container = class_doc , <EOL> docs_extracted_by = '<STR_LIT>' ) <EOL> if public_names is not None : <EOL> var_doc . is_public = ( child_name in public_names ) <EOL> class_doc . variables [ child_name ] = var_doc <EOL> return class_doc <EOL> def introspect_routine ( routine , routine_doc , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> routine_doc . specialize_to ( RoutineDoc ) <EOL> if isinstance ( routine , MethodType ) : <EOL> func = routine . im_func <EOL> elif isinstance ( routine , staticmethod ) : <EOL> func = routine . __get__ ( <NUM_LIT:0> ) <EOL> elif isinstance ( routine , classmethod ) : <EOL> func = routine . __get__ ( <NUM_LIT:0> ) . im_func <EOL> else : <EOL> func = routine <EOL> routine_doc . docstring = get_docstring ( func ) <EOL> if isinstance ( func , FunctionType ) : <EOL> ( args , vararg , kwarg , defaults ) = inspect . getargspec ( func ) <EOL> routine_doc . posargs = args <EOL> routine_doc . vararg = vararg <EOL> routine_doc . kwarg = kwarg <EOL> routine_doc . posarg_defaults = [ None ] * len ( args ) <EOL> if defaults is not None : <EOL> offset = len ( args ) - len ( defaults ) <EOL> for i in range ( len ( defaults ) ) : <EOL> default_val = introspect_docs ( defaults [ i ] ) <EOL> routine_doc . posarg_defaults [ i + offset ] = default_val <EOL> if isinstance ( routine , MethodType ) and routine . im_self is not None : <EOL> routine_doc . posargs = routine_doc . posargs [ <NUM_LIT:1> : ] <EOL> routine_doc . posarg_defaults = routine_doc . posarg_defaults [ <NUM_LIT:1> : ] <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> routine_doc . lineno = func . func_code . co_firstlineno <EOL> else : <EOL> routine_doc . posargs = [ '<STR_LIT>' ] <EOL> routine_doc . posarg_defaults = [ None ] <EOL> routine_doc . kwarg = None <EOL> routine_doc . vararg = None <EOL> if isinstance ( routine , staticmethod ) : <EOL> routine_doc . specialize_to ( StaticMethodDoc ) <EOL> if isinstance ( routine , classmethod ) : <EOL> routine_doc . specialize_to ( ClassMethodDoc ) <EOL> return routine_doc <EOL> def introspect_property ( prop , prop_doc , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> prop_doc . specialize_to ( PropertyDoc ) <EOL> prop_doc . docstring = get_docstring ( prop , module_name = module_name ) <EOL> if hasattr ( prop , '<STR_LIT>' ) : <EOL> prop_doc . fget = introspect_docs ( prop . fget ) <EOL> prop_doc . fset = introspect_docs ( prop . fset ) <EOL> prop_doc . fdel = introspect_docs ( prop . fdel ) <EOL> return prop_doc <EOL> def introspect_other ( val , val_doc , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> val_doc . specialize_to ( GenericValueDoc ) <EOL> return val_doc <EOL> def isclass ( object ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( object , tuple ( _CLASS_TYPES ) ) <EOL> _CLASS_TYPES = set ( [ TypeType , ClassType ] ) <EOL> """<STR_LIT>""" <EOL> def register_class_type ( typ ) : <EOL> """<STR_LIT>""" <EOL> _CLASS_TYPES . add ( typ ) <EOL> __future_check_works = None <EOL> def is_future_feature ( object ) : <EOL> """<STR_LIT>""" <EOL> global __future_check_works <EOL> if __future_check_works is not None : <EOL> if __future_check_works : <EOL> import __future__ <EOL> return isinstance ( object , __future__ . _Feature ) <EOL> else : <EOL> return False <EOL> else : <EOL> __future_check_works = True <EOL> try : <EOL> return is_future_feature ( object ) <EOL> except : <EOL> __future_check_works = False <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return False <EOL> def get_docstring ( value , module_name = None ) : <EOL> """<STR_LIT>""" <EOL> docstring = getattr ( value , '<STR_LIT>' , None ) <EOL> if docstring is None : <EOL> return None <EOL> elif isinstance ( docstring , unicode ) : <EOL> return docstring <EOL> elif isinstance ( docstring , str ) : <EOL> try : return unicode ( docstring , '<STR_LIT:ascii>' ) <EOL> except UnicodeDecodeError : <EOL> if module_name is None : <EOL> module_name = get_containing_module ( value ) <EOL> if module_name is not None : <EOL> try : <EOL> module = get_value_from_name ( module_name ) <EOL> filename = py_src_filename ( module . __file__ ) <EOL> encoding = epydoc . docparser . get_module_encoding ( filename ) <EOL> return unicode ( docstring , encoding ) <EOL> except KeyboardInterrupt : raise <EOL> except Exception : pass <EOL> if hasattr ( value , '<STR_LIT>' ) : name = value . __name__ <EOL> else : name = repr ( value ) <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % name ) <EOL> return unicode ( docstring , '<STR_LIT>' ) <EOL> return None <EOL> elif value is BuiltinMethodType : <EOL> return None <EOL> else : <EOL> if hasattr ( value , '<STR_LIT>' ) : name = value . __name__ <EOL> else : name = repr ( value ) <EOL> log . warning ( "<STR_LIT>" % <EOL> name ) <EOL> return None <EOL> def get_canonical_name ( value , strict = False ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( value , '<STR_LIT>' ) : return UNKNOWN <EOL> if isinstance ( value , ModuleType ) : <EOL> try : <EOL> dotted_name = DottedName ( value . __name__ , strict = strict ) <EOL> if verify_name ( value , dotted_name ) is UNKNOWN : <EOL> log . warning ( "<STR_LIT>" <EOL> "<STR_LIT>" % dotted_name ) <EOL> return DottedName ( value . __name__ + "<STR_LIT:'>" ) <EOL> except DottedName . InvalidDottedName : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> filename = '<STR_LIT:%s>' % value . __str__ <EOL> dotted_name = DottedName ( munge_script_name ( filename ) ) <EOL> elif isclass ( value ) : <EOL> if value . __module__ == '<STR_LIT>' : <EOL> dotted_name = DottedName ( value . __name__ , strict = strict ) <EOL> else : <EOL> dotted_name = DottedName ( value . __module__ , value . __name__ , <EOL> strict = strict ) <EOL> elif ( inspect . ismethod ( value ) and value . im_self is not None and <EOL> value . im_class is ClassType and <EOL> not value . __name__ . startswith ( '<STR_LIT:<>' ) ) : <EOL> class_name = get_canonical_name ( value . im_self ) <EOL> if class_name is UNKNOWN : return UNKNOWN <EOL> dotted_name = DottedName ( class_name , value . __name__ , strict = strict ) <EOL> elif ( inspect . ismethod ( value ) and <EOL> not value . __name__ . startswith ( '<STR_LIT:<>' ) ) : <EOL> class_name = get_canonical_name ( value . im_class ) <EOL> if class_name is UNKNOWN : return UNKNOWN <EOL> dotted_name = DottedName ( class_name , value . __name__ , strict = strict ) <EOL> elif ( isinstance ( value , FunctionType ) and <EOL> not value . __name__ . startswith ( '<STR_LIT:<>' ) ) : <EOL> module_name = _find_function_module ( value ) <EOL> if module_name is None : return UNKNOWN <EOL> dotted_name = DottedName ( module_name , value . __name__ , strict = strict ) <EOL> else : <EOL> return UNKNOWN <EOL> return verify_name ( value , dotted_name ) <EOL> def verify_name ( value , dotted_name ) : <EOL> """<STR_LIT>""" <EOL> if dotted_name is UNKNOWN : return UNKNOWN <EOL> if len ( dotted_name ) == <NUM_LIT:1> and hasattr ( __builtin__ , dotted_name [ <NUM_LIT:0> ] ) : <EOL> return dotted_name <EOL> named_value = sys . modules . get ( dotted_name [ <NUM_LIT:0> ] ) <EOL> if named_value is None : return UNKNOWN <EOL> for identifier in dotted_name [ <NUM_LIT:1> : ] : <EOL> try : named_value = getattr ( named_value , identifier ) <EOL> except : return UNKNOWN <EOL> if value is named_value : <EOL> return dotted_name <EOL> else : <EOL> return UNKNOWN <EOL> def value_repr ( value ) : <EOL> try : <EOL> s = '<STR_LIT>' % value <EOL> if isinstance ( s , str ) : <EOL> s = decode_with_backslashreplace ( s ) <EOL> return s <EOL> except : <EOL> return UNKNOWN <EOL> def get_containing_module ( value ) : <EOL> """<STR_LIT>""" <EOL> if inspect . ismodule ( value ) : <EOL> return DottedName ( value . __name__ ) <EOL> elif isclass ( value ) : <EOL> return DottedName ( value . __module__ ) <EOL> elif ( inspect . ismethod ( value ) and value . im_self is not None and <EOL> value . im_class is ClassType ) : <EOL> return DottedName ( value . im_self . __module__ ) <EOL> elif inspect . ismethod ( value ) : <EOL> return DottedName ( value . im_class . __module__ ) <EOL> elif inspect . isroutine ( value ) : <EOL> module = _find_function_module ( value ) <EOL> if module is None : return None <EOL> return DottedName ( module ) <EOL> else : <EOL> return None <EOL> def _find_function_module ( func ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> return func . __module__ <EOL> try : <EOL> module = inspect . getmodule ( func ) <EOL> if module : return module . __name__ <EOL> except KeyboardInterrupt : raise <EOL> except : pass <EOL> for module in sys . modules . values ( ) : <EOL> if ( hasattr ( module , '<STR_LIT>' ) and <EOL> hasattr ( func , '<STR_LIT>' ) and <EOL> func . func_globals is module . __dict__ ) : <EOL> return module . __name__ <EOL> return None <EOL> _introspecter_registry = [ ] <EOL> def register_introspecter ( applicability_test , introspecter , priority = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> _introspecter_registry . append ( ( priority , applicability_test , <EOL> introspecter ) ) <EOL> _introspecter_registry . sort ( ) <EOL> def _get_introspecter ( value ) : <EOL> for ( priority , applicability_test , introspecter ) in _introspecter_registry : <EOL> if applicability_test ( value ) : <EOL> return introspecter <EOL> else : <EOL> return introspect_other <EOL> def is_classmethod ( v ) : return isinstance ( v , classmethod ) <EOL> def is_staticmethod ( v ) : return isinstance ( v , staticmethod ) <EOL> def is_property ( v ) : return isinstance ( v , property ) <EOL> register_introspecter ( inspect . ismodule , introspect_module , priority = <NUM_LIT:20> ) <EOL> register_introspecter ( isclass , introspect_class , priority = <NUM_LIT> ) <EOL> register_introspecter ( inspect . isroutine , introspect_routine , priority = <NUM_LIT> ) <EOL> register_introspecter ( is_property , introspect_property , priority = <NUM_LIT:30> ) <EOL> try : <EOL> import array <EOL> getset_type = type ( array . array . typecode ) <EOL> del array <EOL> def is_getset ( v ) : return isinstance ( v , getset_type ) <EOL> register_introspecter ( is_getset , introspect_property , priority = <NUM_LIT:32> ) <EOL> except : <EOL> pass <EOL> try : <EOL> import datetime <EOL> member_type = type ( datetime . timedelta . days ) <EOL> del datetime <EOL> def is_member ( v ) : return isinstance ( v , member_type ) <EOL> register_introspecter ( is_member , introspect_property , priority = <NUM_LIT> ) <EOL> except : <EOL> pass <EOL> def get_value_from_filename ( filename , context = None ) : <EOL> filename = os . path . normpath ( os . path . abspath ( filename ) ) <EOL> basedir = os . path . split ( filename ) [ <NUM_LIT:0> ] <EOL> name = os . path . splitext ( os . path . split ( filename ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:0> ] <EOL> if name == '<STR_LIT>' : <EOL> basedir , name = os . path . split ( basedir ) <EOL> name = DottedName ( name ) <EOL> if context is None : <EOL> while is_package_dir ( basedir ) : <EOL> basedir , pkg_name = os . path . split ( basedir ) <EOL> name = DottedName ( pkg_name , name ) <EOL> if context is not None : <EOL> name = DottedName ( context . canonical_name , name ) <EOL> while context not in ( None , UNKNOWN ) : <EOL> pkg_dir = os . path . split ( context . filename ) [ <NUM_LIT:0> ] <EOL> basedir = os . path . split ( pkg_dir ) [ <NUM_LIT:0> ] <EOL> context = context . package <EOL> old_sys_path = sys . path [ : ] <EOL> try : <EOL> sys . path . insert ( <NUM_LIT:0> , basedir ) <EOL> _import ( str ( name ) ) <EOL> if str ( name ) in sys . modules : <EOL> return sys . modules [ str ( name ) ] <EOL> else : <EOL> return get_value_from_name ( name ) <EOL> finally : <EOL> sys . path = old_sys_path <EOL> def get_value_from_scriptname ( filename ) : <EOL> name = munge_script_name ( filename ) <EOL> return _import ( name , filename ) <EOL> def get_value_from_name ( name , globs = None ) : <EOL> """<STR_LIT>""" <EOL> name = DottedName ( name ) <EOL> try : <EOL> module = _import ( name [ <NUM_LIT:0> ] ) <EOL> except ImportError , e : <EOL> if globs is None : globs = __builtin__ . __dict__ <EOL> if name [ <NUM_LIT:0> ] in globs : <EOL> try : return _lookup ( globs [ name [ <NUM_LIT:0> ] ] , name [ <NUM_LIT:1> : ] ) <EOL> except : raise e <EOL> else : <EOL> raise <EOL> for i in range ( <NUM_LIT:1> , len ( name ) ) : <EOL> try : return _lookup ( module , name [ i : ] ) <EOL> except ImportError : pass <EOL> module = _import ( '<STR_LIT:.>' . join ( name [ : i + <NUM_LIT:1> ] ) ) <EOL> module = _lookup ( module , name [ <NUM_LIT:1> : i + <NUM_LIT:1> ] ) <EOL> return module <EOL> def _lookup ( module , name ) : <EOL> val = module <EOL> for i , identifier in enumerate ( name ) : <EOL> try : val = getattr ( val , identifier ) <EOL> except AttributeError : <EOL> exc_msg = ( '<STR_LIT>' % <EOL> ( identifier , '<STR_LIT:.>' . join ( name [ : <NUM_LIT:1> + i ] ) ) ) <EOL> raise ImportError ( exc_msg ) <EOL> return val <EOL> def _import ( name , filename = None ) : <EOL> """<STR_LIT>""" <EOL> old_sys = sys . __dict__ . copy ( ) <EOL> old_sys_path = sys . path [ : ] <EOL> old_builtins = __builtin__ . __dict__ . copy ( ) <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> sys . stdin = sys . stdout = sys . stderr = _dev_null <EOL> sys . __stdin__ = sys . __stdout__ = sys . __stderr__ = _dev_null <EOL> sys . argv = [ '<STR_LIT>' ] <EOL> try : <EOL> try : <EOL> if filename is None : <EOL> return __import__ ( name ) <EOL> else : <EOL> return imp . load_source ( name , filename ) <EOL> except KeyboardInterrupt : raise <EOL> except : <EOL> exc_typ , exc_val , exc_tb = sys . exc_info ( ) <EOL> if exc_val is None : <EOL> estr = '<STR_LIT:%s>' % ( exc_typ , ) <EOL> else : <EOL> estr = '<STR_LIT>' % ( exc_typ . __name__ , exc_val ) <EOL> if exc_tb . tb_next is not None : <EOL> estr += '<STR_LIT>' % ( exc_tb . tb_next . tb_lineno , ) <EOL> raise ImportError ( estr ) <EOL> finally : <EOL> __builtin__ . __dict__ . clear ( ) <EOL> __builtin__ . __dict__ . update ( old_builtins ) <EOL> sys . __dict__ . clear ( ) <EOL> sys . __dict__ . update ( old_sys ) <EOL> sys . path = old_sys_path <EOL> def introspect_docstring_lineno ( api_doc ) : <EOL> """<STR_LIT>""" <EOL> if api_doc . docstring_lineno is not UNKNOWN : <EOL> return api_doc . docstring_lineno <EOL> if isinstance ( api_doc , ValueDoc ) and api_doc . pyval is not UNKNOWN : <EOL> try : <EOL> lines , lineno = inspect . findsource ( api_doc . pyval ) <EOL> if not isinstance ( api_doc , ModuleDoc ) : lineno += <NUM_LIT:1> <EOL> for lineno in range ( lineno , len ( lines ) ) : <EOL> if lines [ lineno ] . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . strip ( ) : <EOL> api_doc . docstring_lineno = lineno + <NUM_LIT:1> <EOL> return lineno + <NUM_LIT:1> <EOL> except IOError : pass <EOL> except TypeError : pass <EOL> except IndexError : <EOL> log . warning ( '<STR_LIT>' <EOL> % api_doc . canonical_name ) <EOL> return None <EOL> class _DevNull : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . closed = <NUM_LIT:1> <EOL> self . mode = '<STR_LIT>' <EOL> self . softspace = <NUM_LIT:0> <EOL> self . name = '<STR_LIT>' <EOL> def close ( self ) : pass <EOL> def flush ( self ) : pass <EOL> def read ( self , size = <NUM_LIT:0> ) : return '<STR_LIT>' <EOL> def readline ( self , size = <NUM_LIT:0> ) : return '<STR_LIT>' <EOL> def readlines ( self , sizehint = <NUM_LIT:0> ) : return [ ] <EOL> def seek ( self , offset , whence = <NUM_LIT:0> ) : pass <EOL> def tell ( self ) : return <NUM_LIT:0> L <EOL> def truncate ( self , size = <NUM_LIT:0> ) : pass <EOL> def write ( self , str ) : pass <EOL> def writelines ( self , sequence ) : pass <EOL> xreadlines = readlines <EOL> _dev_null = _DevNull ( ) <EOL> try : <EOL> from zope . interface . interface import InterfaceClass as _ZopeInterfaceClass <EOL> register_class_type ( _ZopeInterfaceClass ) <EOL> except : <EOL> pass <EOL> try : <EOL> from ExtensionClass import ExtensionClass as _ExtensionClass <EOL> _ZopeType = type ( _ExtensionClass ) <EOL> def _is_zope_type ( val ) : <EOL> return isinstance ( val , _ZopeType ) <EOL> register_introspecter ( _is_zope_type , introspect_class ) <EOL> from ExtensionClass import PythonMethodType as _ZopeMethodType <EOL> from ExtensionClass import ExtensionMethodType as _ZopeCMethodType <EOL> def _is_zope_method ( val ) : <EOL> return isinstance ( val , ( _ZopeMethodType , _ZopeCMethodType ) ) <EOL> register_introspecter ( _is_zope_method , introspect_routine ) <EOL> except : <EOL> pass <EOL> <NUM_LIT:0> <EOL> """<STR_LIT>""" </s>
