<s> VERSION_DATE = "<STR_LIT>" <EOL> VERSION = VERSION_DATE . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] <EOL> COPYRIGHT = "<STR_LIT>" <EOL> import site <EOL> import glob , os , re , string , sys , tokenize <EOL> try : <EOL> try : <EOL> import xml . etree . ElementTree as ET <EOL> except ImportError : <EOL> import elementtree . ElementTree as ET <EOL> except ImportError : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % VERSION <EOL> ) <EOL> try : <EOL> EXTSEP = os . extsep <EOL> except AttributeError : <EOL> EXTSEP = "<STR_LIT:.>" <EOL> DEBUG = <NUM_LIT:0> <EOL> WHITESPACE_TOKEN = ( <EOL> tokenize . NL , tokenize . NEWLINE , tokenize . DEDENT , tokenize . INDENT <EOL> ) <EOL> ENCODING = "<STR_LIT>" <EOL> TAGS = ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:version>" <EOL> ) <EOL> def joinext ( prefix , ext ) : <EOL> assert ext [ <NUM_LIT:0> ] == "<STR_LIT:.>" <EOL> return prefix + EXTSEP + ext [ <NUM_LIT:1> : ] <EOL> def gettags ( comment ) : <EOL> tags = [ ] <EOL> tag = None <EOL> tag_lineno = lineno = <NUM_LIT:0> <EOL> tag_text = [ ] <EOL> for line in comment : <EOL> if line [ : <NUM_LIT:1> ] == "<STR_LIT:@>" : <EOL> tags . append ( ( tag_lineno , tag , string . join ( tag_text , "<STR_LIT:\n>" ) ) ) <EOL> line = string . split ( line , "<STR_LIT:U+0020>" , <NUM_LIT:1> ) <EOL> tag = line [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> if len ( line ) > <NUM_LIT:1> : <EOL> tag_text = [ line [ <NUM_LIT:1> ] ] <EOL> else : <EOL> tag_text = [ ] <EOL> tag_lineno = lineno <EOL> else : <EOL> tag_text . append ( line ) <EOL> lineno = lineno + <NUM_LIT:1> <EOL> tags . append ( ( tag_lineno , tag , string . join ( tag_text , "<STR_LIT:\n>" ) ) ) <EOL> return tags <EOL> def flatten ( elem ) : <EOL> text = elem . text or "<STR_LIT>" <EOL> for e in elem : <EOL> text += flatten ( e ) <EOL> if e . tail : <EOL> text += e . tail <EOL> return text <EOL> def getsummary ( description ) : <EOL> description = flatten ( description ) <EOL> m = re . search ( "<STR_LIT>" , description + "<STR_LIT:U+0020>" ) <EOL> if m : <EOL> return m . group ( <NUM_LIT:1> ) <EOL> return description <EOL> def parsehtml ( parser , tag , text , lineno ) : <EOL> if parser . encoding != "<STR_LIT:ascii>" : <EOL> try : <EOL> text = unicode ( text , parser . encoding ) <EOL> except NameError : <EOL> pass <EOL> if "<STR_LIT:{>" in text : <EOL> def fixlink ( m , parser = parser , lineno = lineno ) : <EOL> linkdef = string . split ( m . group ( <NUM_LIT:1> ) , None , <NUM_LIT:2> ) <EOL> if len ( linkdef ) == <NUM_LIT:2> : <EOL> href = linkdef [ <NUM_LIT:1> ] <EOL> if href [ : <NUM_LIT:1> ] == "<STR_LIT:#>" : <EOL> href = href [ <NUM_LIT:1> : ] <EOL> linkdef . append ( string . split ( href , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) <EOL> if len ( linkdef ) < <NUM_LIT:3> or linkdef [ <NUM_LIT:0> ] not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> parser . warning ( <EOL> ( lineno , <NUM_LIT:0> ) , <EOL> "<STR_LIT>" , <EOL> ) <EOL> return m . group ( <NUM_LIT:0> ) <EOL> type , href , text = linkdef <EOL> href = "<STR_LIT>" + html_encode ( href ) <EOL> if type == "<STR_LIT>" : <EOL> return "<STR_LIT>" % ( href , text ) <EOL> else : <EOL> return "<STR_LIT>" % ( href , text ) <EOL> text = re . sub ( "<STR_LIT>" , fixlink , text ) <EOL> if "<STR_LIT:<>" not in text and "<STR_LIT:&>" not in text : <EOL> elem = ET . Element ( tag ) <EOL> elem . text = string . strip ( text ) <EOL> return elem <EOL> p = HTMLTreeBuilder ( ) <EOL> ix = <NUM_LIT:0> <EOL> try : <EOL> p . feed ( "<STR_LIT>" % tag ) <EOL> p . feed ( "<STR_LIT>" ) <EOL> for line in string . split ( text , "<STR_LIT:\n>" ) : <EOL> p . feed ( line + "<STR_LIT:\n>" ) <EOL> ix = ix + <NUM_LIT:1> <EOL> p . feed ( "<STR_LIT>" % tag ) <EOL> tree = p . close ( ) <EOL> except : <EOL> parser . warning ( <EOL> ( lineno + ix , <NUM_LIT:0> ) , <EOL> "<STR_LIT>" , <EOL> sys . exc_value <EOL> ) <EOL> return ET . Element ( "<STR_LIT:p>" ) <EOL> return tree <EOL> import htmlentitydefs <EOL> AUTOCLOSE = "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:body>" <EOL> IGNOREEND = "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> if sys . version [ : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> is_not_ascii = re . compile ( r"<STR_LIT>" ) . search <EOL> else : <EOL> is_not_ascii = re . compile ( eval ( r'<STR_LIT>' ) ) . search <EOL> try : <EOL> from HTMLParser import HTMLParser <EOL> except ImportError : <EOL> from sgmllib import SGMLParser <EOL> class HTMLParser ( SGMLParser ) : <EOL> def unknown_starttag ( self , tag , attrs ) : <EOL> self . handle_starttag ( tag , attrs ) <EOL> def unknown_endtag ( self , tag ) : <EOL> self . handle_endtag ( tag ) <EOL> class HTMLTreeBuilder ( HTMLParser ) : <EOL> def __init__ ( self , encoding = None ) : <EOL> self . __stack = [ ] <EOL> self . __builder = ET . TreeBuilder ( ) <EOL> self . encoding = encoding or "<STR_LIT>" <EOL> HTMLParser . __init__ ( self ) <EOL> def close ( self ) : <EOL> HTMLParser . close ( self ) <EOL> return self . __builder . close ( ) <EOL> def handle_starttag ( self , tag , attrs ) : <EOL> if tag == "<STR_LIT>" : <EOL> http_equiv = content = None <EOL> for k , v in attrs : <EOL> if k == "<STR_LIT>" : <EOL> http_equiv = string . lower ( v ) <EOL> elif k == "<STR_LIT:content>" : <EOL> content = v <EOL> if http_equiv == "<STR_LIT>" and content : <EOL> import mimetools , StringIO <EOL> header = mimetools . Message ( <EOL> StringIO . StringIO ( "<STR_LIT>" % ( http_equiv , content ) ) <EOL> ) <EOL> encoding = header . getparam ( "<STR_LIT>" ) <EOL> if encoding : <EOL> self . encoding = encoding <EOL> if tag in AUTOCLOSE : <EOL> if self . __stack and self . __stack [ - <NUM_LIT:1> ] == tag : <EOL> self . handle_endtag ( tag ) <EOL> self . __stack . append ( tag ) <EOL> attrib = { } <EOL> if attrs : <EOL> for k , v in attrs : <EOL> attrib [ string . lower ( k ) ] = v <EOL> self . __builder . start ( tag , attrib ) <EOL> if tag in IGNOREEND : <EOL> self . __stack . pop ( ) <EOL> self . __builder . end ( tag ) <EOL> def handle_endtag ( self , tag ) : <EOL> if tag in IGNOREEND : <EOL> return <EOL> lasttag = self . __stack . pop ( ) <EOL> if tag != lasttag and lasttag in AUTOCLOSE : <EOL> self . handle_endtag ( lasttag ) <EOL> self . __builder . end ( tag ) <EOL> def handle_charref ( self , char ) : <EOL> if char [ : <NUM_LIT:1> ] == "<STR_LIT:x>" : <EOL> char = int ( char [ <NUM_LIT:1> : ] , <NUM_LIT:16> ) <EOL> else : <EOL> char = int ( char ) <EOL> if <NUM_LIT:0> <= char < <NUM_LIT> : <EOL> self . __builder . data ( chr ( char ) ) <EOL> else : <EOL> self . __builder . data ( unichr ( char ) ) <EOL> def handle_entityref ( self , name ) : <EOL> entity = htmlentitydefs . entitydefs . get ( name ) <EOL> if entity : <EOL> if len ( entity ) == <NUM_LIT:1> : <EOL> entity = ord ( entity ) <EOL> else : <EOL> entity = int ( entity [ <NUM_LIT:2> : - <NUM_LIT:1> ] ) <EOL> if <NUM_LIT:0> <= entity < <NUM_LIT> : <EOL> self . __builder . data ( chr ( entity ) ) <EOL> else : <EOL> self . __builder . data ( unichr ( entity ) ) <EOL> else : <EOL> self . unknown_entityref ( name ) <EOL> def handle_data ( self , data ) : <EOL> if isinstance ( data , type ( '<STR_LIT>' ) ) and is_not_ascii ( data ) : <EOL> data = unicode ( data , self . encoding , "<STR_LIT:ignore>" ) <EOL> self . __builder . data ( data ) <EOL> def unknown_entityref ( self , name ) : <EOL> pass <EOL> def parsecomment ( parser , lineno , comment , dedent = <NUM_LIT:0> ) : <EOL> subject_info = ET . Element ( "<STR_LIT:info>" ) <EOL> for ix in range ( len ( comment ) ) : <EOL> comment [ ix ] = string . expandtabs ( comment [ ix ] ) <EOL> if dedent : <EOL> margin = None <EOL> for ix in range ( <NUM_LIT:1> , len ( comment ) ) : <EOL> s = string . lstrip ( comment [ ix ] ) <EOL> if not s : <EOL> continue <EOL> m = len ( comment [ ix ] ) - len ( s ) <EOL> if margin is None : <EOL> margin = m <EOL> else : <EOL> margin = min ( m , margin ) <EOL> if margin : <EOL> for ix in range ( <NUM_LIT:1> , len ( comment ) ) : <EOL> comment [ ix ] = comment [ ix ] [ margin : ] <EOL> for ix , tag , text in gettags ( comment ) : <EOL> pos = lineno + ix + <NUM_LIT:1> , <NUM_LIT:0> <EOL> if tag is None : <EOL> tag = "<STR_LIT:description>" <EOL> else : <EOL> if tag not in TAGS : <EOL> parser . warning ( <EOL> pos , <EOL> "<STR_LIT>" , tag <EOL> ) <EOL> if tag in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> tag = "<STR_LIT>" <EOL> if tag in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> text = string . split ( text , "<STR_LIT:U+0020>" , <NUM_LIT:1> ) <EOL> name = text [ <NUM_LIT:0> ] <EOL> if len ( text ) > <NUM_LIT:1> : <EOL> text = string . lstrip ( text [ <NUM_LIT:1> ] ) <EOL> else : <EOL> text = "<STR_LIT>" <EOL> else : <EOL> name = None <EOL> tag_elem = parsehtml ( parser , tag , text , pos [ <NUM_LIT:0> ] ) <EOL> if tag == "<STR_LIT:description>" : <EOL> summary = getsummary ( tag_elem ) <EOL> if summary : <EOL> elem = ET . SubElement ( subject_info , "<STR_LIT>" ) <EOL> elem . text = summary <EOL> subject_info . append ( tag_elem ) <EOL> if name : <EOL> tag_elem . set ( "<STR_LIT:name>" , name ) <EOL> return subject_info <EOL> class ModuleParser : <EOL> name = None <EOL> def __init__ ( self , file , prefix = None ) : <EOL> if hasattr ( file , "<STR_LIT>" ) : <EOL> self . file = file <EOL> self . filename = file . name <EOL> else : <EOL> self . file = None <EOL> self . filename = file <EOL> name = os . path . splitext ( os . path . basename ( self . filename ) ) [ <NUM_LIT:0> ] <EOL> if prefix and prefix != "<STR_LIT:.>" : <EOL> name = prefix + "<STR_LIT:.>" + name <EOL> self . name = name <EOL> self . stack = [ <EOL> ET . Element ( <EOL> "<STR_LIT>" , <EOL> name = name , filename = self . filename <EOL> ) <EOL> ] <EOL> self . indent = <NUM_LIT:0> <EOL> self . scope = [ ] <EOL> self . handler = self . look_for_encoding <EOL> self . encoding = ENCODING <EOL> def parse ( self , docstring = <NUM_LIT:0> ) : <EOL> if self . file is None : <EOL> file = open ( self . filename ) <EOL> else : <EOL> file = self . file <EOL> try : <EOL> tokenize . tokenize ( file . readline , self . handle_token ) <EOL> except tokenize . TokenError , v : <EOL> message , lineno = v <EOL> self . warning ( lineno , "<STR_LIT>" , message ) <EOL> if len ( self . stack ) != <NUM_LIT:1> : <EOL> pass <EOL> tree = self . stack [ <NUM_LIT:0> ] <EOL> elems = { } <EOL> for elem in tree . getiterator ( ) : <EOL> name = elem . get ( "<STR_LIT:name>" ) <EOL> if name : <EOL> elems [ name ] = elem <EOL> for elem in tree . getiterator ( "<STR_LIT:a>" ) : <EOL> href = elem . get ( "<STR_LIT>" ) <EOL> if href [ : <NUM_LIT:5> ] == "<STR_LIT>" : <EOL> href = href [ <NUM_LIT:5> : ] <EOL> if href [ : <NUM_LIT:1> ] == "<STR_LIT:#>" : <EOL> href = href [ <NUM_LIT:1> : ] <EOL> target = elems . get ( self . name + "<STR_LIT:.>" + href ) <EOL> if target : <EOL> href = "<STR_LIT:#>" + target . get ( "<STR_LIT:name>" ) + "<STR_LIT:->" + target . tag <EOL> elem . set ( "<STR_LIT>" , href ) <EOL> if docstring : <EOL> for info in tree . getiterator ( "<STR_LIT:info>" ) : <EOL> docstring = info . findtext ( "<STR_LIT>" ) <EOL> if not docstring : <EOL> continue <EOL> comment = docstring . split ( "<STR_LIT:\n>" ) <EOL> newinfo = parsecomment ( self , <NUM_LIT:0> , comment , dedent = <NUM_LIT:1> ) <EOL> for elem in info : <EOL> if newinfo . find ( elem . tag ) is None : <EOL> newinfo . append ( elem ) <EOL> info [ : ] = newinfo <EOL> return tree <EOL> def warning ( self , position , format , * args ) : <EOL> line , column = position <EOL> message = "<STR_LIT>" % ( self . filename , line , format % args ) <EOL> sys . stderr . write ( message ) <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> def handle_token ( self , * args ) : <EOL> if DEBUG > <NUM_LIT:1> : <EOL> print self . handler . im_func . func_name , self . indent , <EOL> print tokenize . tok_name [ args [ <NUM_LIT:0> ] ] , repr ( args [ <NUM_LIT:1> ] ) <EOL> if args [ <NUM_LIT:0> ] == tokenize . DEDENT : <EOL> self . indent = self . indent - <NUM_LIT:1> <EOL> while self . scope and self . scope [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] >= self . indent : <EOL> del self . scope [ - <NUM_LIT:1> ] <EOL> del self . stack [ - <NUM_LIT:1> ] <EOL> self . handler = apply ( self . handler , args ) <EOL> if args [ <NUM_LIT:0> ] == tokenize . INDENT : <EOL> self . indent = self . indent + <NUM_LIT:1> <EOL> def look_for_encoding ( self , type , token , start , end , line ) : <EOL> if type == tokenize . COMMENT : <EOL> if string . rstrip ( token ) == "<STR_LIT>" : <EOL> return self . look_for_pythondoc ( type , token , start , end , line ) <EOL> m = re . search ( "<STR_LIT>" , token ) <EOL> if m : <EOL> self . encoding = m . group ( <NUM_LIT:1> ) <EOL> return self . look_for_pythondoc <EOL> if start [ <NUM_LIT:0> ] > <NUM_LIT:2> : <EOL> return self . look_for_pythondoc <EOL> return self . look_for_encoding <EOL> def look_for_pythondoc ( self , type , token , start , end , line ) : <EOL> if type == tokenize . COMMENT and string . rstrip ( token ) == "<STR_LIT>" : <EOL> self . comment_start = start <EOL> self . comment = [ ] <EOL> return self . process_comment_body <EOL> else : <EOL> if token == "<STR_LIT>" or token == "<STR_LIT:class>" : <EOL> self . subject_indent = self . indent <EOL> self . subject_parens = <NUM_LIT:0> <EOL> self . subject_start = self . comment_start = None <EOL> self . subject = [ ] <EOL> return self . process_subject ( type , token , start , end , line ) <EOL> return self . look_for_pythondoc <EOL> def process_comment_body ( self , type , token , start , end , line ) : <EOL> if type == tokenize . COMMENT : <EOL> if start [ <NUM_LIT:1> ] != self . comment_start [ <NUM_LIT:1> ] : <EOL> self . warning ( <EOL> start , <EOL> "<STR_LIT>" <EOL> ) <EOL> line = string . rstrip ( token ) <EOL> if line == "<STR_LIT>" : <EOL> if self . stack [ <NUM_LIT:0> ] . find ( "<STR_LIT:info>" ) is not None : <EOL> self . warning ( <EOL> self . comment_start , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . process_subject_info ( None , self . stack [ <NUM_LIT:0> ] ) <EOL> return self . look_for_pythondoc <EOL> elif line [ : <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> line = line [ <NUM_LIT:2> : ] <EOL> elif line [ : <NUM_LIT:1> ] == "<STR_LIT:#>" : <EOL> line = line [ <NUM_LIT:1> : ] <EOL> self . comment . append ( line ) <EOL> else : <EOL> if not self . comment : <EOL> self . warning ( <EOL> self . comment_start , <EOL> "<STR_LIT>" <EOL> ) <EOL> return self . look_for_pythondoc <EOL> self . subject_start = None <EOL> self . subject = [ ] <EOL> if type != tokenize . NL : <EOL> return self . process_subject ( type , token , start , end , line ) <EOL> return self . process_subject <EOL> return self . process_comment_body <EOL> def process_subject ( self , type , token , start , end , line ) : <EOL> if self . subject : <EOL> definition = self . subject [ <NUM_LIT:0> ] in ( "<STR_LIT>" , "<STR_LIT:class>" ) <EOL> if definition : <EOL> if type not in WHITESPACE_TOKEN : <EOL> if token == "<STR_LIT:(>" : <EOL> self . subject_parens = self . subject_parens + <NUM_LIT:1> <EOL> elif token == "<STR_LIT:)>" : <EOL> self . subject_parens = self . subject_parens - <NUM_LIT:1> <EOL> if self . subject_parens or token != "<STR_LIT::>" : <EOL> self . subject . append ( token ) <EOL> return self . process_subject <EOL> else : <EOL> if token != "<STR_LIT:=>" : <EOL> self . warning ( <EOL> self . subject_start , <EOL> "<STR_LIT>" , <EOL> repr ( self . subject [ <NUM_LIT:0> ] ) <EOL> ) <EOL> return self . look_for_pythondoc ( <EOL> type , token , start , end , line <EOL> ) <EOL> else : <EOL> if type in WHITESPACE_TOKEN : <EOL> return self . process_subject <EOL> if type == tokenize . COMMENT : <EOL> self . warning ( <EOL> start , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" <EOL> ) <EOL> return self . look_for_pythondoc ( <EOL> type , token , start , end , line <EOL> ) <EOL> if token == "<STR_LIT:@>" : <EOL> self . decorator_parens = <NUM_LIT:0> <EOL> return self . skip_decorator <EOL> self . subject_start = start <EOL> self . subject . append ( token ) <EOL> if token in ( "<STR_LIT>" , "<STR_LIT:class>" ) : <EOL> while self . scope and self . scope [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] >= self . indent : <EOL> self . scope . pop ( ) <EOL> self . stack . pop ( ) <EOL> self . subject_indent = self . indent <EOL> self . subject_parens = <NUM_LIT:0> <EOL> return self . process_subject <EOL> method = self . scope and self . scope [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] == "<STR_LIT:class>" <EOL> name = [ self . name ] <EOL> for s in self . scope : <EOL> name . append ( s [ <NUM_LIT:2> ] ) <EOL> if definition : <EOL> name . append ( self . subject [ <NUM_LIT:1> ] ) <EOL> else : <EOL> name . append ( self . subject [ <NUM_LIT:0> ] ) <EOL> statement = [ ] <EOL> for part in self . subject : <EOL> if part in ( "<STR_LIT:class>" , "<STR_LIT>" ) : <EOL> continue <EOL> statement . append ( part ) <EOL> if part == "<STR_LIT:U+002C>" : <EOL> statement . append ( "<STR_LIT:U+0020>" ) <EOL> if self . subject [ <NUM_LIT:0> ] == "<STR_LIT>" and method : <EOL> del statement [ <NUM_LIT:2> : min ( <NUM_LIT:5> , len ( statement ) - <NUM_LIT:1> ) ] <EOL> statement = string . join ( statement , "<STR_LIT>" ) <EOL> if self . subject [ <NUM_LIT:0> ] == "<STR_LIT:class>" : <EOL> subject_elem = ET . Element ( "<STR_LIT:class>" ) <EOL> elif self . subject [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> if method : <EOL> subject_elem = ET . Element ( "<STR_LIT>" ) <EOL> else : <EOL> subject_elem = ET . Element ( "<STR_LIT>" ) <EOL> else : <EOL> subject_elem = ET . Element ( "<STR_LIT>" ) <EOL> self . stack [ - <NUM_LIT:1> ] . append ( subject_elem ) <EOL> if definition : <EOL> self . scope . append ( ( self . subject_indent , ) + tuple ( self . subject ) ) <EOL> self . stack . append ( subject_elem ) <EOL> subject_info = self . process_subject_info ( name , subject_elem ) <EOL> elem = ET . Element ( "<STR_LIT:name>" ) <EOL> elem . text = name [ - <NUM_LIT:1> ] <EOL> subject_info . insert ( <NUM_LIT:0> , elem ) <EOL> name = string . join ( name , "<STR_LIT:.>" ) <EOL> subject_elem . set ( "<STR_LIT:name>" , name ) <EOL> subject_elem . set ( "<STR_LIT>" , str ( self . subject_start [ <NUM_LIT:0> ] ) ) <EOL> if subject_info . find ( "<STR_LIT>" ) is None and statement : <EOL> elem = ET . Element ( "<STR_LIT>" ) <EOL> elem . text = statement <EOL> subject_info . insert ( <NUM_LIT:0> , elem ) <EOL> if definition : <EOL> return self . look_for_docstring ( type , token , start , end , line ) <EOL> else : <EOL> return self . look_for_pythondoc ( type , token , start , end , line ) <EOL> def skip_decorator ( self , type , token , start , end , line ) : <EOL> if token == "<STR_LIT:(>" : <EOL> self . decorator_parens = self . decorator_parens + <NUM_LIT:1> <EOL> elif token == "<STR_LIT:)>" : <EOL> self . decorator_parens = self . decorator_parens - <NUM_LIT:1> <EOL> if self . decorator_parens or type != tokenize . NEWLINE : <EOL> return self . skip_decorator <EOL> return self . process_subject <EOL> def process_subject_info ( self , subject_name , subject_elem ) : <EOL> if self . comment_start : <EOL> subject_info = parsecomment ( <EOL> self , self . comment_start [ <NUM_LIT:0> ] , self . comment <EOL> ) <EOL> else : <EOL> subject_info = ET . Element ( "<STR_LIT:info>" ) <EOL> subject_elem . append ( subject_info ) <EOL> if DEBUG : <EOL> if subject_name : <EOL> subject_name = string . join ( subject_name , "<STR_LIT:.>" ) <EOL> else : <EOL> subject_name = "<STR_LIT>" <EOL> print "<STR_LIT>" , subject_name <EOL> prefix = "<STR_LIT:U+0020>" * len ( self . scope ) <EOL> for line in self . comment : <EOL> print prefix + line <EOL> return subject_info <EOL> def look_for_docstring ( self , type , token , start , end , line ) : <EOL> if type in WHITESPACE_TOKEN or token == "<STR_LIT::>" : <EOL> return self . look_for_docstring <EOL> if type == tokenize . STRING : <EOL> subject_elem = self . stack [ - <NUM_LIT:1> ] <EOL> subject_info = subject_elem . find ( "<STR_LIT:info>" ) <EOL> if subject_info is not None : <EOL> elem = ET . SubElement ( subject_info , "<STR_LIT>" ) <EOL> elem . text = eval ( token ) <EOL> return self . skip_subject_body ( type , token , start , end , line ) <EOL> def skip_subject_body ( self , type , token , start , end , line ) : <EOL> return self . look_for_pythondoc ( type , token , start , end , line ) <EOL> def parse ( file , prefix = None , docstring = <NUM_LIT:0> ) : <EOL> m = ModuleParser ( file , prefix ) <EOL> return m . parse ( docstring = docstring ) <EOL> if sys . version [ : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> _escape = re . compile ( r"<STR_LIT>" ) <EOL> else : <EOL> _escape = re . compile ( eval ( r'<STR_LIT>' ) ) <EOL> _escape_map = { <EOL> "<STR_LIT:&>" : "<STR_LIT>" , <EOL> "<STR_LIT:<>" : "<STR_LIT>" , <EOL> "<STR_LIT:>>" : "<STR_LIT>" , <EOL> '<STR_LIT:">' : "<STR_LIT>" , <EOL> } <EOL> def html_encode ( text , pattern = _escape ) : <EOL> if not text : <EOL> return "<STR_LIT>" <EOL> def escape_entities ( m , map = _escape_map ) : <EOL> char = m . group ( ) <EOL> text = map . get ( char ) <EOL> if text is None : <EOL> text = "<STR_LIT>" % ord ( char ) <EOL> return text <EOL> text = pattern . sub ( escape_entities , text ) <EOL> try : <EOL> return text . encode ( "<STR_LIT:ascii>" ) <EOL> except AttributeError : <EOL> return text <EOL> class CompactHTML : <EOL> def __init__ ( self , options = None ) : <EOL> self . options = options or { } <EOL> def writetext ( self , elem , compact = <NUM_LIT:0> ) : <EOL> if len ( elem ) : <EOL> if compact and len ( elem ) == <NUM_LIT:1> and elem [ <NUM_LIT:0> ] . tag == "<STR_LIT:p>" : <EOL> elem = elem [ <NUM_LIT:0> ] <EOL> self . file . write ( html_encode ( elem . text ) ) <EOL> for e in elem : <EOL> ET . ElementTree ( e ) . write ( self . file ) <EOL> self . file . write ( html_encode ( elem . tail ) ) <EOL> else : <EOL> for e in elem : <EOL> ET . ElementTree ( e ) . write ( self . file ) <EOL> elif elem is not None and elem . text : <EOL> if compact : <EOL> self . file . write ( html_encode ( elem . text ) ) <EOL> else : <EOL> self . file . write ( "<STR_LIT>" % html_encode ( elem . text ) ) <EOL> def writeobject ( self , object , summary = <NUM_LIT:0> ) : <EOL> name = object . get ( "<STR_LIT:name>" ) <EOL> info = object . find ( "<STR_LIT:info>" ) <EOL> localname = string . split ( name , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] <EOL> define = info . findtext ( "<STR_LIT>" ) <EOL> anchor = html_encode ( name + "<STR_LIT:->" + object . tag ) <EOL> if object . tag == "<STR_LIT:class>" : <EOL> for obj in object : <EOL> if obj . get ( "<STR_LIT:name>" ) == name + "<STR_LIT>" : <EOL> inf = obj . find ( "<STR_LIT:info>" ) <EOL> define = string . split ( inf . findtext ( "<STR_LIT>" ) , "<STR_LIT:(>" , <NUM_LIT:1> ) <EOL> define = localname + "<STR_LIT:(>" + define [ <NUM_LIT:1> ] <EOL> self . file . write ( <EOL> "<STR_LIT>" % html_encode ( define ) <EOL> ) <EOL> break <EOL> else : <EOL> self . file . write ( <EOL> "<STR_LIT>" % html_encode ( localname ) <EOL> ) <EOL> elif object . tag == "<STR_LIT>" : <EOL> self . file . write ( <EOL> "<STR_LIT>" % ( <EOL> anchor , anchor , html_encode ( localname ) <EOL> ) <EOL> ) <EOL> else : <EOL> self . file . write ( <EOL> "<STR_LIT>" % ( <EOL> anchor , anchor , html_encode ( define ) <EOL> ) <EOL> ) <EOL> if object . tag == "<STR_LIT>" or object . tag == "<STR_LIT>" : <EOL> defreturn = info . find ( "<STR_LIT>" ) <EOL> if defreturn is not None : <EOL> defreturn = flatten ( defreturn ) <EOL> self . file . write ( "<STR_LIT>" % html_encode ( defreturn ) ) <EOL> self . file . write ( "<STR_LIT>" % anchor ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> if summary : <EOL> text = info . findtext ( "<STR_LIT>" ) <EOL> if text : <EOL> self . file . write ( "<STR_LIT>" % html_encode ( text ) ) <EOL> else : <EOL> self . writetext ( info . find ( "<STR_LIT:description>" ) ) <EOL> param = info . findall ( "<STR_LIT>" ) <EOL> keyparam = info . findall ( "<STR_LIT>" ) <EOL> exception = info . findall ( "<STR_LIT>" ) <EOL> return_elem = info . find ( "<STR_LIT>" ) <EOL> if param or keyparam or exception or return_elem != None : <EOL> self . file . write ( "<STR_LIT>" ) <EOL> for p in param + keyparam : <EOL> name = p . get ( "<STR_LIT:name>" ) <EOL> if p . tag == "<STR_LIT>" : <EOL> name = name + "<STR_LIT:=>" <EOL> self . file . write ( "<STR_LIT>" % html_encode ( name ) ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . writetext ( p , compact = <NUM_LIT:1> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> if return_elem is not None : <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . writetext ( return_elem , compact = <NUM_LIT:1> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> for e in exception : <EOL> name = html_encode ( e . get ( "<STR_LIT:name>" ) ) <EOL> self . file . write ( "<STR_LIT>" % name ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . writetext ( e , compact = <NUM_LIT:1> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> if object . tag == "<STR_LIT:class>" and summary : <EOL> self . file . write ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> anchor , localname <EOL> ) <EOL> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> def save ( self , module , file ) : <EOL> title = "<STR_LIT>" % module . get ( "<STR_LIT:name>" ) <EOL> zone = self . options . has_key ( "<STR_LIT>" ) <EOL> if zone : <EOL> filename = joinext ( file , "<STR_LIT>" ) <EOL> else : <EOL> filename = joinext ( file , "<STR_LIT>" ) <EOL> self . file = open ( filename , "<STR_LIT:w>" ) <EOL> if zone : <EOL> self . file . write ( title + "<STR_LIT>" ) <EOL> else : <EOL> self . file . write ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . file . write ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> self . file . write ( "<STR_LIT>" % html_encode ( title ) ) <EOL> try : <EOL> style = self . options [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> self . file . write ( <EOL> "<STR_LIT>" % <EOL> html_encode ( style ) <EOL> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . file . write ( "<STR_LIT>" % title ) <EOL> info = module . find ( "<STR_LIT:info>" ) <EOL> if info is not None : <EOL> self . writetext ( info . find ( "<STR_LIT:description>" ) ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> objects = [ ] <EOL> for object in module : <EOL> info = object . find ( "<STR_LIT:info>" ) <EOL> if info is None or info . find ( "<STR_LIT:description>" ) is None : <EOL> continue <EOL> if object . tag in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:class>" ) : <EOL> objects . append ( object ) <EOL> objects . sort ( lambda a , b : cmp ( <EOL> string . lower ( string . split ( a . get ( "<STR_LIT:name>" ) , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) , <EOL> string . lower ( string . split ( b . get ( "<STR_LIT:name>" ) , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) <EOL> ) ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> for object in objects : <EOL> self . writeobject ( object , object . tag == "<STR_LIT:class>" ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> for object in objects : <EOL> if object . tag != "<STR_LIT:class>" : <EOL> continue <EOL> name = object . get ( "<STR_LIT:name>" ) <EOL> localname = string . split ( name , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] <EOL> anchor = name + "<STR_LIT>" <EOL> self . file . write ( <EOL> "<STR_LIT>" % ( <EOL> anchor , anchor , localname <EOL> ) <EOL> ) <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . writeobject ( object ) <EOL> objects = [ ] <EOL> for object in object : <EOL> info = object . find ( "<STR_LIT:info>" ) <EOL> if info is None or info . find ( "<STR_LIT:description>" ) is None : <EOL> continue <EOL> if object . tag not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> continue <EOL> objects . append ( object ) <EOL> objects . sort ( lambda a , b : cmp ( <EOL> string . lower ( string . split ( a . get ( "<STR_LIT:name>" ) , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) , <EOL> string . lower ( string . split ( b . get ( "<STR_LIT:name>" ) , "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) <EOL> ) ) <EOL> for object in objects : <EOL> if object . tag == "<STR_LIT>" : <EOL> object . tag = "<STR_LIT>" <EOL> self . writeobject ( object ) <EOL> if object . tag == "<STR_LIT>" : <EOL> object . tag = "<STR_LIT>" <EOL> self . file . write ( "<STR_LIT>" ) <EOL> if not zone : <EOL> self . file . write ( "<STR_LIT>" ) <EOL> self . file . close ( ) <EOL> self . file = None <EOL> return filename <EOL> def usage ( ) : <EOL> print "<STR_LIT>" , VERSION , COPYRIGHT <EOL> print <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import getopt <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , "<STR_LIT>" ) <EOL> except getopt . error : <EOL> usage ( ) <EOL> force = <NUM_LIT:0> <EOL> prefix = None <EOL> docstring = <NUM_LIT:0> <EOL> output_xml = <NUM_LIT:0> <EOL> output_handler = CompactHTML <EOL> output_options = { } <EOL> for k , v in opts : <EOL> if k == "<STR_LIT>" : <EOL> force = <NUM_LIT:1> <EOL> elif k == "<STR_LIT>" : <EOL> prefix = v <EOL> elif k == "<STR_LIT>" : <EOL> docstring = <NUM_LIT:1> <EOL> elif k == "<STR_LIT>" : <EOL> output_xml = <NUM_LIT:1> <EOL> elif k == "<STR_LIT>" : <EOL> try : <EOL> m = __import__ ( v ) <EOL> for k in string . split ( v , "<STR_LIT:.>" ) [ <NUM_LIT:1> : ] : <EOL> m = getattr ( m , k ) <EOL> output_handler = getattr ( m , "<STR_LIT>" ) <EOL> except ( ImportError , AttributeError ) : <EOL> print "<STR_LIT>" , repr ( v ) , "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif k == "<STR_LIT>" : <EOL> try : <EOL> k , v = string . split ( v , "<STR_LIT:=>" , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> k = v ; v = None <EOL> output_options [ k ] = v <EOL> elif k == "<STR_LIT>" : <EOL> DEBUG = DEBUG + <NUM_LIT:1> <EOL> if not args : <EOL> usage ( ) <EOL> output_handler = output_handler ( output_options ) <EOL> try : <EOL> TAGS = TAGS + output_handler . tags <EOL> except AttributeError : <EOL> pass <EOL> import time <EOL> t0 = time . time ( ) <EOL> input = output = <NUM_LIT:0> <EOL> for filename in args : <EOL> this_prefix = prefix <EOL> if os . path . isdir ( filename ) : <EOL> files = glob . glob ( os . path . join ( filename , joinext ( "<STR_LIT:*>" , "<STR_LIT>" ) ) ) <EOL> if not this_prefix : <EOL> this_prefix = os . path . basename ( filename ) <EOL> else : <EOL> if sys . platform == "<STR_LIT:win32>" and glob . has_magic ( filename ) : <EOL> files = glob . glob ( filename ) <EOL> else : <EOL> files = [ filename ] <EOL> files . sort ( ) <EOL> for file in files : <EOL> try : <EOL> module = parse ( file , this_prefix , docstring = docstring ) <EOL> except IOError , v : <EOL> sys . stderr . write ( "<STR_LIT>" % ( file , v [ <NUM_LIT:1> ] ) ) <EOL> continue <EOL> input = input + <NUM_LIT:1> <EOL> if not force : <EOL> for n in module : <EOL> i = n . find ( "<STR_LIT:info>" ) <EOL> if i and i . find ( "<STR_LIT:description>" ) is not None : <EOL> break <EOL> else : <EOL> continue <EOL> f = "<STR_LIT>" + string . replace ( module . get ( "<STR_LIT:name>" ) , "<STR_LIT:.>" , EXTSEP ) <EOL> if output_xml : <EOL> filename = joinext ( f , "<STR_LIT>" ) <EOL> try : <EOL> out = open ( filename , "<STR_LIT:w>" ) <EOL> ET . ElementTree ( module ) . write ( out ) <EOL> out . close ( ) <EOL> except IOError , v : <EOL> sys . stderr . write ( "<STR_LIT>" % ( filename , v [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" % filename ) <EOL> try : <EOL> out = output_handler . save ( module , f ) <EOL> except IOError , v : <EOL> sys . stderr . write ( "<STR_LIT>" % ( file , v [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> if out : <EOL> sys . stderr . write ( "<STR_LIT>" % out ) <EOL> output = output + <NUM_LIT:1> <EOL> try : <EOL> done = output_handler . done <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> out = output_handler . done ( ) <EOL> if out : <EOL> sys . stderr . write ( "<STR_LIT>" % out ) <EOL> if DEBUG : <EOL> sys . stderr . write ( <EOL> "<STR_LIT>" % ( <EOL> input , output , time . time ( ) - t0 <EOL> ) ) </s>
