<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" <EOL> __credits__ = """<STR_LIT>""" <EOL> import sys , imp , os , re , types , inspect , __builtin__ , pkgutil <EOL> from repr import Repr <EOL> from string import expandtabs , find , join , lower , split , strip , rfind , rstrip <EOL> try : <EOL> from collections import deque <EOL> except ImportError : <EOL> class deque ( list ) : <EOL> def popleft ( self ) : <EOL> return self . pop ( <NUM_LIT:0> ) <EOL> def pathdirs ( ) : <EOL> """<STR_LIT>""" <EOL> dirs = [ ] <EOL> normdirs = [ ] <EOL> for dir in sys . path : <EOL> dir = os . path . abspath ( dir or '<STR_LIT:.>' ) <EOL> normdir = os . path . normcase ( dir ) <EOL> if normdir not in normdirs and os . path . isdir ( dir ) : <EOL> dirs . append ( dir ) <EOL> normdirs . append ( normdir ) <EOL> return dirs <EOL> def getdoc ( object ) : <EOL> """<STR_LIT>""" <EOL> result = inspect . getdoc ( object ) or inspect . getcomments ( object ) <EOL> return result and re . sub ( '<STR_LIT>' , '<STR_LIT>' , rstrip ( result ) ) or '<STR_LIT>' <EOL> def splitdoc ( doc ) : <EOL> """<STR_LIT>""" <EOL> lines = split ( strip ( doc ) , '<STR_LIT:\n>' ) <EOL> if len ( lines ) == <NUM_LIT:1> : <EOL> return lines [ <NUM_LIT:0> ] , '<STR_LIT>' <EOL> elif len ( lines ) >= <NUM_LIT:2> and not rstrip ( lines [ <NUM_LIT:1> ] ) : <EOL> return lines [ <NUM_LIT:0> ] , join ( lines [ <NUM_LIT:2> : ] , '<STR_LIT:\n>' ) <EOL> return '<STR_LIT>' , join ( lines , '<STR_LIT:\n>' ) <EOL> def classname ( object , modname ) : <EOL> """<STR_LIT>""" <EOL> name = object . __name__ <EOL> if object . __module__ != modname : <EOL> name = object . __module__ + '<STR_LIT:.>' + name <EOL> return name <EOL> def isdata ( object ) : <EOL> """<STR_LIT>""" <EOL> return not ( inspect . ismodule ( object ) or inspect . isclass ( object ) or <EOL> inspect . isroutine ( object ) or inspect . isframe ( object ) or <EOL> inspect . istraceback ( object ) or inspect . iscode ( object ) ) <EOL> def replace ( text , * pairs ) : <EOL> """<STR_LIT>""" <EOL> while pairs : <EOL> text = join ( split ( text , pairs [ <NUM_LIT:0> ] ) , pairs [ <NUM_LIT:1> ] ) <EOL> pairs = pairs [ <NUM_LIT:2> : ] <EOL> return text <EOL> def cram ( text , maxlen ) : <EOL> """<STR_LIT>""" <EOL> if len ( text ) > maxlen : <EOL> pre = max ( <NUM_LIT:0> , ( maxlen - <NUM_LIT:3> ) // <NUM_LIT:2> ) <EOL> post = max ( <NUM_LIT:0> , maxlen - <NUM_LIT:3> - pre ) <EOL> return text [ : pre ] + '<STR_LIT>' + text [ len ( text ) - post : ] <EOL> return text <EOL> _re_stripid = re . compile ( r'<STR_LIT>' , re . IGNORECASE ) <EOL> def stripid ( text ) : <EOL> """<STR_LIT>""" <EOL> if _re_stripid . search ( repr ( Exception ) ) : <EOL> return _re_stripid . sub ( r'<STR_LIT>' , text ) <EOL> return text <EOL> def _is_some_method ( obj ) : <EOL> return inspect . ismethod ( obj ) or inspect . ismethoddescriptor ( obj ) <EOL> def allmethods ( cl ) : <EOL> methods = { } <EOL> for key , value in inspect . getmembers ( cl , _is_some_method ) : <EOL> methods [ key ] = <NUM_LIT:1> <EOL> for base in cl . __bases__ : <EOL> methods . update ( allmethods ( base ) ) <EOL> for key in methods . keys ( ) : <EOL> methods [ key ] = getattr ( cl , key ) <EOL> return methods <EOL> def _split_list ( s , predicate ) : <EOL> """<STR_LIT>""" <EOL> yes = [ ] <EOL> no = [ ] <EOL> for x in s : <EOL> if predicate ( x ) : <EOL> yes . append ( x ) <EOL> else : <EOL> no . append ( x ) <EOL> return yes , no <EOL> def visiblename ( name , all = None ) : <EOL> """<STR_LIT>""" <EOL> _hidden_names = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if name in _hidden_names : return <NUM_LIT:0> <EOL> if name . startswith ( '<STR_LIT>' ) and name . endswith ( '<STR_LIT>' ) : return <NUM_LIT:1> <EOL> if all is not None : <EOL> return name in all <EOL> else : <EOL> return not name . startswith ( '<STR_LIT:_>' ) <EOL> def classify_class_attrs ( object ) : <EOL> """<STR_LIT>""" <EOL> def fixup ( data ) : <EOL> name , kind , cls , value = data <EOL> if inspect . isdatadescriptor ( value ) : <EOL> kind = '<STR_LIT>' <EOL> return name , kind , cls , value <EOL> return map ( fixup , inspect . classify_class_attrs ( object ) ) <EOL> def ispackage ( path ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isdir ( path ) : <EOL> for ext in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if os . path . isfile ( os . path . join ( path , '<STR_LIT>' + ext ) ) : <EOL> return True <EOL> return False <EOL> def source_synopsis ( file ) : <EOL> line = file . readline ( ) <EOL> while line [ : <NUM_LIT:1> ] == '<STR_LIT:#>' or not strip ( line ) : <EOL> line = file . readline ( ) <EOL> if not line : break <EOL> line = strip ( line ) <EOL> if line [ : <NUM_LIT:4> ] == '<STR_LIT>' : line = line [ <NUM_LIT:1> : ] <EOL> if line [ : <NUM_LIT:3> ] == '<STR_LIT>' : <EOL> line = line [ <NUM_LIT:3> : ] <EOL> if line [ - <NUM_LIT:1> : ] == '<STR_LIT:\\>' : line = line [ : - <NUM_LIT:1> ] <EOL> while not strip ( line ) : <EOL> line = file . readline ( ) <EOL> if not line : break <EOL> result = strip ( split ( line , '<STR_LIT>' ) [ <NUM_LIT:0> ] ) <EOL> else : result = None <EOL> return result <EOL> def synopsis ( filename , cache = { } ) : <EOL> """<STR_LIT>""" <EOL> mtime = os . stat ( filename ) . st_mtime <EOL> lastupdate , result = cache . get ( filename , ( <NUM_LIT:0> , None ) ) <EOL> if lastupdate < mtime : <EOL> info = inspect . getmoduleinfo ( filename ) <EOL> try : <EOL> file = open ( filename ) <EOL> except IOError : <EOL> return None <EOL> if info and '<STR_LIT:b>' in info [ <NUM_LIT:2> ] : <EOL> try : module = imp . load_module ( '<STR_LIT>' , file , filename , info [ <NUM_LIT:1> : ] ) <EOL> except : return None <EOL> result = ( module . __doc__ or '<STR_LIT>' ) . splitlines ( ) [ <NUM_LIT:0> ] <EOL> del sys . modules [ '<STR_LIT>' ] <EOL> else : <EOL> result = source_synopsis ( file ) <EOL> file . close ( ) <EOL> cache [ filename ] = ( mtime , result ) <EOL> return result <EOL> class ErrorDuringImport ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename , exc_info ) : <EOL> exc , value , tb = exc_info <EOL> self . filename = filename <EOL> self . exc = exc <EOL> self . value = value <EOL> self . tb = tb <EOL> def __str__ ( self ) : <EOL> exc = self . exc <EOL> if type ( exc ) is types . ClassType : <EOL> exc = exc . __name__ <EOL> return '<STR_LIT>' % ( self . filename , exc , self . value ) <EOL> def importfile ( path ) : <EOL> """<STR_LIT>""" <EOL> magic = imp . get_magic ( ) <EOL> file = open ( path , '<STR_LIT:r>' ) <EOL> if file . read ( len ( magic ) ) == magic : <EOL> kind = imp . PY_COMPILED <EOL> else : <EOL> kind = imp . PY_SOURCE <EOL> file . close ( ) <EOL> filename = os . path . basename ( path ) <EOL> name , ext = os . path . splitext ( filename ) <EOL> file = open ( path , '<STR_LIT:r>' ) <EOL> try : <EOL> module = imp . load_module ( name , file , path , ( ext , '<STR_LIT:r>' , kind ) ) <EOL> except : <EOL> raise ErrorDuringImport ( path , sys . exc_info ( ) ) <EOL> file . close ( ) <EOL> return module <EOL> def safeimport ( path , forceload = <NUM_LIT:0> , cache = { } ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if forceload and path in sys . modules : <EOL> if path not in sys . builtin_module_names : <EOL> subs = [ m for m in sys . modules if m . startswith ( path + '<STR_LIT:.>' ) ] <EOL> for key in [ path ] + subs : <EOL> cache [ key ] = sys . modules [ key ] <EOL> del sys . modules [ key ] <EOL> module = __import__ ( path ) <EOL> except : <EOL> ( exc , value , tb ) = info = sys . exc_info ( ) <EOL> if path in sys . modules : <EOL> raise ErrorDuringImport ( sys . modules [ path ] . __file__ , info ) <EOL> elif exc is SyntaxError : <EOL> raise ErrorDuringImport ( value . filename , info ) <EOL> elif exc is ImportError and split ( lower ( str ( value ) ) ) [ : <NUM_LIT:2> ] == [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return None <EOL> else : <EOL> raise ErrorDuringImport ( path , sys . exc_info ( ) ) <EOL> for part in split ( path , '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] : <EOL> try : module = getattr ( module , part ) <EOL> except AttributeError : return None <EOL> return module <EOL> class Doc : <EOL> def document ( self , object , name = None , * args ) : <EOL> """<STR_LIT>""" <EOL> args = ( object , name ) + args <EOL> if inspect . isgetsetdescriptor ( object ) : return self . docdata ( * args ) <EOL> if inspect . ismemberdescriptor ( object ) : return self . docdata ( * args ) <EOL> try : <EOL> if inspect . ismodule ( object ) : return self . docmodule ( * args ) <EOL> if inspect . isclass ( object ) : return self . docclass ( * args ) <EOL> if inspect . isroutine ( object ) : return self . docroutine ( * args ) <EOL> except AttributeError : <EOL> pass <EOL> if isinstance ( object , property ) : return self . docproperty ( * args ) <EOL> return self . docother ( * args ) <EOL> def fail ( self , object , name = None , * args ) : <EOL> """<STR_LIT>""" <EOL> message = "<STR_LIT>" % ( <EOL> name and '<STR_LIT:U+0020>' + repr ( name ) , type ( object ) . __name__ ) <EOL> raise TypeError , message <EOL> docmodule = docclass = docroutine = docother = docproperty = docdata = fail <EOL> def getdocloc ( self , object ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> file = inspect . getabsfile ( object ) <EOL> except TypeError : <EOL> file = '<STR_LIT>' <EOL> docloc = os . environ . get ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> basedir = os . path . join ( sys . exec_prefix , "<STR_LIT>" , <EOL> "<STR_LIT>" + sys . version [ <NUM_LIT:0> : <NUM_LIT:3> ] ) <EOL> if ( isinstance ( object , type ( os ) ) and <EOL> ( object . __name__ in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) or <EOL> ( file . startswith ( basedir ) and <EOL> not file . startswith ( os . path . join ( basedir , '<STR_LIT>' ) ) ) ) ) : <EOL> if docloc . startswith ( "<STR_LIT>" ) : <EOL> docloc = "<STR_LIT>" % ( docloc . rstrip ( "<STR_LIT:/>" ) , object . __name__ ) <EOL> else : <EOL> docloc = os . path . join ( docloc , object . __name__ + "<STR_LIT>" ) <EOL> else : <EOL> docloc = None <EOL> return docloc <EOL> class HTMLRepr ( Repr ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Repr . __init__ ( self ) <EOL> self . maxlist = self . maxtuple = <NUM_LIT:20> <EOL> self . maxdict = <NUM_LIT:10> <EOL> self . maxstring = self . maxother = <NUM_LIT:100> <EOL> def escape ( self , text ) : <EOL> return replace ( text , '<STR_LIT:&>' , '<STR_LIT>' , '<STR_LIT:<>' , '<STR_LIT>' , '<STR_LIT:>>' , '<STR_LIT>' ) <EOL> def repr ( self , object ) : <EOL> return Repr . repr ( self , object ) <EOL> def repr1 ( self , x , level ) : <EOL> if hasattr ( type ( x ) , '<STR_LIT>' ) : <EOL> methodname = '<STR_LIT>' + join ( split ( type ( x ) . __name__ ) , '<STR_LIT:_>' ) <EOL> if hasattr ( self , methodname ) : <EOL> return getattr ( self , methodname ) ( x , level ) <EOL> return self . escape ( cram ( stripid ( repr ( x ) ) , self . maxother ) ) <EOL> def repr_string ( self , x , level ) : <EOL> test = cram ( x , self . maxstring ) <EOL> testrepr = repr ( test ) <EOL> if '<STR_LIT:\\>' in test and '<STR_LIT:\\>' not in replace ( testrepr , r'<STR_LIT:\\>' , '<STR_LIT>' ) : <EOL> return '<STR_LIT:r>' + testrepr [ <NUM_LIT:0> ] + self . escape ( test ) + testrepr [ <NUM_LIT:0> ] <EOL> return re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> self . escape ( testrepr ) ) <EOL> repr_str = repr_string <EOL> def repr_instance ( self , x , level ) : <EOL> try : <EOL> return self . escape ( cram ( stripid ( repr ( x ) ) , self . maxstring ) ) <EOL> except : <EOL> return self . escape ( '<STR_LIT>' % x . __class__ . __name__ ) <EOL> repr_unicode = repr_string <EOL> class HTMLDoc ( Doc ) : <EOL> """<STR_LIT>""" <EOL> _repr_instance = HTMLRepr ( ) <EOL> repr = _repr_instance . repr <EOL> escape = _repr_instance . escape <EOL> def page ( self , title , contents ) : <EOL> """<STR_LIT>""" <EOL> return '''<STR_LIT>''' % ( title , contents ) <EOL> def heading ( self , title , fgcol , bgcol , extras = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return '''<STR_LIT>''' % ( bgcol , fgcol , title , fgcol , extras or '<STR_LIT>' ) <EOL> def section ( self , title , fgcol , bgcol , contents , width = <NUM_LIT:6> , <EOL> prelude = '<STR_LIT>' , marginalia = None , gap = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if marginalia is None : <EOL> marginalia = '<STR_LIT>' + '<STR_LIT>' * width + '<STR_LIT>' <EOL> result = '''<STR_LIT>''' % ( bgcol , fgcol , title ) <EOL> if prelude : <EOL> result = result + '''<STR_LIT>''' % ( bgcol , marginalia , prelude , gap ) <EOL> else : <EOL> result = result + '''<STR_LIT>''' % ( bgcol , marginalia , gap ) <EOL> return result + '<STR_LIT>' % contents <EOL> def bigsection ( self , title , * args ) : <EOL> """<STR_LIT>""" <EOL> title = '<STR_LIT>' % title <EOL> return self . section ( title , * args ) <EOL> def preformat ( self , text ) : <EOL> """<STR_LIT>""" <EOL> text = self . escape ( expandtabs ( text ) ) <EOL> return replace ( text , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:U+0020>' , '<STR_LIT>' , '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> def multicolumn ( self , list , format , cols = <NUM_LIT:4> ) : <EOL> """<STR_LIT>""" <EOL> result = '<STR_LIT>' <EOL> rows = ( len ( list ) + cols - <NUM_LIT:1> ) / cols <EOL> for col in range ( cols ) : <EOL> result = result + '<STR_LIT>' % ( <NUM_LIT:100> / cols ) <EOL> for i in range ( rows * col , rows * col + rows ) : <EOL> if i < len ( list ) : <EOL> result = result + format ( list [ i ] ) + '<STR_LIT>' <EOL> result = result + '<STR_LIT>' <EOL> return '<STR_LIT>' % result <EOL> def grey ( self , text ) : return '<STR_LIT>' % text <EOL> def namelink ( self , name , * dicts ) : <EOL> """<STR_LIT>""" <EOL> for dict in dicts : <EOL> if name in dict : <EOL> return '<STR_LIT>' % ( dict [ name ] , name ) <EOL> return name <EOL> def classlink ( self , object , modname ) : <EOL> """<STR_LIT>""" <EOL> name , module = object . __name__ , sys . modules . get ( object . __module__ ) <EOL> if hasattr ( module , name ) and getattr ( module , name ) is object : <EOL> return '<STR_LIT>' % ( <EOL> module . __name__ , name , classname ( object , modname ) ) <EOL> return classname ( object , modname ) <EOL> def modulelink ( self , object ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( object . __name__ , object . __name__ ) <EOL> def modpkglink ( self , data ) : <EOL> """<STR_LIT>""" <EOL> name , path , ispackage , shadowed = data <EOL> if shadowed : <EOL> return self . grey ( name ) <EOL> if path : <EOL> url = '<STR_LIT>' % ( path , name ) <EOL> else : <EOL> url = '<STR_LIT>' % name <EOL> if ispackage : <EOL> text = '<STR_LIT>' % name <EOL> else : <EOL> text = name <EOL> return '<STR_LIT>' % ( url , text ) <EOL> def markup ( self , text , escape = None , funcs = { } , classes = { } , methods = { } ) : <EOL> """<STR_LIT>""" <EOL> escape = escape or self . escape <EOL> results = [ ] <EOL> here = <NUM_LIT:0> <EOL> pattern = re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) <EOL> while True : <EOL> match = pattern . search ( text , here ) <EOL> if not match : break <EOL> start , end = match . span ( ) <EOL> results . append ( escape ( text [ here : start ] ) ) <EOL> all , scheme , rfc , pep , selfdot , name = match . groups ( ) <EOL> if scheme : <EOL> url = escape ( all ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> results . append ( '<STR_LIT>' % ( url , url ) ) <EOL> elif rfc : <EOL> url = '<STR_LIT>' % int ( rfc ) <EOL> results . append ( '<STR_LIT>' % ( url , escape ( all ) ) ) <EOL> elif pep : <EOL> url = '<STR_LIT>' % int ( pep ) <EOL> results . append ( '<STR_LIT>' % ( url , escape ( all ) ) ) <EOL> elif text [ end : end + <NUM_LIT:1> ] == '<STR_LIT:(>' : <EOL> results . append ( self . namelink ( name , methods , funcs , classes ) ) <EOL> elif selfdot : <EOL> results . append ( '<STR_LIT>' % name ) <EOL> else : <EOL> results . append ( self . namelink ( name , classes ) ) <EOL> here = end <EOL> results . append ( escape ( text [ here : ] ) ) <EOL> return join ( results , '<STR_LIT>' ) <EOL> def formattree ( self , tree , modname , parent = None ) : <EOL> """<STR_LIT>""" <EOL> result = '<STR_LIT>' <EOL> for entry in tree : <EOL> if type ( entry ) is type ( ( ) ) : <EOL> c , bases = entry <EOL> result = result + '<STR_LIT>' <EOL> result = result + self . classlink ( c , modname ) <EOL> if bases and bases != ( parent , ) : <EOL> parents = [ ] <EOL> for base in bases : <EOL> parents . append ( self . classlink ( base , modname ) ) <EOL> result = result + '<STR_LIT:(>' + join ( parents , '<STR_LIT:U+002CU+0020>' ) + '<STR_LIT:)>' <EOL> result = result + '<STR_LIT>' <EOL> elif type ( entry ) is type ( [ ] ) : <EOL> result = result + '<STR_LIT>' % self . formattree ( <EOL> entry , modname , c ) <EOL> return '<STR_LIT>' % result <EOL> def docmodule ( self , object , name = None , mod = None , * ignored ) : <EOL> """<STR_LIT>""" <EOL> name = object . __name__ <EOL> try : <EOL> all = object . __all__ <EOL> except AttributeError : <EOL> all = None <EOL> parts = split ( name , '<STR_LIT:.>' ) <EOL> links = [ ] <EOL> for i in range ( len ( parts ) - <NUM_LIT:1> ) : <EOL> links . append ( <EOL> '<STR_LIT>' % <EOL> ( join ( parts [ : i + <NUM_LIT:1> ] , '<STR_LIT:.>' ) , parts [ i ] ) ) <EOL> linkedname = join ( links + parts [ - <NUM_LIT:1> : ] , '<STR_LIT:.>' ) <EOL> head = '<STR_LIT>' % linkedname <EOL> try : <EOL> path = inspect . getabsfile ( object ) <EOL> url = path <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> import nturl2path <EOL> url = nturl2path . pathname2url ( path ) <EOL> filelink = '<STR_LIT>' % ( url , path ) <EOL> except TypeError : <EOL> filelink = '<STR_LIT>' <EOL> info = [ ] <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> version = str ( object . __version__ ) <EOL> if version [ : <NUM_LIT:11> ] == '<STR_LIT:$>' + '<STR_LIT>' and version [ - <NUM_LIT:1> : ] == '<STR_LIT:$>' : <EOL> version = strip ( version [ <NUM_LIT:11> : - <NUM_LIT:1> ] ) <EOL> info . append ( '<STR_LIT>' % self . escape ( version ) ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> info . append ( self . escape ( str ( object . __date__ ) ) ) <EOL> if info : <EOL> head = head + '<STR_LIT>' % join ( info , '<STR_LIT:U+002CU+0020>' ) <EOL> docloc = self . getdocloc ( object ) <EOL> if docloc is not None : <EOL> docloc = '<STR_LIT>' % locals ( ) <EOL> else : <EOL> docloc = '<STR_LIT>' <EOL> result = self . heading ( <EOL> head , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' + filelink + docloc ) <EOL> modules = inspect . getmembers ( object , inspect . ismodule ) <EOL> classes , cdict = [ ] , { } <EOL> for key , value in inspect . getmembers ( object , inspect . isclass ) : <EOL> if ( all is not None or <EOL> ( inspect . getmodule ( value ) or object ) is object ) : <EOL> if visiblename ( key , all ) : <EOL> classes . append ( ( key , value ) ) <EOL> cdict [ key ] = cdict [ value ] = '<STR_LIT:#>' + key <EOL> for key , value in classes : <EOL> for base in value . __bases__ : <EOL> key , modname = base . __name__ , base . __module__ <EOL> module = sys . modules . get ( modname ) <EOL> if modname != name and module and hasattr ( module , key ) : <EOL> if getattr ( module , key ) is base : <EOL> if not key in cdict : <EOL> cdict [ key ] = cdict [ base ] = modname + '<STR_LIT>' + key <EOL> funcs , fdict = [ ] , { } <EOL> for key , value in inspect . getmembers ( object , inspect . isroutine ) : <EOL> if ( all is not None or <EOL> inspect . isbuiltin ( value ) or inspect . getmodule ( value ) is object ) : <EOL> if visiblename ( key , all ) : <EOL> funcs . append ( ( key , value ) ) <EOL> fdict [ key ] = '<STR_LIT>' + key <EOL> if inspect . isfunction ( value ) : fdict [ value ] = fdict [ key ] <EOL> data = [ ] <EOL> for key , value in inspect . getmembers ( object , isdata ) : <EOL> if visiblename ( key , all ) : <EOL> data . append ( ( key , value ) ) <EOL> doc = self . markup ( getdoc ( object ) , self . preformat , fdict , cdict ) <EOL> doc = doc and '<STR_LIT>' % doc <EOL> result = result + '<STR_LIT>' % doc <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> modpkgs = [ ] <EOL> for importer , modname , ispkg in pkgutil . iter_modules ( object . __path__ ) : <EOL> modpkgs . append ( ( modname , name , ispkg , <NUM_LIT:0> ) ) <EOL> modpkgs . sort ( ) <EOL> contents = self . multicolumn ( modpkgs , self . modpkglink ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , contents ) <EOL> elif modules : <EOL> contents = self . multicolumn ( <EOL> modules , lambda key_value , s = self : s . modulelink ( key_value [ <NUM_LIT:1> ] ) ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , contents ) <EOL> if classes : <EOL> classlist = map ( lambda key_value : key_value [ <NUM_LIT:1> ] , classes ) <EOL> contents = [ <EOL> self . formattree ( inspect . getclasstree ( classlist , <NUM_LIT:1> ) , name ) ] <EOL> for key , value in classes : <EOL> contents . append ( self . document ( value , key , name , fdict , cdict ) ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , join ( contents ) ) <EOL> if funcs : <EOL> contents = [ ] <EOL> for key , value in funcs : <EOL> contents . append ( self . document ( value , key , name , fdict , cdict ) ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , join ( contents ) ) <EOL> if data : <EOL> contents = [ ] <EOL> for key , value in data : <EOL> contents . append ( self . document ( value , key ) ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , join ( contents , '<STR_LIT>' ) ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> contents = self . markup ( str ( object . __author__ ) , self . preformat ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , contents ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> contents = self . markup ( str ( object . __credits__ ) , self . preformat ) <EOL> result = result + self . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , contents ) <EOL> return result <EOL> def docclass ( self , object , name = None , mod = None , funcs = { } , classes = { } , <EOL> * ignored ) : <EOL> """<STR_LIT>""" <EOL> realname = object . __name__ <EOL> name = name or realname <EOL> bases = object . __bases__ <EOL> contents = [ ] <EOL> push = contents . append <EOL> class HorizontalRule : <EOL> def __init__ ( self ) : <EOL> self . needone = <NUM_LIT:0> <EOL> def maybe ( self ) : <EOL> if self . needone : <EOL> push ( '<STR_LIT>' ) <EOL> self . needone = <NUM_LIT:1> <EOL> hr = HorizontalRule ( ) <EOL> mro = deque ( inspect . getmro ( object ) ) <EOL> if len ( mro ) > <NUM_LIT:2> : <EOL> hr . maybe ( ) <EOL> push ( '<STR_LIT>' ) <EOL> for base in mro : <EOL> push ( '<STR_LIT>' % self . classlink ( base , <EOL> object . __module__ ) ) <EOL> push ( '<STR_LIT>' ) <EOL> def spill ( msg , attrs , predicate ) : <EOL> ok , attrs = _split_list ( attrs , predicate ) <EOL> if ok : <EOL> hr . maybe ( ) <EOL> push ( msg ) <EOL> for name , kind , homecls , value in ok : <EOL> push ( self . document ( getattr ( object , name ) , name , mod , <EOL> funcs , classes , mdict , object ) ) <EOL> push ( '<STR_LIT:\n>' ) <EOL> return attrs <EOL> def spilldescriptors ( msg , attrs , predicate ) : <EOL> ok , attrs = _split_list ( attrs , predicate ) <EOL> if ok : <EOL> hr . maybe ( ) <EOL> push ( msg ) <EOL> for name , kind , homecls , value in ok : <EOL> push ( self . _docdescriptor ( name , value , mod ) ) <EOL> return attrs <EOL> def spilldata ( msg , attrs , predicate ) : <EOL> ok , attrs = _split_list ( attrs , predicate ) <EOL> if ok : <EOL> hr . maybe ( ) <EOL> push ( msg ) <EOL> for name , kind , homecls , value in ok : <EOL> base = self . docother ( getattr ( object , name ) , name , mod ) <EOL> if ( hasattr ( value , '<STR_LIT>' ) or <EOL> inspect . isdatadescriptor ( value ) ) : <EOL> doc = getattr ( value , "<STR_LIT>" , None ) <EOL> else : <EOL> doc = None <EOL> if doc is None : <EOL> push ( '<STR_LIT>' % base ) <EOL> else : <EOL> doc = self . markup ( getdoc ( value ) , self . preformat , <EOL> funcs , classes , mdict ) <EOL> doc = '<STR_LIT>' % doc <EOL> push ( '<STR_LIT>' % ( base , doc ) ) <EOL> push ( '<STR_LIT:\n>' ) <EOL> return attrs <EOL> attrs = filter ( lambda data : visiblename ( data [ <NUM_LIT:0> ] ) , <EOL> classify_class_attrs ( object ) ) <EOL> mdict = { } <EOL> for key , kind , homecls , value in attrs : <EOL> mdict [ key ] = anchor = '<STR_LIT:#>' + name + '<STR_LIT:->' + key <EOL> value = getattr ( object , key ) <EOL> try : <EOL> mdict [ value ] = anchor <EOL> except TypeError : <EOL> pass <EOL> while attrs : <EOL> if mro : <EOL> thisclass = mro . popleft ( ) <EOL> else : <EOL> thisclass = attrs [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> attrs , inherited = _split_list ( attrs , lambda t : t [ <NUM_LIT:2> ] is thisclass ) <EOL> if thisclass is __builtin__ . object : <EOL> attrs = inherited <EOL> continue <EOL> elif thisclass is object : <EOL> tag = '<STR_LIT>' <EOL> else : <EOL> tag = '<STR_LIT>' % self . classlink ( thisclass , <EOL> object . __module__ ) <EOL> tag += '<STR_LIT>' <EOL> try : <EOL> attrs . sort ( key = lambda t : t [ <NUM_LIT:0> ] ) <EOL> except TypeError : <EOL> attrs . sort ( lambda t1 , t2 : cmp ( t1 [ <NUM_LIT:0> ] , t2 [ <NUM_LIT:0> ] ) ) <EOL> attrs = spill ( '<STR_LIT>' % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spill ( '<STR_LIT>' % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spill ( '<STR_LIT>' % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spilldescriptors ( '<STR_LIT>' % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spilldata ( '<STR_LIT>' % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT:data>' ) <EOL> assert attrs == [ ] <EOL> attrs = inherited <EOL> contents = '<STR_LIT>' . join ( contents ) <EOL> if name == realname : <EOL> title = '<STR_LIT>' % ( <EOL> name , realname ) <EOL> else : <EOL> title = '<STR_LIT>' % ( <EOL> name , name , realname ) <EOL> if bases : <EOL> parents = [ ] <EOL> for base in bases : <EOL> parents . append ( self . classlink ( base , object . __module__ ) ) <EOL> title = title + '<STR_LIT>' % join ( parents , '<STR_LIT:U+002CU+0020>' ) <EOL> doc = self . markup ( getdoc ( object ) , self . preformat , funcs , classes , mdict ) <EOL> doc = doc and '<STR_LIT>' % doc <EOL> return self . section ( title , '<STR_LIT>' , '<STR_LIT>' , contents , <NUM_LIT:3> , doc ) <EOL> def formatvalue ( self , object ) : <EOL> """<STR_LIT>""" <EOL> return self . grey ( '<STR_LIT:=>' + self . repr ( object ) ) <EOL> def docroutine ( self , object , name = None , mod = None , <EOL> funcs = { } , classes = { } , methods = { } , cl = None ) : <EOL> """<STR_LIT>""" <EOL> realname = object . __name__ <EOL> name = name or realname <EOL> anchor = ( cl and cl . __name__ or '<STR_LIT>' ) + '<STR_LIT:->' + name <EOL> note = '<STR_LIT>' <EOL> skipdocs = <NUM_LIT:0> <EOL> if inspect . ismethod ( object ) : <EOL> imclass = object . im_class <EOL> if cl : <EOL> if imclass is not cl : <EOL> note = '<STR_LIT>' + self . classlink ( imclass , mod ) <EOL> else : <EOL> if object . im_self is not None : <EOL> note = '<STR_LIT>' % self . classlink ( <EOL> object . im_self . __class__ , mod ) <EOL> else : <EOL> note = '<STR_LIT>' % self . classlink ( imclass , mod ) <EOL> object = object . im_func <EOL> if name == realname : <EOL> title = '<STR_LIT>' % ( anchor , realname ) <EOL> else : <EOL> if ( cl and realname in cl . __dict__ and <EOL> cl . __dict__ [ realname ] is object ) : <EOL> reallink = '<STR_LIT>' % ( <EOL> cl . __name__ + '<STR_LIT:->' + realname , realname ) <EOL> skipdocs = <NUM_LIT:1> <EOL> else : <EOL> reallink = realname <EOL> title = '<STR_LIT>' % ( <EOL> anchor , name , reallink ) <EOL> if inspect . isfunction ( object ) : <EOL> args , varargs , varkw , defaults = inspect . getargspec ( object ) <EOL> argspec = inspect . formatargspec ( <EOL> args , varargs , varkw , defaults , formatvalue = self . formatvalue ) <EOL> if realname == '<STR_LIT>' : <EOL> title = '<STR_LIT>' % name <EOL> argspec = argspec [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> else : <EOL> argspec = '<STR_LIT>' <EOL> decl = title + argspec + ( note and self . grey ( <EOL> '<STR_LIT>' % note ) ) <EOL> if skipdocs : <EOL> return '<STR_LIT>' % decl <EOL> else : <EOL> doc = self . markup ( <EOL> getdoc ( object ) , self . preformat , funcs , classes , methods ) <EOL> doc = doc and '<STR_LIT>' % doc <EOL> return '<STR_LIT>' % ( decl , doc ) <EOL> def _docdescriptor ( self , name , value , mod ) : <EOL> results = [ ] <EOL> push = results . append <EOL> if name : <EOL> push ( '<STR_LIT>' % name ) <EOL> if value . __doc__ is not None : <EOL> doc = self . markup ( getdoc ( value ) , self . preformat ) <EOL> push ( '<STR_LIT>' % doc ) <EOL> push ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( results ) <EOL> def docproperty ( self , object , name = None , mod = None , cl = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _docdescriptor ( name , object , mod ) <EOL> def docother ( self , object , name = None , mod = None , * ignored ) : <EOL> """<STR_LIT>""" <EOL> lhs = name and '<STR_LIT>' % name or '<STR_LIT>' <EOL> return lhs + self . repr ( object ) <EOL> def docdata ( self , object , name = None , mod = None , cl = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _docdescriptor ( name , object , mod ) <EOL> def index ( self , dir , shadowed = None ) : <EOL> """<STR_LIT>""" <EOL> modpkgs = [ ] <EOL> if shadowed is None : shadowed = { } <EOL> for importer , name , ispkg in pkgutil . iter_modules ( [ dir ] ) : <EOL> modpkgs . append ( ( name , '<STR_LIT>' , ispkg , name in shadowed ) ) <EOL> shadowed [ name ] = <NUM_LIT:1> <EOL> modpkgs . sort ( ) <EOL> contents = self . multicolumn ( modpkgs , self . modpkglink ) <EOL> return self . bigsection ( dir , '<STR_LIT>' , '<STR_LIT>' , contents ) <EOL> class TextRepr ( Repr ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Repr . __init__ ( self ) <EOL> self . maxlist = self . maxtuple = <NUM_LIT:20> <EOL> self . maxdict = <NUM_LIT:10> <EOL> self . maxstring = self . maxother = <NUM_LIT:100> <EOL> def repr1 ( self , x , level ) : <EOL> if hasattr ( type ( x ) , '<STR_LIT>' ) : <EOL> methodname = '<STR_LIT>' + join ( split ( type ( x ) . __name__ ) , '<STR_LIT:_>' ) <EOL> if hasattr ( self , methodname ) : <EOL> return getattr ( self , methodname ) ( x , level ) <EOL> return cram ( stripid ( repr ( x ) ) , self . maxother ) <EOL> def repr_string ( self , x , level ) : <EOL> test = cram ( x , self . maxstring ) <EOL> testrepr = repr ( test ) <EOL> if '<STR_LIT:\\>' in test and '<STR_LIT:\\>' not in replace ( testrepr , r'<STR_LIT:\\>' , '<STR_LIT>' ) : <EOL> return '<STR_LIT:r>' + testrepr [ <NUM_LIT:0> ] + test + testrepr [ <NUM_LIT:0> ] <EOL> return testrepr <EOL> repr_str = repr_string <EOL> def repr_instance ( self , x , level ) : <EOL> try : <EOL> return cram ( stripid ( repr ( x ) ) , self . maxstring ) <EOL> except : <EOL> return '<STR_LIT>' % x . __class__ . __name__ <EOL> class TextDoc ( Doc ) : <EOL> """<STR_LIT>""" <EOL> _repr_instance = TextRepr ( ) <EOL> repr = _repr_instance . repr <EOL> def bold ( self , text ) : <EOL> """<STR_LIT>""" <EOL> return join ( map ( lambda ch : ch + '<STR_LIT>' + ch , text ) , '<STR_LIT>' ) <EOL> def indent ( self , text , prefix = '<STR_LIT:U+0020>' ) : <EOL> """<STR_LIT>""" <EOL> if not text : return '<STR_LIT>' <EOL> lines = split ( text , '<STR_LIT:\n>' ) <EOL> lines = map ( lambda line , prefix = prefix : prefix + line , lines ) <EOL> if lines : lines [ - <NUM_LIT:1> ] = rstrip ( lines [ - <NUM_LIT:1> ] ) <EOL> return join ( lines , '<STR_LIT:\n>' ) <EOL> def section ( self , title , contents ) : <EOL> """<STR_LIT>""" <EOL> return self . bold ( title ) + '<STR_LIT:\n>' + rstrip ( self . indent ( contents ) ) + '<STR_LIT>' <EOL> def formattree ( self , tree , modname , parent = None , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> result = '<STR_LIT>' <EOL> for entry in tree : <EOL> if type ( entry ) is type ( ( ) ) : <EOL> c , bases = entry <EOL> result = result + prefix + classname ( c , modname ) <EOL> if bases and bases != ( parent , ) : <EOL> parents = map ( lambda c , m = modname : classname ( c , m ) , bases ) <EOL> result = result + '<STR_LIT>' % join ( parents , '<STR_LIT:U+002CU+0020>' ) <EOL> result = result + '<STR_LIT:\n>' <EOL> elif type ( entry ) is type ( [ ] ) : <EOL> result = result + self . formattree ( <EOL> entry , modname , c , prefix + '<STR_LIT:U+0020>' ) <EOL> return result <EOL> def docmodule ( self , object , name = None , mod = None ) : <EOL> """<STR_LIT>""" <EOL> name = object . __name__ <EOL> synop , desc = splitdoc ( getdoc ( object ) ) <EOL> result = self . section ( '<STR_LIT>' , name + ( synop and '<STR_LIT>' + synop ) ) <EOL> try : <EOL> all = object . __all__ <EOL> except AttributeError : <EOL> all = None <EOL> try : <EOL> file = inspect . getabsfile ( object ) <EOL> except TypeError : <EOL> file = '<STR_LIT>' <EOL> result = result + self . section ( '<STR_LIT>' , file ) <EOL> docloc = self . getdocloc ( object ) <EOL> if docloc is not None : <EOL> result = result + self . section ( '<STR_LIT>' , docloc ) <EOL> if desc : <EOL> result = result + self . section ( '<STR_LIT>' , desc ) <EOL> classes = [ ] <EOL> for key , value in inspect . getmembers ( object , inspect . isclass ) : <EOL> if ( all is not None <EOL> or ( inspect . getmodule ( value ) or object ) is object ) : <EOL> if visiblename ( key , all ) : <EOL> classes . append ( ( key , value ) ) <EOL> funcs = [ ] <EOL> for key , value in inspect . getmembers ( object , inspect . isroutine ) : <EOL> if ( all is not None or <EOL> inspect . isbuiltin ( value ) or inspect . getmodule ( value ) is object ) : <EOL> if visiblename ( key , all ) : <EOL> funcs . append ( ( key , value ) ) <EOL> data = [ ] <EOL> for key , value in inspect . getmembers ( object , isdata ) : <EOL> if visiblename ( key , all ) : <EOL> data . append ( ( key , value ) ) <EOL> modpkgs = [ ] <EOL> modpkgs_names = set ( ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> for importer , modname , ispkg in pkgutil . iter_modules ( object . __path__ ) : <EOL> modpkgs_names . add ( modname ) <EOL> if ispkg : <EOL> modpkgs . append ( modname + '<STR_LIT>' ) <EOL> else : <EOL> modpkgs . append ( modname ) <EOL> modpkgs . sort ( ) <EOL> result = result + self . section ( <EOL> '<STR_LIT>' , join ( modpkgs , '<STR_LIT:\n>' ) ) <EOL> submodules = [ ] <EOL> for key , value in inspect . getmembers ( object , inspect . ismodule ) : <EOL> if value . __name__ . startswith ( name + '<STR_LIT:.>' ) and key not in modpkgs_names : <EOL> submodules . append ( key ) <EOL> if submodules : <EOL> submodules . sort ( ) <EOL> result = result + self . section ( <EOL> '<STR_LIT>' , join ( submodules , '<STR_LIT:\n>' ) ) <EOL> if classes : <EOL> classlist = map ( lambda key_value : key_value [ <NUM_LIT:1> ] , classes ) <EOL> contents = [ self . formattree ( <EOL> inspect . getclasstree ( classlist , <NUM_LIT:1> ) , name ) ] <EOL> for key , value in classes : <EOL> contents . append ( self . document ( value , key , name ) ) <EOL> result = result + self . section ( '<STR_LIT>' , join ( contents , '<STR_LIT:\n>' ) ) <EOL> if funcs : <EOL> contents = [ ] <EOL> for key , value in funcs : <EOL> contents . append ( self . document ( value , key , name ) ) <EOL> result = result + self . section ( '<STR_LIT>' , join ( contents , '<STR_LIT:\n>' ) ) <EOL> if data : <EOL> contents = [ ] <EOL> for key , value in data : <EOL> contents . append ( self . docother ( value , key , name , maxlen = <NUM_LIT> ) ) <EOL> result = result + self . section ( '<STR_LIT>' , join ( contents , '<STR_LIT:\n>' ) ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> version = str ( object . __version__ ) <EOL> if version [ : <NUM_LIT:11> ] == '<STR_LIT:$>' + '<STR_LIT>' and version [ - <NUM_LIT:1> : ] == '<STR_LIT:$>' : <EOL> version = strip ( version [ <NUM_LIT:11> : - <NUM_LIT:1> ] ) <EOL> result = result + self . section ( '<STR_LIT>' , version ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> result = result + self . section ( '<STR_LIT>' , str ( object . __date__ ) ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> result = result + self . section ( '<STR_LIT>' , str ( object . __author__ ) ) <EOL> if hasattr ( object , '<STR_LIT>' ) : <EOL> result = result + self . section ( '<STR_LIT>' , str ( object . __credits__ ) ) <EOL> return result <EOL> def docclass ( self , object , name = None , mod = None ) : <EOL> """<STR_LIT>""" <EOL> realname = object . __name__ <EOL> name = name or realname <EOL> bases = object . __bases__ <EOL> def makename ( c , m = object . __module__ ) : <EOL> return classname ( c , m ) <EOL> if name == realname : <EOL> title = '<STR_LIT>' + self . bold ( realname ) <EOL> else : <EOL> title = self . bold ( name ) + '<STR_LIT>' + realname <EOL> if bases : <EOL> parents = map ( makename , bases ) <EOL> title = title + '<STR_LIT>' % join ( parents , '<STR_LIT:U+002CU+0020>' ) <EOL> doc = getdoc ( object ) <EOL> contents = doc and [ doc + '<STR_LIT:\n>' ] or [ ] <EOL> push = contents . append <EOL> mro = deque ( inspect . getmro ( object ) ) <EOL> if len ( mro ) > <NUM_LIT:2> : <EOL> push ( "<STR_LIT>" ) <EOL> for base in mro : <EOL> push ( '<STR_LIT:U+0020>' + makename ( base ) ) <EOL> push ( '<STR_LIT>' ) <EOL> class HorizontalRule : <EOL> def __init__ ( self ) : <EOL> self . needone = <NUM_LIT:0> <EOL> def maybe ( self ) : <EOL> if self . needone : <EOL> push ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> self . needone = <NUM_LIT:1> <EOL> hr = HorizontalRule ( ) <EOL> def spill ( msg , attrs , predicate ) : <EOL> ok , attrs = _split_list ( attrs , predicate ) <EOL> if ok : <EOL> hr . maybe ( ) <EOL> push ( msg ) <EOL> for name , kind , homecls , value in ok : <EOL> push ( self . document ( getattr ( object , name ) , <EOL> name , mod , object ) ) <EOL> return attrs <EOL> def spilldescriptors ( msg , attrs , predicate ) : <EOL> ok , attrs = _split_list ( attrs , predicate ) <EOL> if ok : <EOL> hr . maybe ( ) <EOL> push ( msg ) <EOL> for name , kind , homecls , value in ok : <EOL> push ( self . _docdescriptor ( name , value , mod ) ) <EOL> return attrs <EOL> def spilldata ( msg , attrs , predicate ) : <EOL> ok , attrs = _split_list ( attrs , predicate ) <EOL> if ok : <EOL> hr . maybe ( ) <EOL> push ( msg ) <EOL> for name , kind , homecls , value in ok : <EOL> if ( hasattr ( value , '<STR_LIT>' ) or <EOL> inspect . isdatadescriptor ( value ) ) : <EOL> doc = getdoc ( value ) <EOL> else : <EOL> doc = None <EOL> push ( self . docother ( getattr ( object , name ) , <EOL> name , mod , maxlen = <NUM_LIT> , doc = doc ) + '<STR_LIT:\n>' ) <EOL> return attrs <EOL> attrs = filter ( lambda data : visiblename ( data [ <NUM_LIT:0> ] ) , <EOL> classify_class_attrs ( object ) ) <EOL> while attrs : <EOL> if mro : <EOL> thisclass = mro . popleft ( ) <EOL> else : <EOL> thisclass = attrs [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] <EOL> attrs , inherited = _split_list ( attrs , lambda t : t [ <NUM_LIT:2> ] is thisclass ) <EOL> if thisclass is __builtin__ . object : <EOL> attrs = inherited <EOL> continue <EOL> elif thisclass is object : <EOL> tag = "<STR_LIT>" <EOL> else : <EOL> tag = "<STR_LIT>" % classname ( thisclass , <EOL> object . __module__ ) <EOL> attrs . sort ( ) <EOL> attrs = spill ( "<STR_LIT>" % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spill ( "<STR_LIT>" % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spill ( "<STR_LIT>" % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spilldescriptors ( "<STR_LIT>" % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> attrs = spilldata ( "<STR_LIT>" % tag , attrs , <EOL> lambda t : t [ <NUM_LIT:1> ] == '<STR_LIT:data>' ) <EOL> assert attrs == [ ] <EOL> attrs = inherited <EOL> contents = '<STR_LIT:\n>' . join ( contents ) <EOL> if not contents : <EOL> return title + '<STR_LIT:\n>' <EOL> return title + '<STR_LIT:\n>' + self . indent ( rstrip ( contents ) , '<STR_LIT>' ) + '<STR_LIT:\n>' <EOL> def formatvalue ( self , object ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:=>' + self . repr ( object ) <EOL> def docroutine ( self , object , name = None , mod = None , cl = None ) : <EOL> """<STR_LIT>""" <EOL> realname = object . __name__ <EOL> name = name or realname <EOL> note = '<STR_LIT>' <EOL> skipdocs = <NUM_LIT:0> <EOL> if inspect . ismethod ( object ) : <EOL> imclass = object . im_class <EOL> if cl : <EOL> if imclass is not cl : <EOL> note = '<STR_LIT>' + classname ( imclass , mod ) <EOL> else : <EOL> if object . im_self is not None : <EOL> note = '<STR_LIT>' % classname ( <EOL> object . im_self . __class__ , mod ) <EOL> else : <EOL> note = '<STR_LIT>' % classname ( imclass , mod ) <EOL> object = object . im_func <EOL> if name == realname : <EOL> title = self . bold ( realname ) <EOL> else : <EOL> if ( cl and realname in cl . __dict__ and <EOL> cl . __dict__ [ realname ] is object ) : <EOL> skipdocs = <NUM_LIT:1> <EOL> title = self . bold ( name ) + '<STR_LIT>' + realname <EOL> if inspect . isfunction ( object ) : <EOL> args , varargs , varkw , defaults = inspect . getargspec ( object ) <EOL> argspec = inspect . formatargspec ( <EOL> args , varargs , varkw , defaults , formatvalue = self . formatvalue ) <EOL> if realname == '<STR_LIT>' : <EOL> title = self . bold ( name ) + '<STR_LIT>' <EOL> argspec = argspec [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> else : <EOL> argspec = '<STR_LIT>' <EOL> decl = title + argspec + note <EOL> if skipdocs : <EOL> return decl + '<STR_LIT:\n>' <EOL> else : <EOL> doc = getdoc ( object ) or '<STR_LIT>' <EOL> return decl + '<STR_LIT:\n>' + ( doc and rstrip ( self . indent ( doc ) ) + '<STR_LIT:\n>' ) <EOL> def _docdescriptor ( self , name , value , mod ) : <EOL> results = [ ] <EOL> push = results . append <EOL> if name : <EOL> push ( self . bold ( name ) ) <EOL> push ( '<STR_LIT:\n>' ) <EOL> doc = getdoc ( value ) or '<STR_LIT>' <EOL> if doc : <EOL> push ( self . indent ( doc ) ) <EOL> push ( '<STR_LIT:\n>' ) <EOL> return '<STR_LIT>' . join ( results ) <EOL> def docproperty ( self , object , name = None , mod = None , cl = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _docdescriptor ( name , object , mod ) <EOL> def docdata ( self , object , name = None , mod = None , cl = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _docdescriptor ( name , object , mod ) <EOL> def docother ( self , object , name = None , mod = None , parent = None , maxlen = None , doc = None ) : <EOL> """<STR_LIT>""" <EOL> repr = self . repr ( object ) <EOL> if maxlen : <EOL> line = ( name and name + '<STR_LIT>' or '<STR_LIT>' ) + repr <EOL> chop = maxlen - len ( line ) <EOL> if chop < <NUM_LIT:0> : repr = repr [ : chop ] + '<STR_LIT>' <EOL> line = ( name and self . bold ( name ) + '<STR_LIT>' or '<STR_LIT>' ) + repr <EOL> if doc is not None : <EOL> line += '<STR_LIT:\n>' + self . indent ( str ( doc ) ) <EOL> return line <EOL> def pager ( text ) : <EOL> """<STR_LIT>""" <EOL> global pager <EOL> pager = getpager ( ) <EOL> pager ( text ) <EOL> def getpager ( ) : <EOL> """<STR_LIT>""" <EOL> if type ( sys . stdout ) is not types . FileType : <EOL> return plainpager <EOL> if not sys . stdin . isatty ( ) or not sys . stdout . isatty ( ) : <EOL> return plainpager <EOL> if '<STR_LIT>' in os . environ : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> return lambda text : tempfilepager ( plain ( text ) , os . environ [ '<STR_LIT>' ] ) <EOL> elif os . environ . get ( '<STR_LIT>' ) in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return lambda text : pipepager ( plain ( text ) , os . environ [ '<STR_LIT>' ] ) <EOL> else : <EOL> return lambda text : pipepager ( text , os . environ [ '<STR_LIT>' ] ) <EOL> if os . environ . get ( '<STR_LIT>' ) in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return plainpager <EOL> if sys . platform == '<STR_LIT:win32>' or sys . platform . startswith ( '<STR_LIT>' ) : <EOL> return lambda text : tempfilepager ( plain ( text ) , '<STR_LIT>' ) <EOL> if hasattr ( os , '<STR_LIT>' ) and os . system ( '<STR_LIT>' ) == <NUM_LIT:0> : <EOL> return lambda text : pipepager ( text , '<STR_LIT>' ) <EOL> import tempfile <EOL> ( fd , filename ) = tempfile . mkstemp ( ) <EOL> os . close ( fd ) <EOL> try : <EOL> if hasattr ( os , '<STR_LIT>' ) and os . system ( '<STR_LIT>' % filename ) == <NUM_LIT:0> : <EOL> return lambda text : pipepager ( text , '<STR_LIT>' ) <EOL> else : <EOL> return ttypager <EOL> finally : <EOL> os . unlink ( filename ) <EOL> def plain ( text ) : <EOL> """<STR_LIT>""" <EOL> return re . sub ( '<STR_LIT>' , '<STR_LIT>' , text ) <EOL> def pipepager ( text , cmd ) : <EOL> """<STR_LIT>""" <EOL> pipe = os . popen ( cmd , '<STR_LIT:w>' ) <EOL> try : <EOL> pipe . write ( text ) <EOL> pipe . close ( ) <EOL> except IOError : <EOL> pass <EOL> def tempfilepager ( text , cmd ) : <EOL> """<STR_LIT>""" <EOL> import tempfile <EOL> filename = tempfile . mktemp ( ) <EOL> file = open ( filename , '<STR_LIT:w>' ) <EOL> file . write ( text ) <EOL> file . close ( ) <EOL> try : <EOL> os . system ( cmd + '<STR_LIT>' + filename + '<STR_LIT:">' ) <EOL> finally : <EOL> os . unlink ( filename ) <EOL> def ttypager ( text ) : <EOL> """<STR_LIT>""" <EOL> lines = split ( plain ( text ) , '<STR_LIT:\n>' ) <EOL> try : <EOL> import tty <EOL> fd = sys . stdin . fileno ( ) <EOL> old = tty . tcgetattr ( fd ) <EOL> tty . setcbreak ( fd ) <EOL> getchar = lambda : sys . stdin . read ( <NUM_LIT:1> ) <EOL> except ( ImportError , AttributeError ) : <EOL> tty = None <EOL> getchar = lambda : sys . stdin . readline ( ) [ : - <NUM_LIT:1> ] [ : <NUM_LIT:1> ] <EOL> try : <EOL> r = inc = os . environ . get ( '<STR_LIT>' , <NUM_LIT> ) - <NUM_LIT:1> <EOL> sys . stdout . write ( join ( lines [ : inc ] , '<STR_LIT:\n>' ) + '<STR_LIT:\n>' ) <EOL> while lines [ r : ] : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> c = getchar ( ) <EOL> if c in ( '<STR_LIT:q>' , '<STR_LIT>' ) : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> elif c in ( '<STR_LIT:\r>' , '<STR_LIT:\n>' ) : <EOL> sys . stdout . write ( '<STR_LIT>' + lines [ r ] + '<STR_LIT:\n>' ) <EOL> r = r + <NUM_LIT:1> <EOL> continue <EOL> if c in ( '<STR_LIT:b>' , '<STR_LIT:B>' , '<STR_LIT>' ) : <EOL> r = r - inc - inc <EOL> if r < <NUM_LIT:0> : r = <NUM_LIT:0> <EOL> sys . stdout . write ( '<STR_LIT:\n>' + join ( lines [ r : r + inc ] , '<STR_LIT:\n>' ) + '<STR_LIT:\n>' ) <EOL> r = r + inc <EOL> finally : <EOL> if tty : <EOL> tty . tcsetattr ( fd , tty . TCSAFLUSH , old ) <EOL> def plainpager ( text ) : <EOL> """<STR_LIT>""" <EOL> sys . stdout . write ( plain ( text ) ) <EOL> def describe ( thing ) : <EOL> """<STR_LIT>""" <EOL> if inspect . ismodule ( thing ) : <EOL> if thing . __name__ in sys . builtin_module_names : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> if hasattr ( thing , '<STR_LIT>' ) : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> else : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> if inspect . isbuiltin ( thing ) : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> if inspect . isgetsetdescriptor ( thing ) : <EOL> return '<STR_LIT>' % ( <EOL> thing . __objclass__ . __module__ , thing . __objclass__ . __name__ , <EOL> thing . __name__ ) <EOL> if inspect . ismemberdescriptor ( thing ) : <EOL> return '<STR_LIT>' % ( <EOL> thing . __objclass__ . __module__ , thing . __objclass__ . __name__ , <EOL> thing . __name__ ) <EOL> if inspect . isclass ( thing ) : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> if inspect . isfunction ( thing ) : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> if inspect . ismethod ( thing ) : <EOL> return '<STR_LIT>' + thing . __name__ <EOL> if type ( thing ) is types . InstanceType : <EOL> return '<STR_LIT>' + thing . __class__ . __name__ <EOL> return type ( thing ) . __name__ <EOL> def locate ( path , forceload = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> parts = [ part for part in split ( path , '<STR_LIT:.>' ) if part ] <EOL> module , n = None , <NUM_LIT:0> <EOL> while n < len ( parts ) : <EOL> nextmodule = safeimport ( join ( parts [ : n + <NUM_LIT:1> ] , '<STR_LIT:.>' ) , forceload ) <EOL> if nextmodule : module , n = nextmodule , n + <NUM_LIT:1> <EOL> else : break <EOL> if module : <EOL> object = module <EOL> for part in parts [ n : ] : <EOL> try : object = getattr ( object , part ) <EOL> except AttributeError : return None <EOL> return object <EOL> else : <EOL> if hasattr ( __builtin__ , path ) : <EOL> return getattr ( __builtin__ , path ) <EOL> text = TextDoc ( ) <EOL> html = HTMLDoc ( ) <EOL> class _OldStyleClass : pass <EOL> _OLD_INSTANCE_TYPE = type ( _OldStyleClass ( ) ) <EOL> def resolve ( thing , forceload = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( thing , str ) : <EOL> object = locate ( thing , forceload ) <EOL> if not object : <EOL> raise ImportError , '<STR_LIT>' % thing <EOL> return object , thing <EOL> else : <EOL> return thing , getattr ( thing , '<STR_LIT>' , None ) <EOL> def render_doc ( thing , title = '<STR_LIT>' , forceload = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> object , name = resolve ( thing , forceload ) <EOL> desc = describe ( object ) <EOL> module = inspect . getmodule ( object ) <EOL> if name and '<STR_LIT:.>' in name : <EOL> desc += '<STR_LIT>' + name [ : name . rfind ( '<STR_LIT:.>' ) ] <EOL> elif module and module is not object : <EOL> desc += '<STR_LIT>' + module . __name__ <EOL> if type ( object ) is _OLD_INSTANCE_TYPE : <EOL> object = object . __class__ <EOL> elif not ( inspect . ismodule ( object ) or <EOL> inspect . isclass ( object ) or <EOL> inspect . isroutine ( object ) or <EOL> inspect . isgetsetdescriptor ( object ) or <EOL> inspect . ismemberdescriptor ( object ) or <EOL> isinstance ( object , property ) ) : <EOL> object = type ( object ) <EOL> desc += '<STR_LIT>' <EOL> return title % desc + '<STR_LIT>' + text . document ( object , name ) <EOL> def doc ( thing , title = '<STR_LIT>' , forceload = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> pager ( render_doc ( thing , title , forceload ) ) <EOL> except ( ImportError , ErrorDuringImport ) , value : <EOL> print value <EOL> def writedoc ( thing , forceload = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> object , name = resolve ( thing , forceload ) <EOL> page = html . page ( describe ( object ) , html . document ( object , name ) ) <EOL> file = open ( name + '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> file . write ( page ) <EOL> file . close ( ) <EOL> print '<STR_LIT>' , name + '<STR_LIT>' <EOL> except ( ImportError , ErrorDuringImport ) , value : <EOL> print value <EOL> def writedocs ( dir , pkgpath = '<STR_LIT>' , done = None ) : <EOL> """<STR_LIT>""" <EOL> if done is None : done = { } <EOL> for importer , modname , ispkg in pkgutil . walk_packages ( [ dir ] , pkgpath ) : <EOL> writedoc ( modname ) <EOL> return <EOL> class Helper : <EOL> keywords = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:class>' : ( '<STR_LIT:class>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> topics = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , input , output ) : <EOL> self . input = input <EOL> self . output = output <EOL> def __repr__ ( self ) : <EOL> if inspect . stack ( ) [ <NUM_LIT:1> ] [ <NUM_LIT:3> ] == '<STR_LIT:?>' : <EOL> self ( ) <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> def __call__ ( self , request = None ) : <EOL> if request is not None : <EOL> self . help ( request ) <EOL> else : <EOL> self . intro ( ) <EOL> self . interact ( ) <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> def interact ( self ) : <EOL> self . output . write ( '<STR_LIT:\n>' ) <EOL> while True : <EOL> try : <EOL> request = self . getline ( '<STR_LIT>' ) <EOL> if not request : break <EOL> except ( KeyboardInterrupt , EOFError ) : <EOL> break <EOL> request = strip ( replace ( request , '<STR_LIT:">' , '<STR_LIT>' , "<STR_LIT:'>" , '<STR_LIT>' ) ) <EOL> if lower ( request ) in ( '<STR_LIT:q>' , '<STR_LIT>' ) : break <EOL> self . help ( request ) <EOL> def getline ( self , prompt ) : <EOL> """<STR_LIT>""" <EOL> if self . input is sys . stdin : <EOL> return raw_input ( prompt ) <EOL> else : <EOL> self . output . write ( prompt ) <EOL> self . output . flush ( ) <EOL> return self . input . readline ( ) <EOL> def help ( self , request ) : <EOL> if type ( request ) is type ( '<STR_LIT>' ) : <EOL> if request == '<STR_LIT>' : self . intro ( ) <EOL> elif request == '<STR_LIT>' : self . listkeywords ( ) <EOL> elif request == '<STR_LIT>' : self . listtopics ( ) <EOL> elif request == '<STR_LIT>' : self . listmodules ( ) <EOL> elif request [ : <NUM_LIT:8> ] == '<STR_LIT>' : <EOL> self . listmodules ( split ( request ) [ <NUM_LIT:1> ] ) <EOL> elif request in self . keywords : self . showtopic ( request ) <EOL> elif request in self . topics : self . showtopic ( request ) <EOL> elif request : doc ( request , '<STR_LIT>' ) <EOL> elif isinstance ( request , Helper ) : self ( ) <EOL> else : doc ( request , '<STR_LIT>' ) <EOL> self . output . write ( '<STR_LIT:\n>' ) <EOL> def intro ( self ) : <EOL> self . output . write ( '''<STR_LIT>''' % sys . version [ : <NUM_LIT:3> ] ) <EOL> def list ( self , items , columns = <NUM_LIT:4> , width = <NUM_LIT> ) : <EOL> items = items [ : ] <EOL> items . sort ( ) <EOL> colw = width / columns <EOL> rows = ( len ( items ) + columns - <NUM_LIT:1> ) / columns <EOL> for row in range ( rows ) : <EOL> for col in range ( columns ) : <EOL> i = col * rows + row <EOL> if i < len ( items ) : <EOL> self . output . write ( items [ i ] ) <EOL> if col < columns - <NUM_LIT:1> : <EOL> self . output . write ( '<STR_LIT:U+0020>' + '<STR_LIT:U+0020>' * ( colw - <NUM_LIT:1> - len ( items [ i ] ) ) ) <EOL> self . output . write ( '<STR_LIT:\n>' ) <EOL> def listkeywords ( self ) : <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> self . list ( self . keywords . keys ( ) ) <EOL> def listtopics ( self ) : <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> self . list ( self . topics . keys ( ) ) <EOL> def showtopic ( self , topic ) : <EOL> try : <EOL> import pydoc_topics <EOL> except ImportError : <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> return <EOL> target = self . topics . get ( topic , self . keywords . get ( topic ) ) <EOL> if not target : <EOL> self . output . write ( '<STR_LIT>' % repr ( topic ) ) <EOL> return <EOL> if type ( target ) is type ( '<STR_LIT>' ) : <EOL> return self . showtopic ( target ) <EOL> label , xrefs = target <EOL> try : <EOL> doc = pydoc_topics . topics [ label ] <EOL> except KeyError : <EOL> self . output . write ( '<STR_LIT>' % repr ( topic ) ) <EOL> return <EOL> pager ( strip ( doc ) + '<STR_LIT:\n>' ) <EOL> if xrefs : <EOL> import StringIO , formatter <EOL> buffer = StringIO . StringIO ( ) <EOL> formatter . DumbWriter ( buffer ) . send_flowing_data ( <EOL> '<STR_LIT>' + join ( split ( xrefs ) , '<STR_LIT:U+002CU+0020>' ) + '<STR_LIT:\n>' ) <EOL> self . output . write ( '<STR_LIT>' % buffer . getvalue ( ) ) <EOL> def listmodules ( self , key = '<STR_LIT>' ) : <EOL> if key : <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> apropos ( key ) <EOL> else : <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> modules = { } <EOL> def callback ( path , modname , desc , modules = modules ) : <EOL> if modname and modname [ - <NUM_LIT:9> : ] == '<STR_LIT>' : <EOL> modname = modname [ : - <NUM_LIT:9> ] + '<STR_LIT>' <EOL> if find ( modname , '<STR_LIT:.>' ) < <NUM_LIT:0> : <EOL> modules [ modname ] = <NUM_LIT:1> <EOL> def onerror ( modname ) : <EOL> callback ( None , modname , None ) <EOL> ModuleScanner ( ) . run ( callback , onerror = onerror ) <EOL> self . list ( modules . keys ( ) ) <EOL> self . output . write ( '''<STR_LIT>''' ) <EOL> help = Helper ( sys . stdin , sys . stdout ) <EOL> class Scanner : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , roots , children , descendp ) : <EOL> self . roots = roots [ : ] <EOL> self . state = [ ] <EOL> self . children = children <EOL> self . descendp = descendp <EOL> def next ( self ) : <EOL> if not self . state : <EOL> if not self . roots : <EOL> return None <EOL> root = self . roots . pop ( <NUM_LIT:0> ) <EOL> self . state = [ ( root , self . children ( root ) ) ] <EOL> node , children = self . state [ - <NUM_LIT:1> ] <EOL> if not children : <EOL> self . state . pop ( ) <EOL> return self . next ( ) <EOL> child = children . pop ( <NUM_LIT:0> ) <EOL> if self . descendp ( child ) : <EOL> self . state . append ( ( child , self . children ( child ) ) ) <EOL> return child <EOL> class ModuleScanner : <EOL> """<STR_LIT>""" <EOL> def run ( self , callback , key = None , completer = None , onerror = None ) : <EOL> if key : key = lower ( key ) <EOL> self . quit = False <EOL> seen = { } <EOL> for modname in sys . builtin_module_names : <EOL> if modname != '<STR_LIT:__main__>' : <EOL> seen [ modname ] = <NUM_LIT:1> <EOL> if key is None : <EOL> callback ( None , modname , '<STR_LIT>' ) <EOL> else : <EOL> desc = split ( __import__ ( modname ) . __doc__ or '<STR_LIT>' , '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] <EOL> if find ( lower ( modname + '<STR_LIT>' + desc ) , key ) >= <NUM_LIT:0> : <EOL> callback ( None , modname , desc ) <EOL> for importer , modname , ispkg in pkgutil . walk_packages ( onerror = onerror ) : <EOL> if self . quit : <EOL> break <EOL> if key is None : <EOL> callback ( None , modname , '<STR_LIT>' ) <EOL> else : <EOL> loader = importer . find_module ( modname ) <EOL> if hasattr ( loader , '<STR_LIT>' ) : <EOL> import StringIO <EOL> desc = source_synopsis ( <EOL> StringIO . StringIO ( loader . get_source ( modname ) ) <EOL> ) or '<STR_LIT>' <EOL> if hasattr ( loader , '<STR_LIT>' ) : <EOL> path = loader . get_filename ( modname ) <EOL> else : <EOL> path = None <EOL> else : <EOL> module = loader . load_module ( modname ) <EOL> desc = ( module . __doc__ or '<STR_LIT>' ) . splitlines ( ) [ <NUM_LIT:0> ] <EOL> path = getattr ( module , '<STR_LIT>' , None ) <EOL> if find ( lower ( modname + '<STR_LIT>' + desc ) , key ) >= <NUM_LIT:0> : <EOL> callback ( path , modname , desc ) <EOL> if completer : <EOL> completer ( ) <EOL> def apropos ( key ) : <EOL> """<STR_LIT>""" <EOL> def callback ( path , modname , desc ) : <EOL> if modname [ - <NUM_LIT:9> : ] == '<STR_LIT>' : <EOL> modname = modname [ : - <NUM_LIT:9> ] + '<STR_LIT>' <EOL> print modname , desc and '<STR_LIT>' + desc <EOL> try : import warnings <EOL> except ImportError : pass <EOL> else : warnings . filterwarnings ( '<STR_LIT:ignore>' ) <EOL> ModuleScanner ( ) . run ( callback , key ) <EOL> def serve ( port , callback = None , completer = None ) : <EOL> import BaseHTTPServer , mimetools , select <EOL> class Message ( mimetools . Message ) : <EOL> def __init__ ( self , fp , seekable = <NUM_LIT:1> ) : <EOL> Message = self . __class__ <EOL> Message . __bases__ [ <NUM_LIT:0> ] . __bases__ [ <NUM_LIT:0> ] . __init__ ( self , fp , seekable ) <EOL> self . encodingheader = self . getheader ( '<STR_LIT>' ) <EOL> self . typeheader = self . getheader ( '<STR_LIT>' ) <EOL> self . parsetype ( ) <EOL> self . parseplist ( ) <EOL> class DocHandler ( BaseHTTPServer . BaseHTTPRequestHandler ) : <EOL> def send_document ( self , title , contents ) : <EOL> try : <EOL> self . send_response ( <NUM_LIT:200> ) <EOL> self . send_header ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> self . end_headers ( ) <EOL> self . wfile . write ( html . page ( title , contents ) ) <EOL> except IOError : pass <EOL> def do_GET ( self ) : <EOL> path = self . path <EOL> if path [ - <NUM_LIT:5> : ] == '<STR_LIT>' : path = path [ : - <NUM_LIT:5> ] <EOL> if path [ : <NUM_LIT:1> ] == '<STR_LIT:/>' : path = path [ <NUM_LIT:1> : ] <EOL> if path and path != '<STR_LIT:.>' : <EOL> try : <EOL> obj = locate ( path , forceload = <NUM_LIT:1> ) <EOL> except ErrorDuringImport , value : <EOL> self . send_document ( path , html . escape ( str ( value ) ) ) <EOL> return <EOL> if obj : <EOL> self . send_document ( describe ( obj ) , html . document ( obj , path ) ) <EOL> else : <EOL> self . send_document ( path , <EOL> '<STR_LIT>' % repr ( path ) ) <EOL> else : <EOL> heading = html . heading ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def bltinlink ( name ) : <EOL> return '<STR_LIT>' % ( name , name ) <EOL> names = filter ( lambda x : x != '<STR_LIT:__main__>' , <EOL> sys . builtin_module_names ) <EOL> contents = html . multicolumn ( names , bltinlink ) <EOL> indices = [ '<STR_LIT>' + html . bigsection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , contents ) ] <EOL> seen = { } <EOL> for dir in sys . path : <EOL> indices . append ( html . index ( dir , seen ) ) <EOL> contents = heading + join ( indices ) + '''<STR_LIT>''' <EOL> self . send_document ( '<STR_LIT>' , contents ) <EOL> def log_message ( self , * args ) : pass <EOL> class DocServer ( BaseHTTPServer . HTTPServer ) : <EOL> def __init__ ( self , port , callback ) : <EOL> host = ( sys . platform == '<STR_LIT>' ) and '<STR_LIT:127.0.0.1>' or '<STR_LIT:localhost>' <EOL> self . address = ( '<STR_LIT>' , port ) <EOL> self . url = '<STR_LIT>' % ( host , port ) <EOL> self . callback = callback <EOL> self . base . __init__ ( self , self . address , self . handler ) <EOL> def serve_until_quit ( self ) : <EOL> import select <EOL> self . quit = False <EOL> while not self . quit : <EOL> rd , wr , ex = select . select ( [ self . socket . fileno ( ) ] , [ ] , [ ] , <NUM_LIT:1> ) <EOL> if rd : self . handle_request ( ) <EOL> def server_activate ( self ) : <EOL> self . base . server_activate ( self ) <EOL> if self . callback : self . callback ( self ) <EOL> DocServer . base = BaseHTTPServer . HTTPServer <EOL> DocServer . handler = DocHandler <EOL> DocHandler . MessageClass = Message <EOL> try : <EOL> try : <EOL> DocServer ( port , callback ) . serve_until_quit ( ) <EOL> except ( KeyboardInterrupt , select . error ) : <EOL> pass <EOL> finally : <EOL> if completer : completer ( ) <EOL> def gui ( ) : <EOL> """<STR_LIT>""" <EOL> class GUI : <EOL> def __init__ ( self , window , port = <NUM_LIT> ) : <EOL> self . window = window <EOL> self . server = None <EOL> self . scanner = None <EOL> import Tkinter <EOL> self . server_frm = Tkinter . Frame ( window ) <EOL> self . title_lbl = Tkinter . Label ( self . server_frm , <EOL> text = '<STR_LIT>' ) <EOL> self . open_btn = Tkinter . Button ( self . server_frm , <EOL> text = '<STR_LIT>' , command = self . open , state = '<STR_LIT>' ) <EOL> self . quit_btn = Tkinter . Button ( self . server_frm , <EOL> text = '<STR_LIT>' , command = self . quit , state = '<STR_LIT>' ) <EOL> self . search_frm = Tkinter . Frame ( window ) <EOL> self . search_lbl = Tkinter . Label ( self . search_frm , text = '<STR_LIT>' ) <EOL> self . search_ent = Tkinter . Entry ( self . search_frm ) <EOL> self . search_ent . bind ( '<STR_LIT>' , self . search ) <EOL> self . stop_btn = Tkinter . Button ( self . search_frm , <EOL> text = '<STR_LIT>' , pady = <NUM_LIT:0> , command = self . stop , state = '<STR_LIT>' ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> self . stop_btn . pack ( side = '<STR_LIT:right>' ) <EOL> self . window . title ( '<STR_LIT>' ) <EOL> self . window . protocol ( '<STR_LIT>' , self . quit ) <EOL> self . title_lbl . pack ( side = '<STR_LIT>' , fill = '<STR_LIT:x>' ) <EOL> self . open_btn . pack ( side = '<STR_LIT:left>' , fill = '<STR_LIT:x>' , expand = <NUM_LIT:1> ) <EOL> self . quit_btn . pack ( side = '<STR_LIT:right>' , fill = '<STR_LIT:x>' , expand = <NUM_LIT:1> ) <EOL> self . server_frm . pack ( side = '<STR_LIT>' , fill = '<STR_LIT:x>' ) <EOL> self . search_lbl . pack ( side = '<STR_LIT:left>' ) <EOL> self . search_ent . pack ( side = '<STR_LIT:right>' , fill = '<STR_LIT:x>' , expand = <NUM_LIT:1> ) <EOL> self . search_frm . pack ( side = '<STR_LIT>' , fill = '<STR_LIT:x>' ) <EOL> self . search_ent . focus_set ( ) <EOL> font = ( '<STR_LIT>' , sys . platform == '<STR_LIT:win32>' and <NUM_LIT:8> or <NUM_LIT:10> ) <EOL> self . result_lst = Tkinter . Listbox ( window , font = font , height = <NUM_LIT:6> ) <EOL> self . result_lst . bind ( '<STR_LIT>' , self . select ) <EOL> self . result_lst . bind ( '<STR_LIT>' , self . goto ) <EOL> self . result_scr = Tkinter . Scrollbar ( window , <EOL> orient = '<STR_LIT>' , command = self . result_lst . yview ) <EOL> self . result_lst . config ( yscrollcommand = self . result_scr . set ) <EOL> self . result_frm = Tkinter . Frame ( window ) <EOL> self . goto_btn = Tkinter . Button ( self . result_frm , <EOL> text = '<STR_LIT>' , command = self . goto ) <EOL> self . hide_btn = Tkinter . Button ( self . result_frm , <EOL> text = '<STR_LIT>' , command = self . hide ) <EOL> self . goto_btn . pack ( side = '<STR_LIT:left>' , fill = '<STR_LIT:x>' , expand = <NUM_LIT:1> ) <EOL> self . hide_btn . pack ( side = '<STR_LIT:right>' , fill = '<STR_LIT:x>' , expand = <NUM_LIT:1> ) <EOL> self . window . update ( ) <EOL> self . minwidth = self . window . winfo_width ( ) <EOL> self . minheight = self . window . winfo_height ( ) <EOL> self . bigminheight = ( self . server_frm . winfo_reqheight ( ) + <EOL> self . search_frm . winfo_reqheight ( ) + <EOL> self . result_lst . winfo_reqheight ( ) + <EOL> self . result_frm . winfo_reqheight ( ) ) <EOL> self . bigwidth , self . bigheight = self . minwidth , self . bigminheight <EOL> self . expanded = <NUM_LIT:0> <EOL> self . window . wm_geometry ( '<STR_LIT>' % ( self . minwidth , self . minheight ) ) <EOL> self . window . wm_minsize ( self . minwidth , self . minheight ) <EOL> self . window . tk . willdispatch ( ) <EOL> import threading <EOL> threading . Thread ( <EOL> target = serve , args = ( port , self . ready , self . quit ) ) . start ( ) <EOL> def ready ( self , server ) : <EOL> self . server = server <EOL> self . title_lbl . config ( <EOL> text = '<STR_LIT>' + server . url ) <EOL> self . open_btn . config ( state = '<STR_LIT>' ) <EOL> self . quit_btn . config ( state = '<STR_LIT>' ) <EOL> def open ( self , event = None , url = None ) : <EOL> url = url or self . server . url <EOL> try : <EOL> import webbrowser <EOL> webbrowser . open ( url ) <EOL> except ImportError : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> os . system ( '<STR_LIT>' % url ) <EOL> elif sys . platform == '<STR_LIT>' : <EOL> try : import ic <EOL> except ImportError : pass <EOL> else : ic . launchurl ( url ) <EOL> else : <EOL> rc = os . system ( '<STR_LIT>' % url ) <EOL> if rc : os . system ( '<STR_LIT>' % url ) <EOL> def quit ( self , event = None ) : <EOL> if self . server : <EOL> self . server . quit = <NUM_LIT:1> <EOL> self . window . quit ( ) <EOL> def search ( self , event = None ) : <EOL> key = self . search_ent . get ( ) <EOL> self . stop_btn . pack ( side = '<STR_LIT:right>' ) <EOL> self . stop_btn . config ( state = '<STR_LIT>' ) <EOL> self . search_lbl . config ( text = '<STR_LIT>' % key ) <EOL> self . search_ent . forget ( ) <EOL> self . search_lbl . pack ( side = '<STR_LIT:left>' ) <EOL> self . result_lst . delete ( <NUM_LIT:0> , '<STR_LIT:end>' ) <EOL> self . goto_btn . config ( state = '<STR_LIT>' ) <EOL> self . expand ( ) <EOL> import threading <EOL> if self . scanner : <EOL> self . scanner . quit = <NUM_LIT:1> <EOL> self . scanner = ModuleScanner ( ) <EOL> threading . Thread ( target = self . scanner . run , <EOL> args = ( self . update , key , self . done ) ) . start ( ) <EOL> def update ( self , path , modname , desc ) : <EOL> if modname [ - <NUM_LIT:9> : ] == '<STR_LIT>' : <EOL> modname = modname [ : - <NUM_LIT:9> ] + '<STR_LIT>' <EOL> self . result_lst . insert ( '<STR_LIT:end>' , <EOL> modname + '<STR_LIT>' + ( desc or '<STR_LIT>' ) ) <EOL> def stop ( self , event = None ) : <EOL> if self . scanner : <EOL> self . scanner . quit = <NUM_LIT:1> <EOL> self . scanner = None <EOL> def done ( self ) : <EOL> self . scanner = None <EOL> self . search_lbl . config ( text = '<STR_LIT>' ) <EOL> self . search_lbl . pack ( side = '<STR_LIT:left>' ) <EOL> self . search_ent . pack ( side = '<STR_LIT:right>' , fill = '<STR_LIT:x>' , expand = <NUM_LIT:1> ) <EOL> if sys . platform != '<STR_LIT:win32>' : self . stop_btn . forget ( ) <EOL> self . stop_btn . config ( state = '<STR_LIT>' ) <EOL> def select ( self , event = None ) : <EOL> self . goto_btn . config ( state = '<STR_LIT>' ) <EOL> def goto ( self , event = None ) : <EOL> selection = self . result_lst . curselection ( ) <EOL> if selection : <EOL> modname = split ( self . result_lst . get ( selection [ <NUM_LIT:0> ] ) ) [ <NUM_LIT:0> ] <EOL> self . open ( url = self . server . url + modname + '<STR_LIT>' ) <EOL> def collapse ( self ) : <EOL> if not self . expanded : return <EOL> self . result_frm . forget ( ) <EOL> self . result_scr . forget ( ) <EOL> self . result_lst . forget ( ) <EOL> self . bigwidth = self . window . winfo_width ( ) <EOL> self . bigheight = self . window . winfo_height ( ) <EOL> self . window . wm_geometry ( '<STR_LIT>' % ( self . minwidth , self . minheight ) ) <EOL> self . window . wm_minsize ( self . minwidth , self . minheight ) <EOL> self . expanded = <NUM_LIT:0> <EOL> def expand ( self ) : <EOL> if self . expanded : return <EOL> self . result_frm . pack ( side = '<STR_LIT>' , fill = '<STR_LIT:x>' ) <EOL> self . result_scr . pack ( side = '<STR_LIT:right>' , fill = '<STR_LIT:y>' ) <EOL> self . result_lst . pack ( side = '<STR_LIT>' , fill = '<STR_LIT>' , expand = <NUM_LIT:1> ) <EOL> self . window . wm_geometry ( '<STR_LIT>' % ( self . bigwidth , self . bigheight ) ) <EOL> self . window . wm_minsize ( self . minwidth , self . bigminheight ) <EOL> self . expanded = <NUM_LIT:1> <EOL> def hide ( self , event = None ) : <EOL> self . stop ( ) <EOL> self . collapse ( ) <EOL> import Tkinter <EOL> try : <EOL> root = Tkinter . Tk ( ) <EOL> try : <EOL> gui = GUI ( root ) <EOL> root . mainloop ( ) <EOL> finally : <EOL> root . destroy ( ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> def ispath ( x ) : <EOL> return isinstance ( x , str ) and find ( x , os . sep ) >= <NUM_LIT:0> <EOL> def cli ( ) : <EOL> """<STR_LIT>""" <EOL> import getopt <EOL> class BadUsage : pass <EOL> scriptdir = os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) <EOL> if scriptdir in sys . path : <EOL> sys . path . remove ( scriptdir ) <EOL> sys . path . insert ( <NUM_LIT:0> , '<STR_LIT:.>' ) <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' ) <EOL> writing = <NUM_LIT:0> <EOL> for opt , val in opts : <EOL> if opt == '<STR_LIT>' : <EOL> gui ( ) <EOL> return <EOL> if opt == '<STR_LIT>' : <EOL> apropos ( val ) <EOL> return <EOL> if opt == '<STR_LIT>' : <EOL> try : <EOL> port = int ( val ) <EOL> except ValueError : <EOL> raise BadUsage <EOL> def ready ( server ) : <EOL> print '<STR_LIT>' % server . url <EOL> def stopped ( ) : <EOL> print '<STR_LIT>' <EOL> serve ( port , ready , stopped ) <EOL> return <EOL> if opt == '<STR_LIT>' : <EOL> writing = <NUM_LIT:1> <EOL> if not args : raise BadUsage <EOL> for arg in args : <EOL> if ispath ( arg ) and not os . path . exists ( arg ) : <EOL> print '<STR_LIT>' % arg <EOL> break <EOL> try : <EOL> if ispath ( arg ) and os . path . isfile ( arg ) : <EOL> arg = importfile ( arg ) <EOL> if writing : <EOL> if ispath ( arg ) and os . path . isdir ( arg ) : <EOL> writedocs ( arg ) <EOL> else : <EOL> writedoc ( arg ) <EOL> else : <EOL> help . help ( arg ) <EOL> except ErrorDuringImport , value : <EOL> print value <EOL> except ( getopt . error , BadUsage ) : <EOL> cmd = os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> print """<STR_LIT>""" % ( cmd , os . sep , cmd , cmd , cmd , cmd , os . sep ) <EOL> if __name__ == '<STR_LIT:__main__>' : cli ( ) </s>
