<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import types , re , os . path , pickle <EOL> from epydoc import log <EOL> import epydoc <EOL> import __builtin__ <EOL> from epydoc . compat import * <EOL> from epydoc . util import decode_with_backslashreplace , py_src_filename <EOL> import epydoc . markup . pyval_repr <EOL> class DottedName : <EOL> """<STR_LIT>""" <EOL> UNREACHABLE = "<STR_LIT>" <EOL> _IDENTIFIER_RE = re . compile ( """<STR_LIT>""" <EOL> % re . escape ( UNREACHABLE ) ) <EOL> class InvalidDottedName ( ValueError ) : <EOL> """<STR_LIT>""" <EOL> _ok_identifiers = set ( ) <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * pieces ) : <EOL> """<STR_LIT>""" <EOL> if len ( pieces ) == <NUM_LIT:1> and isinstance ( pieces [ <NUM_LIT:0> ] , tuple ) : <EOL> self . _identifiers = pieces [ <NUM_LIT:0> ] <EOL> return <EOL> if len ( pieces ) == <NUM_LIT:0> : <EOL> raise DottedName . InvalidDottedName ( '<STR_LIT>' ) <EOL> self . _identifiers = [ ] <EOL> for piece in pieces : <EOL> if isinstance ( piece , DottedName ) : <EOL> self . _identifiers += piece . _identifiers <EOL> elif isinstance ( piece , basestring ) : <EOL> for subpiece in piece . split ( '<STR_LIT:.>' ) : <EOL> if piece not in self . _ok_identifiers : <EOL> if self . _IDENTIFIER_RE . match ( subpiece ) : <EOL> self . _ok_identifiers . add ( piece ) <EOL> else : <EOL> raise DottedName . InvalidDottedName ( <EOL> '<STR_LIT>' % ( piece , ) ) <EOL> self . _identifiers . append ( subpiece ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( piece , ) ) <EOL> self . _identifiers = tuple ( self . _identifiers ) <EOL> def __repr__ ( self ) : <EOL> idents = [ ` ident ` for ident in self . _identifiers ] <EOL> return '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( idents ) + '<STR_LIT:)>' <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:.>' . join ( self . _identifiers ) <EOL> def __add__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , ( basestring , DottedName ) ) : <EOL> return DottedName ( self , other ) <EOL> else : <EOL> return DottedName ( self , * other ) <EOL> def __radd__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , ( basestring , DottedName ) ) : <EOL> return DottedName ( other , self ) <EOL> else : <EOL> return DottedName ( * ( list ( other ) + [ self ] ) ) <EOL> def __getitem__ ( self , i ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( i , types . SliceType ) : <EOL> pieces = self . _identifiers [ i . start : i . stop ] <EOL> if pieces : return DottedName ( pieces ) <EOL> else : return [ ] <EOL> else : <EOL> return self . _identifiers [ i ] <EOL> def __hash__ ( self ) : <EOL> return hash ( self . _identifiers ) <EOL> def __cmp__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( other , DottedName ) : <EOL> return - <NUM_LIT:1> <EOL> return cmp ( self . _identifiers , other . _identifiers ) <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . _identifiers ) <EOL> def container ( self ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . _identifiers ) == <NUM_LIT:1> : <EOL> return None <EOL> else : <EOL> return DottedName ( * self . _identifiers [ : - <NUM_LIT:1> ] ) <EOL> def dominates ( self , name , strict = False ) : <EOL> """<STR_LIT>""" <EOL> len_self = len ( self . _identifiers ) <EOL> len_name = len ( name . _identifiers ) <EOL> if ( len_self > len_name ) or ( strict and len_self == len_name ) : <EOL> return False <EOL> return ( ( self . _identifiers [ <NUM_LIT:0> ] == name . _identifiers [ <NUM_LIT:0> ] ) and <EOL> self . _identifiers == name . _identifiers [ : len_self ] ) <EOL> def contextualize ( self , context ) : <EOL> """<STR_LIT>""" <EOL> if context is UNKNOWN or not context or len ( self ) <= <NUM_LIT:1> : <EOL> return self <EOL> if self [ <NUM_LIT:0> ] == context [ <NUM_LIT:0> ] : <EOL> return self [ <NUM_LIT:1> : ] . contextualize ( context [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> return self <EOL> for i in range ( min ( len ( context ) , len ( self ) ) ) : <EOL> if self . _identifiers [ i ] != context . _identifiers [ i ] : <EOL> first_difference = i <EOL> break <EOL> else : <EOL> first_difference = i + <NUM_LIT:1> <EOL> if first_difference == <NUM_LIT:0> : <EOL> return self <EOL> elif first_difference == len ( self ) : <EOL> return self [ - <NUM_LIT:1> : ] <EOL> else : <EOL> return self [ first_difference : ] <EOL> class _Sentinel : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def __nonzero__ ( self ) : <EOL> raise ValueError ( '<STR_LIT>' % <EOL> self . name ) <EOL> UNKNOWN = _Sentinel ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> class APIDoc ( object ) : <EOL> """<STR_LIT>""" <EOL> docstring = UNKNOWN <EOL> """<STR_LIT>""" <EOL> docstring_lineno = UNKNOWN <EOL> """<STR_LIT>""" <EOL> descr = UNKNOWN <EOL> """<STR_LIT>""" <EOL> summary = UNKNOWN <EOL> """<STR_LIT>""" <EOL> other_docs = UNKNOWN <EOL> """<STR_LIT>""" <EOL> metadata = UNKNOWN <EOL> """<STR_LIT>""" <EOL> extra_docstring_fields = UNKNOWN <EOL> """<STR_LIT>""" <EOL> docs_extracted_by = UNKNOWN <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if epydoc . DEBUG : <EOL> for key in kwargs : <EOL> if key [ <NUM_LIT:0> ] != '<STR_LIT:_>' and not hasattr ( self . __class__ , key ) : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> ( self . __class__ . __name__ , key ) ) <EOL> self . __dict__ . update ( kwargs ) <EOL> def _debug_setattr ( self , attr , val ) : <EOL> """<STR_LIT>""" <EOL> if attr . startswith ( '<STR_LIT:_>' ) : <EOL> return object . __setattr__ ( self , attr , val ) <EOL> if not hasattr ( self , attr ) : <EOL> raise AttributeError ( '<STR_LIT>' % <EOL> ( self . __class__ . __name__ , attr ) ) <EOL> self . __dict__ [ attr ] = val <EOL> if epydoc . DEBUG : <EOL> __setattr__ = _debug_setattr <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . __class__ . __name__ <EOL> def pp ( self , doublespace = <NUM_LIT:0> , depth = <NUM_LIT:5> , exclude = ( ) , include = ( ) ) : <EOL> """<STR_LIT>""" <EOL> return pp_apidoc ( self , doublespace , depth , exclude , include ) <EOL> __str__ = pp <EOL> def specialize_to ( self , cls ) : <EOL> """<STR_LIT>""" <EOL> if not issubclass ( cls , self . __class__ ) : <EOL> raise ValueError ( '<STR_LIT>' % cls ) <EOL> self . __class__ = cls <EOL> if self . __mergeset is not None : <EOL> for apidoc in self . __mergeset : <EOL> apidoc . __class__ = cls <EOL> self . __init__ ( ** self . __dict__ ) <EOL> __has_been_hashed = False <EOL> """<STR_LIT>""" <EOL> def __hash__ ( self ) : <EOL> self . __has_been_hashed = True <EOL> return id ( self . __dict__ ) <EOL> def __cmp__ ( self , other ) : <EOL> if not isinstance ( other , APIDoc ) : return - <NUM_LIT:1> <EOL> if self . __dict__ is other . __dict__ : return <NUM_LIT:0> <EOL> name_cmp = cmp ( self . canonical_name , other . canonical_name ) <EOL> if name_cmp == <NUM_LIT:0> : return - <NUM_LIT:1> <EOL> else : return name_cmp <EOL> def is_detailed ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . other_docs is True : <EOL> return True <EOL> if self . metadata is not UNKNOWN : <EOL> return bool ( self . metadata ) <EOL> __mergeset = None <EOL> """<STR_LIT>""" <EOL> def merge_and_overwrite ( self , other , ignore_hash_conflict = False ) : <EOL> """<STR_LIT>""" <EOL> if ( self . __dict__ is other . __dict__ and <EOL> self . __class__ is other . __class__ ) : return self <EOL> if other . __has_been_hashed and not ignore_hash_conflict : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" % other ) <EOL> a , b = ( self . __mergeset , other . __mergeset ) <EOL> mergeset = ( self . __mergeset or [ self ] ) + ( other . __mergeset or [ other ] ) <EOL> other . __dict__ . clear ( ) <EOL> for apidoc in mergeset : <EOL> apidoc . __class__ = self . __class__ <EOL> apidoc . __dict__ = self . __dict__ <EOL> self . __mergeset = mergeset <EOL> assert self in mergeset and other in mergeset <EOL> for apidoc in mergeset : <EOL> assert apidoc . __dict__ is self . __dict__ <EOL> return self <EOL> def apidoc_links ( self , ** filters ) : <EOL> """<STR_LIT>""" <EOL> return [ ] <EOL> def reachable_valdocs ( root , ** filters ) : <EOL> """<STR_LIT>""" <EOL> apidoc_queue = list ( root ) <EOL> val_set = set ( ) <EOL> var_set = set ( ) <EOL> while apidoc_queue : <EOL> api_doc = apidoc_queue . pop ( ) <EOL> if isinstance ( api_doc , ValueDoc ) : <EOL> val_set . add ( api_doc ) <EOL> else : <EOL> var_set . add ( api_doc ) <EOL> apidoc_queue . extend ( [ v for v in api_doc . apidoc_links ( ** filters ) <EOL> if v not in val_set and v not in var_set ] ) <EOL> return val_set <EOL> class VariableDoc ( APIDoc ) : <EOL> """<STR_LIT>""" <EOL> name = UNKNOWN <EOL> """<STR_LIT>""" <EOL> container = UNKNOWN <EOL> """<STR_LIT>""" <EOL> canonical_name = UNKNOWN <EOL> """<STR_LIT>""" <EOL> value = UNKNOWN <EOL> """<STR_LIT>""" <EOL> type_descr = UNKNOWN <EOL> """<STR_LIT>""" <EOL> imported_from = UNKNOWN <EOL> """<STR_LIT>""" <EOL> is_imported = UNKNOWN <EOL> """<STR_LIT>""" <EOL> is_instvar = UNKNOWN <EOL> """<STR_LIT>""" <EOL> overrides = UNKNOWN <EOL> """<STR_LIT>""" <EOL> is_alias = UNKNOWN <EOL> """<STR_LIT>""" <EOL> is_public = UNKNOWN <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> APIDoc . __init__ ( self , ** kwargs ) <EOL> if self . is_public is UNKNOWN and self . name is not UNKNOWN : <EOL> self . is_public = ( not self . name . startswith ( '<STR_LIT:_>' ) or <EOL> self . name . endswith ( '<STR_LIT:_>' ) ) <EOL> def __repr__ ( self ) : <EOL> if self . canonical_name is not UNKNOWN : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . canonical_name ) <EOL> if self . name is not UNKNOWN : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> else : <EOL> return '<STR_LIT>' % self . __class__ . __name__ <EOL> def _get_defining_module ( self ) : <EOL> if self . container is UNKNOWN : <EOL> return UNKNOWN <EOL> return self . container . defining_module <EOL> defining_module = property ( _get_defining_module , doc = """<STR_LIT>""" ) <EOL> def apidoc_links ( self , ** filters ) : <EOL> if self . value in ( None , UNKNOWN ) : <EOL> return [ ] <EOL> else : <EOL> return [ self . value ] <EOL> def is_detailed ( self ) : <EOL> pval = super ( VariableDoc , self ) . is_detailed ( ) <EOL> if pval or self . value in ( None , UNKNOWN ) : <EOL> return pval <EOL> if ( self . overrides not in ( None , UNKNOWN ) and <EOL> isinstance ( self . value , RoutineDoc ) ) : <EOL> return True <EOL> if isinstance ( self . value , GenericValueDoc ) : <EOL> maxlen = self . value . SUMMARY_REPR_LINELEN - <NUM_LIT:3> - len ( self . name ) <EOL> return ( not self . value . summary_pyval_repr ( maxlen ) . is_complete ) <EOL> else : <EOL> return self . value . is_detailed ( ) <EOL> class ValueDoc ( APIDoc ) : <EOL> """<STR_LIT>""" <EOL> canonical_name = UNKNOWN <EOL> """<STR_LIT>""" <EOL> pyval = UNKNOWN <EOL> """<STR_LIT>""" <EOL> parse_repr = UNKNOWN <EOL> """<STR_LIT>""" <EOL> REPR_MAXLINES = <NUM_LIT:5> <EOL> """<STR_LIT>""" <EOL> REPR_LINELEN = <NUM_LIT> <EOL> """<STR_LIT>""" <EOL> SUMMARY_REPR_LINELEN = <NUM_LIT> <EOL> """<STR_LIT>""" <EOL> REPR_MIN_SCORE = <NUM_LIT:0> <EOL> """<STR_LIT>""" <EOL> defining_module = UNKNOWN <EOL> """<STR_LIT>""" <EOL> proxy_for = None <EOL> """<STR_LIT>""" <EOL> toktree = UNKNOWN <EOL> def __repr__ ( self ) : <EOL> if self . canonical_name is not UNKNOWN : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . canonical_name ) <EOL> else : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , <EOL> self . summary_pyval_repr ( ) . to_plaintext ( None ) ) <EOL> def __setstate__ ( self , state ) : <EOL> self . __dict__ = state <EOL> def __getstate__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . pyval_repr ( ) , self . summary_pyval_repr ( ) <EOL> self . __pickle_state = self . __dict__ . copy ( ) <EOL> self . __pickle_state [ '<STR_LIT>' ] = UNKNOWN <EOL> if not isinstance ( self , GenericValueDoc ) : <EOL> assert self . __pickle_state != { } <EOL> return self . __pickle_state <EOL> def pyval_repr ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . __pyval_repr = epydoc . markup . pyval_repr . colorize_pyval ( <EOL> self . pyval , self . parse_repr , self . REPR_MIN_SCORE , <EOL> self . REPR_LINELEN , self . REPR_MAXLINES , linebreakok = True ) <EOL> return self . __pyval_repr <EOL> def summary_pyval_repr ( self , max_len = None ) : <EOL> """<STR_LIT>""" <EOL> if max_len is not None : <EOL> return epydoc . markup . pyval_repr . colorize_pyval ( <EOL> self . pyval , self . parse_repr , self . REPR_MIN_SCORE , <EOL> max_len , maxlines = <NUM_LIT:1> , linebreakok = False ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . __summary_pyval_repr = epydoc . markup . pyval_repr . colorize_pyval ( <EOL> self . pyval , self . parse_repr , self . REPR_MIN_SCORE , <EOL> self . SUMMARY_REPR_LINELEN , maxlines = <NUM_LIT:1> , linebreakok = False ) <EOL> return self . __summary_pyval_repr <EOL> def apidoc_links ( self , ** filters ) : <EOL> return [ ] <EOL> class GenericValueDoc ( ValueDoc ) : <EOL> """<STR_LIT>""" <EOL> canonical_name = None <EOL> def is_detailed ( self ) : <EOL> return ( not self . summary_pyval_repr ( ) . is_complete ) <EOL> class NamespaceDoc ( ValueDoc ) : <EOL> """<STR_LIT>""" <EOL> variables = UNKNOWN <EOL> """<STR_LIT>""" <EOL> sorted_variables = UNKNOWN <EOL> """<STR_LIT>""" <EOL> sort_spec = UNKNOWN <EOL> """<STR_LIT>""" <EOL> group_specs = UNKNOWN <EOL> """<STR_LIT>""" <EOL> variable_groups = UNKNOWN <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , { } ) <EOL> APIDoc . __init__ ( self , ** kwargs ) <EOL> assert self . variables is not UNKNOWN <EOL> def is_detailed ( self ) : <EOL> return True <EOL> def apidoc_links ( self , ** filters ) : <EOL> variables = filters . get ( '<STR_LIT>' , True ) <EOL> imports = filters . get ( '<STR_LIT>' , True ) <EOL> private = filters . get ( '<STR_LIT>' , True ) <EOL> if variables and imports and private : <EOL> return self . variables . values ( ) <EOL> elif not variables : <EOL> return [ ] <EOL> elif not imports and not private : <EOL> return [ v for v in self . variables . values ( ) if <EOL> v . is_imported != True and v . is_public != False ] <EOL> elif not private : <EOL> return [ v for v in self . variables . values ( ) if <EOL> v . is_public != False ] <EOL> elif not imports : <EOL> return [ v for v in self . variables . values ( ) if <EOL> v . is_imported != True ] <EOL> assert <NUM_LIT:0> , '<STR_LIT>' <EOL> def init_sorted_variables ( self ) : <EOL> """<STR_LIT>""" <EOL> unsorted = self . variables . copy ( ) <EOL> self . sorted_variables = [ ] <EOL> if self . sort_spec is not UNKNOWN : <EOL> for ident in self . sort_spec : <EOL> if ident in unsorted : <EOL> self . sorted_variables . append ( unsorted [ ident ] ) <EOL> del unsorted [ ident ] <EOL> elif '<STR_LIT:*>' in ident : <EOL> regexp = re . compile ( '<STR_LIT>' % ident . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) ) <EOL> for name , var_doc in unsorted . items ( ) : <EOL> if regexp . match ( name ) : <EOL> self . sorted_variables . append ( var_doc ) <EOL> unsorted . remove ( var_doc ) <EOL> var_docs = unsorted . items ( ) <EOL> var_docs . sort ( ) <EOL> for name , var_doc in var_docs : <EOL> self . sorted_variables . append ( var_doc ) <EOL> def init_variable_groups ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . sorted_variables is UNKNOWN : <EOL> self . init_sorted_variables <EOL> assert len ( self . sorted_variables ) == len ( self . variables ) <EOL> elts = [ ( v . name , v ) for v in self . sorted_variables ] <EOL> self . variable_groups = self . _init_grouping ( elts ) <EOL> def group_names ( self ) : <EOL> """<STR_LIT>""" <EOL> name_list = [ '<STR_LIT>' ] <EOL> name_set = set ( ) <EOL> for name , spec in self . group_specs : <EOL> if name not in name_set : <EOL> name_set . add ( name ) <EOL> name_list . append ( name ) <EOL> return name_list <EOL> def _init_grouping ( self , elts ) : <EOL> """<STR_LIT>""" <EOL> if len ( self . group_specs ) == <NUM_LIT:0> : <EOL> return { '<STR_LIT>' : [ elt [ <NUM_LIT:1> ] for elt in elts ] } <EOL> ungrouped = set ( [ elt_doc for ( elt_name , elt_doc ) in elts ] ) <EOL> groups = { } <EOL> for ( group_name , elt_names ) in self . group_specs : <EOL> group_re = re . compile ( '<STR_LIT:|>' . join ( [ n . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) + '<STR_LIT:$>' <EOL> for n in elt_names ] ) ) <EOL> group = groups . get ( group_name , [ ] ) <EOL> for elt_name , elt_doc in list ( elts ) : <EOL> if group_re . match ( elt_name ) : <EOL> group . append ( elt_doc ) <EOL> if elt_doc in ungrouped : <EOL> ungrouped . remove ( elt_doc ) <EOL> else : <EOL> log . warning ( "<STR_LIT>" % <EOL> ( self . canonical_name , elt_name ) ) <EOL> groups [ group_name ] = group <EOL> groups [ '<STR_LIT>' ] = [ elt_doc for ( elt_name , elt_doc ) in elts <EOL> if elt_doc in ungrouped ] <EOL> return groups <EOL> class ModuleDoc ( NamespaceDoc ) : <EOL> """<STR_LIT>""" <EOL> filename = UNKNOWN <EOL> """<STR_LIT>""" <EOL> docformat = UNKNOWN <EOL> """<STR_LIT>""" <EOL> submodules = UNKNOWN <EOL> """<STR_LIT>""" <EOL> submodule_groups = UNKNOWN <EOL> """<STR_LIT>""" <EOL> package = UNKNOWN <EOL> """<STR_LIT>""" <EOL> is_package = UNKNOWN <EOL> """<STR_LIT>""" <EOL> path = UNKNOWN <EOL> """<STR_LIT>""" <EOL> imports = UNKNOWN <EOL> """<STR_LIT>""" <EOL> def apidoc_links ( self , ** filters ) : <EOL> val_docs = NamespaceDoc . apidoc_links ( self , ** filters ) <EOL> if ( filters . get ( '<STR_LIT>' , True ) and <EOL> self . package not in ( None , UNKNOWN ) ) : <EOL> val_docs . append ( self . package ) <EOL> if ( filters . get ( '<STR_LIT>' , True ) and <EOL> self . submodules not in ( None , UNKNOWN ) ) : <EOL> val_docs += self . submodules <EOL> return val_docs <EOL> def init_submodule_groups ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . submodules in ( None , UNKNOWN ) : <EOL> return <EOL> self . submodules = sorted ( self . submodules , <EOL> key = lambda m : m . canonical_name ) <EOL> elts = [ ( m . canonical_name [ - <NUM_LIT:1> ] , m ) for m in self . submodules ] <EOL> self . submodule_groups = self . _init_grouping ( elts ) <EOL> def select_variables ( self , group = None , value_type = None , public = None , <EOL> imported = None , detailed = None ) : <EOL> """<STR_LIT>""" <EOL> if ( self . sorted_variables is UNKNOWN or <EOL> self . variable_groups is UNKNOWN ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if group is None : var_list = self . sorted_variables <EOL> else : <EOL> var_list = self . variable_groups [ group ] <EOL> if public is True : <EOL> var_list = [ v for v in var_list if v . is_public is not False ] <EOL> elif public is False : <EOL> var_list = [ v for v in var_list if v . is_public is False ] <EOL> if imported is True : <EOL> var_list = [ v for v in var_list if v . is_imported is True ] <EOL> elif imported is False : <EOL> var_list = [ v for v in var_list if v . is_imported is not True ] <EOL> if detailed is True : <EOL> var_list = [ v for v in var_list if v . is_detailed ( ) is True ] <EOL> elif detailed is False : <EOL> var_list = [ v for v in var_list if v . is_detailed ( ) is not True ] <EOL> if value_type is None : <EOL> return var_list <EOL> elif value_type == '<STR_LIT:class>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , ClassDoc ) ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if isinstance ( var_doc . value , RoutineDoc ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if not isinstance ( var_doc . value , <EOL> ( ClassDoc , RoutineDoc , ModuleDoc ) ) <EOL> and var_doc . name . upper ( ) == var_doc . name ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if not isinstance ( var_doc . value , <EOL> ( ClassDoc , RoutineDoc , ModuleDoc ) ) <EOL> and var_doc . name . upper ( ) != var_doc . name ] <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % value_type ) <EOL> class ClassDoc ( NamespaceDoc ) : <EOL> """<STR_LIT>""" <EOL> bases = UNKNOWN <EOL> """<STR_LIT>""" <EOL> subclasses = UNKNOWN <EOL> """<STR_LIT>""" <EOL> def apidoc_links ( self , ** filters ) : <EOL> val_docs = NamespaceDoc . apidoc_links ( self , ** filters ) <EOL> if ( filters . get ( '<STR_LIT>' , True ) and <EOL> self . bases not in ( None , UNKNOWN ) ) : <EOL> val_docs += self . bases <EOL> if ( filters . get ( '<STR_LIT>' , True ) and <EOL> self . subclasses not in ( None , UNKNOWN ) ) : <EOL> val_docs += self . subclasses <EOL> return val_docs <EOL> def is_type ( self ) : <EOL> if self . canonical_name == DottedName ( '<STR_LIT:type>' ) : return True <EOL> if self . bases is UNKNOWN : return False <EOL> for base in self . bases : <EOL> if isinstance ( base , ClassDoc ) and base . is_type ( ) : <EOL> return True <EOL> return False <EOL> def is_exception ( self ) : <EOL> if self . canonical_name == DottedName ( '<STR_LIT>' ) : return True <EOL> if self . bases is UNKNOWN : return False <EOL> for base in self . bases : <EOL> if isinstance ( base , ClassDoc ) and base . is_exception ( ) : <EOL> return True <EOL> return False <EOL> def is_newstyle_class ( self ) : <EOL> if self . canonical_name == DottedName ( '<STR_LIT:object>' ) : return True <EOL> if self . bases is UNKNOWN : return False <EOL> for base in self . bases : <EOL> if isinstance ( base , ClassDoc ) and base . is_newstyle_class ( ) : <EOL> return True <EOL> return False <EOL> def mro ( self , warn_about_bad_bases = False ) : <EOL> if self . is_newstyle_class ( ) : <EOL> return self . _c3_mro ( warn_about_bad_bases ) <EOL> else : <EOL> return self . _dfs_bases ( [ ] , set ( ) , warn_about_bad_bases ) <EOL> def _dfs_bases ( self , mro , seen , warn_about_bad_bases ) : <EOL> if self in seen : return mro <EOL> mro . append ( self ) <EOL> seen . add ( self ) <EOL> if self . bases is not UNKNOWN : <EOL> for base in self . bases : <EOL> if isinstance ( base , ClassDoc ) and base . proxy_for is None : <EOL> base . _dfs_bases ( mro , seen , warn_about_bad_bases ) <EOL> elif warn_about_bad_bases : <EOL> self . _report_bad_base ( base ) <EOL> return mro <EOL> def _c3_mro ( self , warn_about_bad_bases ) : <EOL> """<STR_LIT>""" <EOL> bases = [ base for base in self . bases if isinstance ( base , ClassDoc ) ] <EOL> if len ( bases ) != len ( self . bases ) and warn_about_bad_bases : <EOL> for base in self . bases : <EOL> if ( not isinstance ( base , ClassDoc ) or <EOL> base . proxy_for is not None ) : <EOL> self . _report_bad_base ( base ) <EOL> w = [ warn_about_bad_bases ] * len ( bases ) <EOL> return self . _c3_merge ( [ [ self ] ] + map ( ClassDoc . _c3_mro , bases , w ) + <EOL> [ list ( bases ) ] ) <EOL> def _report_bad_base ( self , base ) : <EOL> if not isinstance ( base , ClassDoc ) : <EOL> log . warning ( "<STR_LIT>" % <EOL> ( self . canonical_name , base . canonical_name ) ) <EOL> elif base . proxy_for is not None : <EOL> log . warning ( "<STR_LIT>" % <EOL> ( self . canonical_name , base . proxy_for ) ) <EOL> def _c3_merge ( self , seqs ) : <EOL> """<STR_LIT>""" <EOL> res = [ ] <EOL> while <NUM_LIT:1> : <EOL> nonemptyseqs = [ seq for seq in seqs if seq ] <EOL> if not nonemptyseqs : return res <EOL> for seq in nonemptyseqs : <EOL> cand = seq [ <NUM_LIT:0> ] <EOL> nothead = [ s for s in nonemptyseqs if cand in s [ <NUM_LIT:1> : ] ] <EOL> if nothead : cand = None <EOL> else : break <EOL> if not cand : raise "<STR_LIT>" <EOL> res . append ( cand ) <EOL> for seq in nonemptyseqs : <EOL> if seq [ <NUM_LIT:0> ] == cand : del seq [ <NUM_LIT:0> ] <EOL> def select_variables ( self , group = None , value_type = None , inherited = None , <EOL> public = None , imported = None , detailed = None ) : <EOL> """<STR_LIT>""" <EOL> if ( self . sorted_variables is UNKNOWN or <EOL> self . variable_groups is UNKNOWN ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if group is None : var_list = self . sorted_variables <EOL> else : var_list = self . variable_groups [ group ] <EOL> if public is True : <EOL> var_list = [ v for v in var_list if v . is_public is not False ] <EOL> elif public is False : <EOL> var_list = [ v for v in var_list if v . is_public is False ] <EOL> if inherited is None : pass <EOL> elif inherited : <EOL> var_list = [ v for v in var_list if v . container != self ] <EOL> else : <EOL> var_list = [ v for v in var_list if v . container == self ] <EOL> if imported is True : <EOL> var_list = [ v for v in var_list if v . is_imported is True ] <EOL> elif imported is False : <EOL> var_list = [ v for v in var_list if v . is_imported is not True ] <EOL> if detailed is True : <EOL> var_list = [ v for v in var_list if v . is_detailed ( ) is True ] <EOL> elif detailed is False : <EOL> var_list = [ v for v in var_list if v . is_detailed ( ) is not True ] <EOL> if value_type is None : <EOL> return var_list <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , RoutineDoc ) and <EOL> var_doc . value . is_event == False and <EOL> var_doc . is_instvar in ( False , UNKNOWN ) ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , RoutineDoc ) and <EOL> not isinstance ( var_doc . value , ClassMethodDoc ) and <EOL> not isinstance ( var_doc . value , StaticMethodDoc ) and <EOL> var_doc . value . is_event == False and <EOL> var_doc . is_instvar in ( False , UNKNOWN ) ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , RoutineDoc ) and <EOL> var_doc . value . is_event == True ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , ClassMethodDoc ) and <EOL> var_doc . is_instvar in ( False , UNKNOWN ) ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , StaticMethodDoc ) and <EOL> var_doc . is_instvar in ( False , UNKNOWN ) ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , PropertyDoc ) and <EOL> var_doc . is_instvar in ( False , UNKNOWN ) ) ] <EOL> elif value_type == '<STR_LIT:class>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( isinstance ( var_doc . value , ClassDoc ) and <EOL> var_doc . is_instvar in ( False , UNKNOWN ) and <EOL> var_doc . name != '<STR_LIT>' ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if var_doc . is_instvar is True ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( var_doc . is_instvar in ( False , UNKNOWN ) and <EOL> not isinstance ( var_doc . value , <EOL> ( RoutineDoc , ClassDoc , PropertyDoc ) ) and <EOL> var_doc . name . upper ( ) == var_doc . name ) ] <EOL> elif value_type == '<STR_LIT>' : <EOL> return [ var_doc for var_doc in var_list <EOL> if ( var_doc . is_instvar in ( False , UNKNOWN ) and <EOL> not isinstance ( var_doc . value , <EOL> ( RoutineDoc , ClassDoc , PropertyDoc ) ) <EOL> and not var_doc . name . upper ( ) == var_doc . name ) ] <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % value_type ) <EOL> class RoutineDoc ( ValueDoc ) : <EOL> """<STR_LIT>""" <EOL> posargs = UNKNOWN <EOL> """<STR_LIT>""" <EOL> posarg_defaults = UNKNOWN <EOL> """<STR_LIT>""" <EOL> vararg = UNKNOWN <EOL> """<STR_LIT>""" <EOL> kwarg = UNKNOWN <EOL> """<STR_LIT>""" <EOL> lineno = UNKNOWN <EOL> """<STR_LIT>""" <EOL> decorators = UNKNOWN <EOL> """<STR_LIT>""" <EOL> arg_descrs = UNKNOWN <EOL> """<STR_LIT>""" <EOL> arg_types = UNKNOWN <EOL> """<STR_LIT>""" <EOL> return_descr = UNKNOWN <EOL> """<STR_LIT>""" <EOL> return_type = UNKNOWN <EOL> """<STR_LIT>""" <EOL> exception_descrs = UNKNOWN <EOL> """<STR_LIT>""" <EOL> callgraph_uid = None <EOL> """<STR_LIT>""" <EOL> is_event = False <EOL> def is_detailed ( self ) : <EOL> if super ( RoutineDoc , self ) . is_detailed ( ) : <EOL> return True <EOL> if self . arg_descrs not in ( None , UNKNOWN ) and self . arg_descrs : <EOL> return True <EOL> if self . arg_types not in ( None , UNKNOWN ) and self . arg_types : <EOL> return True <EOL> if self . return_descr not in ( None , UNKNOWN ) : <EOL> return True <EOL> if self . exception_descrs not in ( None , UNKNOWN ) and self . exception_descrs : <EOL> return True <EOL> if ( self . decorators not in ( None , UNKNOWN ) <EOL> and [ d for d in self . decorators <EOL> if d not in ( '<STR_LIT>' , '<STR_LIT>' ) ] ) : <EOL> return True <EOL> return False <EOL> def all_args ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . posargs is UNKNOWN : <EOL> return UNKNOWN <EOL> all_args = _flatten ( self . posargs ) <EOL> if self . vararg not in ( None , UNKNOWN ) : <EOL> all_args . append ( self . vararg ) <EOL> if self . kwarg not in ( None , UNKNOWN ) : <EOL> all_args . append ( self . kwarg ) <EOL> return all_args <EOL> def _flatten ( lst , out = None ) : <EOL> """<STR_LIT>""" <EOL> if out is None : out = [ ] <EOL> for elt in lst : <EOL> if isinstance ( elt , ( list , tuple ) ) : <EOL> _flatten ( elt , out ) <EOL> else : <EOL> out . append ( elt ) <EOL> return out <EOL> class ClassMethodDoc ( RoutineDoc ) : pass <EOL> class StaticMethodDoc ( RoutineDoc ) : pass <EOL> class PropertyDoc ( ValueDoc ) : <EOL> """<STR_LIT>""" <EOL> fget = UNKNOWN <EOL> """<STR_LIT>""" <EOL> fset = UNKNOWN <EOL> """<STR_LIT>""" <EOL> fdel = UNKNOWN <EOL> """<STR_LIT>""" <EOL> type_descr = UNKNOWN <EOL> """<STR_LIT>""" <EOL> def apidoc_links ( self , ** filters ) : <EOL> val_docs = [ ] <EOL> if self . fget not in ( None , UNKNOWN ) : val_docs . append ( self . fget ) <EOL> if self . fset not in ( None , UNKNOWN ) : val_docs . append ( self . fset ) <EOL> if self . fdel not in ( None , UNKNOWN ) : val_docs . append ( self . fdel ) <EOL> return val_docs <EOL> def is_detailed ( self ) : <EOL> if super ( PropertyDoc , self ) . is_detailed ( ) : <EOL> return True <EOL> if self . fget not in ( None , UNKNOWN ) and self . fget . pyval is not None : <EOL> return True <EOL> if self . fset not in ( None , UNKNOWN ) and self . fset . pyval is not None : <EOL> return True <EOL> if self . fdel not in ( None , UNKNOWN ) and self . fdel . pyval is not None : <EOL> return True <EOL> return False <EOL> class DocIndex : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root ) : <EOL> """<STR_LIT>""" <EOL> for apidoc in root : <EOL> if apidoc . canonical_name in ( None , UNKNOWN ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . root = sorted ( root , <EOL> key = lambda d : ( len ( d . canonical_name ) , d . canonical_name ) ) <EOL> """<STR_LIT>""" <EOL> i = <NUM_LIT:1> <EOL> while i < len ( self . root ) : <EOL> if self . root [ i - <NUM_LIT:1> ] is self . root [ i ] : <EOL> del self . root [ i ] <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> self . mlclasses = self . _get_module_classes ( self . root ) <EOL> """<STR_LIT>""" <EOL> self . callers = None <EOL> """<STR_LIT>""" <EOL> self . callees = None <EOL> """<STR_LIT>""" <EOL> self . _funcid_to_doc = { } <EOL> """<STR_LIT>""" <EOL> self . _container_cache = { } <EOL> """<STR_LIT>""" <EOL> self . _get_cache = { } <EOL> """<STR_LIT>""" <EOL> def get_vardoc ( self , name ) : <EOL> """<STR_LIT>""" <EOL> var , val = self . _get ( name ) <EOL> return var <EOL> def get_valdoc ( self , name ) : <EOL> """<STR_LIT>""" <EOL> var , val = self . _get ( name ) <EOL> return val <EOL> def _get ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( name , DottedName ) : <EOL> name = DottedName ( name ) <EOL> val = self . _get_cache . get ( name ) <EOL> if val is not None : return val <EOL> for root_valdoc in self . root : <EOL> if root_valdoc . canonical_name . dominates ( name ) : <EOL> var_doc = None <EOL> val_doc = root_valdoc <EOL> for identifier in name [ len ( root_valdoc . canonical_name ) : ] : <EOL> if val_doc is None : break <EOL> var_doc , val_doc = self . _get_from ( val_doc , identifier ) <EOL> if type ( val_doc ) is GenericValueDoc : <EOL> continue <EOL> else : <EOL> if var_doc is not None or val_doc is not None : <EOL> self . _get_cache [ name ] = ( var_doc , val_doc ) <EOL> return var_doc , val_doc <EOL> self . _get_cache [ name ] = ( None , None ) <EOL> return None , None <EOL> def _get_from ( self , val_doc , identifier ) : <EOL> if isinstance ( val_doc , NamespaceDoc ) : <EOL> child_var = val_doc . variables . get ( identifier ) <EOL> if child_var is not None : <EOL> child_val = child_var . value <EOL> if child_val is UNKNOWN : child_val = None <EOL> return child_var , child_val <EOL> if ( isinstance ( val_doc , ModuleDoc ) and <EOL> val_doc . submodules is not UNKNOWN ) : <EOL> for submodule in val_doc . submodules : <EOL> if submodule . canonical_name [ - <NUM_LIT:1> ] == identifier : <EOL> var_doc = None <EOL> val_doc = submodule <EOL> if val_doc is UNKNOWN : val_doc = None <EOL> return var_doc , val_doc <EOL> return None , None <EOL> def find ( self , name , context ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( name , basestring ) : <EOL> name = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , name . strip ( ) ) <EOL> if re . match ( '<STR_LIT>' , name ) : <EOL> name = DottedName ( name ) <EOL> else : <EOL> return None <EOL> elif not isinstance ( name , DottedName ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if context is None or context . canonical_name is None : <EOL> container_name = [ ] <EOL> else : <EOL> container_name = context . canonical_name <EOL> for i in range ( len ( container_name ) , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> relative_name = container_name [ : i ] + name <EOL> val_doc = self . get_valdoc ( relative_name ) <EOL> if ( val_doc is not None and <EOL> not isinstance ( val_doc , GenericValueDoc ) ) : <EOL> return val_doc <EOL> var_doc = self . get_vardoc ( relative_name ) <EOL> if var_doc is not None : return var_doc <EOL> if name [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> doc = self . find ( '<STR_LIT:.>' . join ( name [ <NUM_LIT:1> : ] ) , context ) <EOL> if doc is not None : return doc <EOL> if len ( name ) == <NUM_LIT:1> and hasattr ( __builtin__ , name [ <NUM_LIT:0> ] ) : <EOL> return None <EOL> if isinstance ( context , RoutineDoc ) : <EOL> all_args = context . all_args ( ) <EOL> if all_args is not UNKNOWN and name [ <NUM_LIT:0> ] in all_args : <EOL> return None <EOL> doc = self . mlclasses . get ( name [ - <NUM_LIT:1> ] ) <EOL> if isinstance ( doc , APIDoc ) : <EOL> return doc <EOL> elif isinstance ( doc , list ) : <EOL> log . warning ( "<STR_LIT>" % ( <EOL> name [ - <NUM_LIT:1> ] , <EOL> "<STR_LIT:U+002CU+0020>" . join ( [ "<STR_LIT>" % d . canonical_name for d in doc ] ) ) ) <EOL> del self . mlclasses [ name [ - <NUM_LIT:1> ] ] <EOL> def _get_module_classes ( self , docs ) : <EOL> """<STR_LIT>""" <EOL> classes = { } <EOL> for doc in docs : <EOL> if not isinstance ( doc , ModuleDoc ) : <EOL> continue <EOL> for var in doc . variables . values ( ) : <EOL> if not isinstance ( var . value , ClassDoc ) : <EOL> continue <EOL> val = var . value <EOL> if val in ( None , UNKNOWN ) or val . defining_module is not doc : <EOL> continue <EOL> if val . canonical_name in ( None , UNKNOWN ) : <EOL> continue <EOL> name = val . canonical_name [ - <NUM_LIT:1> ] <EOL> vals = classes . get ( name ) <EOL> if vals is None : <EOL> classes [ name ] = val <EOL> elif not isinstance ( vals , list ) : <EOL> classes [ name ] = [ vals , val ] <EOL> else : <EOL> vals . append ( val ) <EOL> return classes <EOL> def reachable_valdocs ( self , ** filters ) : <EOL> """<STR_LIT>""" <EOL> return reachable_valdocs ( self . root , ** filters ) <EOL> def container ( self , api_doc ) : <EOL> """<STR_LIT>""" <EOL> val = self . _container_cache . get ( api_doc ) <EOL> if val is not None : return val <EOL> if isinstance ( api_doc , GenericValueDoc ) : <EOL> self . _container_cache [ api_doc ] = None <EOL> return None <EOL> if isinstance ( api_doc , VariableDoc ) : <EOL> self . _container_cache [ api_doc ] = api_doc . container <EOL> return api_doc . container <EOL> if len ( api_doc . canonical_name ) == <NUM_LIT:1> : <EOL> self . _container_cache [ api_doc ] = None <EOL> return None <EOL> elif isinstance ( api_doc , ModuleDoc ) and api_doc . package is not UNKNOWN : <EOL> self . _container_cache [ api_doc ] = api_doc . package <EOL> return api_doc . package <EOL> else : <EOL> parent = self . get_valdoc ( api_doc . canonical_name . container ( ) ) <EOL> self . _container_cache [ api_doc ] = parent <EOL> return parent <EOL> def read_profiling_info ( self , profile_stats ) : <EOL> """<STR_LIT>""" <EOL> if self . callers is None : self . callers = { } <EOL> if self . callees is None : self . callees = { } <EOL> self . _update_funcid_to_doc ( profile_stats ) <EOL> for callee , ( cc , nc , tt , ct , callers ) in profile_stats . stats . items ( ) : <EOL> callee = self . _funcid_to_doc . get ( callee ) <EOL> if callee is None : continue <EOL> for caller in callers : <EOL> caller = self . _funcid_to_doc . get ( caller ) <EOL> if caller is None : continue <EOL> self . callers . setdefault ( callee , [ ] ) . append ( caller ) <EOL> self . callees . setdefault ( caller , [ ] ) . append ( callee ) <EOL> def _update_funcid_to_doc ( self , profile_stats ) : <EOL> """<STR_LIT>""" <EOL> for val_doc in self . reachable_valdocs ( ) : <EOL> if not isinstance ( val_doc , RoutineDoc ) : continue <EOL> module = val_doc . defining_module <EOL> if module is UNKNOWN or module . filename is UNKNOWN : continue <EOL> filename = os . path . abspath ( module . filename ) <EOL> try : filename = py_src_filename ( filename ) <EOL> except : pass <EOL> funcid = ( filename , val_doc . lineno , val_doc . canonical_name [ - <NUM_LIT:1> ] ) <EOL> if funcid in profile_stats . stats : <EOL> self . _funcid_to_doc [ funcid ] = val_doc <EOL> def pp_apidoc ( api_doc , doublespace = <NUM_LIT:0> , depth = <NUM_LIT:5> , exclude = ( ) , include = ( ) , <EOL> backpointers = None ) : <EOL> """<STR_LIT>""" <EOL> pyid = id ( api_doc . __dict__ ) <EOL> if backpointers is None : backpointers = { } <EOL> if ( hasattr ( api_doc , '<STR_LIT>' ) and <EOL> api_doc . canonical_name not in ( None , UNKNOWN ) ) : <EOL> name = '<STR_LIT>' % ( api_doc . __class__ . __name__ , <EOL> api_doc . canonical_name ) <EOL> elif getattr ( api_doc , '<STR_LIT:name>' , None ) not in ( UNKNOWN , None ) : <EOL> if ( getattr ( api_doc , '<STR_LIT>' , None ) not in ( UNKNOWN , None ) and <EOL> getattr ( api_doc . container , '<STR_LIT>' , None ) <EOL> not in ( UNKNOWN , None ) ) : <EOL> name = '<STR_LIT>' % ( api_doc . __class__ . __name__ , <EOL> api_doc . container . canonical_name + <EOL> api_doc . name ) <EOL> else : <EOL> name = '<STR_LIT>' % ( api_doc . __class__ . __name__ , api_doc . name ) <EOL> else : <EOL> name = api_doc . __class__ . __name__ <EOL> if pyid in backpointers : <EOL> return '<STR_LIT>' % ( name , backpointers [ pyid ] ) <EOL> if depth == <NUM_LIT:0> : <EOL> if hasattr ( api_doc , '<STR_LIT:name>' ) and api_doc . name is not None : <EOL> return '<STR_LIT>' % api_doc . name <EOL> else : <EOL> return '<STR_LIT>' <EOL> backpointers [ pyid ] = len ( backpointers ) <EOL> s = '<STR_LIT>' % ( name , backpointers [ pyid ] ) <EOL> fields = [ field for field in api_doc . __dict__ . keys ( ) <EOL> if ( field in include or <EOL> ( getattr ( api_doc , field ) is not UNKNOWN <EOL> and field not in exclude ) ) ] <EOL> if include : <EOL> fields = [ field for field in dir ( api_doc ) <EOL> if field in include ] <EOL> else : <EOL> fields = [ field for field in api_doc . __dict__ . keys ( ) <EOL> if ( getattr ( api_doc , field ) is not UNKNOWN <EOL> and field not in exclude ) ] <EOL> fields . sort ( ) <EOL> for field in fields : <EOL> fieldval = getattr ( api_doc , field ) <EOL> if doublespace : s += '<STR_LIT>' <EOL> s += '<STR_LIT>' % field <EOL> if ( isinstance ( fieldval , types . ListType ) and <EOL> len ( fieldval ) > <NUM_LIT:0> and <EOL> isinstance ( fieldval [ <NUM_LIT:0> ] , APIDoc ) ) : <EOL> s += _pp_list ( api_doc , fieldval , doublespace , depth , <EOL> exclude , include , backpointers , <EOL> ( field is fields [ - <NUM_LIT:1> ] ) ) <EOL> elif ( isinstance ( fieldval , types . DictType ) and <EOL> len ( fieldval ) > <NUM_LIT:0> and <EOL> isinstance ( fieldval . values ( ) [ <NUM_LIT:0> ] , APIDoc ) ) : <EOL> s += _pp_dict ( api_doc , fieldval , doublespace , <EOL> depth , exclude , include , backpointers , <EOL> ( field is fields [ - <NUM_LIT:1> ] ) ) <EOL> elif isinstance ( fieldval , APIDoc ) : <EOL> s += _pp_apidoc ( api_doc , fieldval , doublespace , depth , <EOL> exclude , include , backpointers , <EOL> ( field is fields [ - <NUM_LIT:1> ] ) ) <EOL> else : <EOL> s += '<STR_LIT>' + _pp_val ( api_doc , fieldval , doublespace , <EOL> depth , exclude , include , backpointers ) <EOL> return s <EOL> def _pp_list ( api_doc , items , doublespace , depth , exclude , include , <EOL> backpointers , is_last ) : <EOL> line1 = ( is_last and '<STR_LIT:U+0020>' ) or '<STR_LIT:|>' <EOL> s = '<STR_LIT>' <EOL> for item in items : <EOL> line2 = ( ( item is items [ - <NUM_LIT:1> ] ) and '<STR_LIT:U+0020>' ) or '<STR_LIT:|>' <EOL> joiner = '<STR_LIT>' % ( line1 , line2 ) <EOL> if doublespace : s += '<STR_LIT>' % line1 <EOL> s += '<STR_LIT>' % line1 <EOL> valstr = _pp_val ( api_doc , item , doublespace , depth , exclude , include , <EOL> backpointers ) <EOL> s += joiner . join ( valstr . split ( '<STR_LIT:\n>' ) ) <EOL> return s <EOL> def _pp_dict ( api_doc , dict , doublespace , depth , exclude , include , <EOL> backpointers , is_last ) : <EOL> items = dict . items ( ) <EOL> items . sort ( ) <EOL> line1 = ( is_last and '<STR_LIT:U+0020>' ) or '<STR_LIT:|>' <EOL> s = '<STR_LIT>' <EOL> for item in items : <EOL> line2 = ( ( item is items [ - <NUM_LIT:1> ] ) and '<STR_LIT:U+0020>' ) or '<STR_LIT:|>' <EOL> joiner = '<STR_LIT>' % ( line1 , line2 ) <EOL> if doublespace : s += '<STR_LIT>' % line1 <EOL> s += '<STR_LIT>' % line1 <EOL> valstr = _pp_val ( api_doc , item [ <NUM_LIT:1> ] , doublespace , depth , exclude , <EOL> include , backpointers ) <EOL> s += joiner . join ( ( '<STR_LIT>' % ( item [ <NUM_LIT:0> ] , valstr ) ) . split ( '<STR_LIT:\n>' ) ) <EOL> return s <EOL> def _pp_apidoc ( api_doc , val , doublespace , depth , exclude , include , <EOL> backpointers , is_last ) : <EOL> line1 = ( is_last and '<STR_LIT:U+0020>' ) or '<STR_LIT:|>' <EOL> s = '<STR_LIT>' <EOL> if doublespace : s += '<STR_LIT>' % line1 <EOL> s += '<STR_LIT>' % line1 <EOL> joiner = '<STR_LIT>' % line1 <EOL> childstr = pp_apidoc ( val , doublespace , depth - <NUM_LIT:1> , exclude , <EOL> include , backpointers ) <EOL> return s + joiner . join ( childstr . split ( '<STR_LIT:\n>' ) ) <EOL> def _pp_val ( api_doc , val , doublespace , depth , exclude , include , backpointers ) : <EOL> from epydoc import markup <EOL> if isinstance ( val , APIDoc ) : <EOL> return pp_apidoc ( val , doublespace , depth - <NUM_LIT:1> , exclude , <EOL> include , backpointers ) <EOL> elif isinstance ( val , markup . ParsedDocstring ) : <EOL> valrepr = ` val . to_plaintext ( None ) ` <EOL> if len ( valrepr ) < <NUM_LIT> : return valrepr <EOL> else : return valrepr [ : <NUM_LIT> ] + '<STR_LIT>' <EOL> else : <EOL> valrepr = repr ( val ) <EOL> if len ( valrepr ) < <NUM_LIT> : return valrepr <EOL> else : return valrepr [ : <NUM_LIT> ] + '<STR_LIT>' </s>
