<s> '''<STR_LIT>''' <EOL> import sys <EOL> from urllib import urlopen as _open <EOL> from BeautifulSoup import BeautifulSoup <EOL> from htmlentitydefs import codepoint2name <EOL> def uni2html ( u ) : <EOL> '''<STR_LIT>''' <EOL> htmlentities = list ( ) <EOL> for c in u : <EOL> ord_c = ord ( c ) <EOL> if ord_c < <NUM_LIT> : <EOL> if ord_c > <NUM_LIT> : <EOL> htmlentities . append ( c ) <EOL> else : <EOL> try : <EOL> htmlentities . append ( '<STR_LIT>' % codepoint2name [ ord_c ] ) <EOL> except KeyError : <EOL> pass <EOL> return '<STR_LIT>' . join ( htmlentities ) <EOL> def print_fw ( iterable , joins = '<STR_LIT:U+002CU+0020>' , prefix = '<STR_LIT>' , indent = <NUM_LIT:0> , width = <NUM_LIT> , trail = False ) : <EOL> '''<STR_LIT>''' <EOL> shift_width = <NUM_LIT:4> <EOL> preline = '<STR_LIT>' % ( '<STR_LIT:U+0020>' * shift_width , prefix ) <EOL> linew = len ( preline ) <EOL> sys . stdout . write ( preline ) <EOL> for i , entry in enumerate ( iterable ) : <EOL> if not trail and i == len ( iterable ) - <NUM_LIT:1> : <EOL> sentry = str ( entry ) <EOL> else : <EOL> sentry = '<STR_LIT>' % ( str ( entry ) , joins ) <EOL> if linew + len ( sentry ) > width : <EOL> sys . stdout . write ( '<STR_LIT>' % ( preline ) ) <EOL> linew = len ( preline ) <EOL> sys . stdout . write ( sentry ) <EOL> linew += len ( sentry ) <EOL> sys . stdout . write ( '<STR_LIT:\n>' ) <EOL> def main_with_options ( options , files ) : <EOL> '''<STR_LIT>''' <EOL> apifile = _open ( '<STR_LIT>' ) <EOL> try : <EOL> apihtml = uni2html ( apifile . read ( ) ) <EOL> finally : <EOL> apifile . close ( ) <EOL> apidoc = BeautifulSoup ( apihtml ) <EOL> toc = apidoc . find ( '<STR_LIT>' , { '<STR_LIT:class>' : '<STR_LIT>' } ) <EOL> toc_entries = toc . findAll ( '<STR_LIT>' , text = lambda text : '<STR_LIT>' in text ) <EOL> method_links = { } <EOL> for entry in toc_entries : <EOL> links = entry . parent . parent . findAll ( '<STR_LIT:a>' ) <EOL> method_links [ links [ <NUM_LIT:0> ] . string ] = [ x [ '<STR_LIT>' ] for x in links [ <NUM_LIT:1> : ] ] <EOL> POST_ACTION_HASH = { } <EOL> for method_type , methods in method_links . items ( ) : <EOL> for method in methods : <EOL> method = method [ <NUM_LIT:1> : ] <EOL> method_body = apidoc . find ( '<STR_LIT:a>' , { '<STR_LIT:name>' : method } ) <EOL> value = list ( method_body . findNext ( <EOL> '<STR_LIT:b>' , text = lambda text : '<STR_LIT>' in text <EOL> ) . parent . parent . childGenerator ( ) ) [ - <NUM_LIT:1> ] <EOL> if '<STR_LIT:POST>' in value : <EOL> method_name = method_body . findNext ( '<STR_LIT>' ) . string <EOL> try : <EOL> POST_ACTION_HASH [ method_name ] += ( method_type , ) <EOL> except KeyError : <EOL> POST_ACTION_HASH [ method_name ] = ( method_type , ) <EOL> POST_ACTION_HASH_R = { } <EOL> for method , method_types in POST_ACTION_HASH . items ( ) : <EOL> try : <EOL> POST_ACTION_HASH_R [ method_types ] . append ( method ) <EOL> except KeyError : <EOL> POST_ACTION_HASH_R [ method_types ] = [ method ] <EOL> print """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> for method_types , methods in POST_ACTION_HASH_R . items ( ) : <EOL> print_fw ( method_types , prefix = '<STR_LIT>' , indent = <NUM_LIT:1> ) <EOL> print_fw ( [ repr ( str ( x ) ) for x in methods ] , indent = <NUM_LIT:1> , trail = True ) <EOL> print "<STR_LIT>" <EOL> print '<STR_LIT:]>' <EOL> def main ( ) : <EOL> import optparse <EOL> class CustomFormatter ( optparse . IndentedHelpFormatter ) : <EOL> """<STR_LIT>""" <EOL> def format_description ( self , description ) : <EOL> '''<STR_LIT>''' <EOL> return "<STR_LIT:\n>" . join ( [ <EOL> "<STR_LIT>" % ( "<STR_LIT:U+0020>" * ( ( self . level + <NUM_LIT:1> ) * self . indent_increment ) , line ) <EOL> for line in description . splitlines ( ) <EOL> ] ) + "<STR_LIT:\n>" <EOL> parser = optparse . OptionParser ( <EOL> formatter = CustomFormatter ( ) , <EOL> description = __doc__ <EOL> ) <EOL> ( options , files ) = parser . parse_args ( ) <EOL> main_with_options ( options , files ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
