<s> from input_algorithms . many_item_spec import many_item_formatted_spec <EOL> from harpoon . option_spec . harpoon_specs import HarpoonSpec <EOL> from input_algorithms import spec_base as sb <EOL> from docutils . statemachine import ViewList <EOL> from sphinx . util . compat import Directive <EOL> from textwrap import dedent <EOL> from docutils import nodes <EOL> import six <EOL> class ShowSpecsDirective ( Directive ) : <EOL> """<STR_LIT>""" <EOL> has_content = True <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> tokens = [ ] <EOL> for name , spec in ( ( "<STR_LIT>" , HarpoonSpec ( ) . harpoon_spec ) , ( "<STR_LIT>" , HarpoonSpec ( ) . image_spec ) ) : <EOL> section = nodes . section ( ) <EOL> section [ '<STR_LIT>' ] . append ( name ) <EOL> section [ '<STR_LIT>' ] . append ( name ) <EOL> header = nodes . title ( ) <EOL> header += nodes . Text ( name ) <EOL> section . append ( header ) <EOL> section . extend ( self . nodes_for_spec ( spec ) ) <EOL> tokens . append ( section ) <EOL> return tokens <EOL> def nodes_for_signature ( self , spec , para ) : <EOL> tokens = [ ] <EOL> if isinstance ( spec , sb . create_spec ) : <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> elif isinstance ( spec , sb . optional_spec ) : <EOL> colord = nodes . inline ( classes = [ '<STR_LIT>' ] ) <EOL> emphasis = nodes . emphasis ( ) <EOL> emphasis += nodes . Text ( "<STR_LIT>" ) <EOL> colord += emphasis <EOL> para += colord <EOL> self . nodes_for_signature ( spec . spec , para ) <EOL> elif isinstance ( spec , sb . defaulted ) : <EOL> colord = nodes . inline ( classes = [ '<STR_LIT>' ] ) <EOL> emphasis = nodes . emphasis ( ) <EOL> dflt = spec . default ( None ) <EOL> if isinstance ( dflt , six . string_types ) : <EOL> dflt = '<STR_LIT>' . format ( dflt ) <EOL> emphasis += nodes . Text ( "<STR_LIT>" . format ( dflt ) ) <EOL> colord += emphasis <EOL> para += colord <EOL> self . nodes_for_signature ( spec . spec , para ) <EOL> elif isinstance ( spec , sb . required ) : <EOL> colord = nodes . inline ( classes = [ '<STR_LIT>' ] ) <EOL> strong = nodes . strong ( ) <EOL> strong += nodes . Text ( "<STR_LIT>" ) <EOL> colord += strong <EOL> para += colord <EOL> self . nodes_for_signature ( spec . spec , para ) <EOL> elif isinstance ( spec , sb . listof ) : <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> self . nodes_for_signature ( spec . spec , para ) <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> elif isinstance ( spec , sb . dictof ) : <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> self . nodes_for_signature ( spec . name_spec , para ) <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> self . nodes_for_signature ( spec . value_spec , para ) <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> elif isinstance ( spec , many_item_formatted_spec ) : <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> for i , s in enumerate ( spec . specs ) : <EOL> self . nodes_for_signature ( s , para ) <EOL> if i < len ( spec . specs ) - <NUM_LIT:1> or spec . optional_specs : <EOL> para += nodes . Text ( '<STR_LIT:U+002CU+0020>' ) <EOL> if spec . optional_specs : <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> for i , s in enumerate ( spec . optional_specs ) : <EOL> self . nodes_for_signature ( s , para ) <EOL> if i < len ( spec . specs ) - <NUM_LIT:1> : <EOL> para += nodes . Text ( '<STR_LIT:U+002CU+0020>' ) <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> para += nodes . Text ( "<STR_LIT>" ) <EOL> elif isinstance ( spec , ( sb . container_spec , sb . formatted ) ) : <EOL> self . nodes_for_signature ( spec . spec , para ) <EOL> elif isinstance ( spec , sb . overridden ) : <EOL> para += nodes . Text ( '<STR_LIT>' . format ( spec . value ) ) <EOL> else : <EOL> spec_name = spec . __class__ . __name__ <EOL> if spec_name . endswith ( "<STR_LIT>" ) : <EOL> spec_name = spec_name [ : - <NUM_LIT:5> ] <EOL> para += nodes . Text ( spec_name ) <EOL> return tokens <EOL> def nodes_for_spec ( self , spec ) : <EOL> """<STR_LIT>""" <EOL> tokens = [ ] <EOL> if isinstance ( spec , sb . create_spec ) : <EOL> container = nodes . container ( classes = [ "<STR_LIT>" ] ) <EOL> creates = spec . kls <EOL> for name , option in sorted ( spec . kwargs . items ( ) , key = lambda x : len ( x [ <NUM_LIT:0> ] ) ) : <EOL> para = nodes . paragraph ( classes = [ "<STR_LIT>" ] ) <EOL> para += nodes . Text ( "<STR_LIT>" . format ( name ) ) <EOL> self . nodes_for_signature ( option , para ) <EOL> fields = { } <EOL> if creates and hasattr ( creates , '<STR_LIT>' ) and isinstance ( creates . fields , dict ) : <EOL> for key , val in creates . fields . items ( ) : <EOL> if isinstance ( key , tuple ) : <EOL> fields [ key [ <NUM_LIT:0> ] ] = val <EOL> else : <EOL> fields [ key ] = val <EOL> txt = fields . get ( name ) or "<STR_LIT>" <EOL> viewlist = ViewList ( ) <EOL> for line in dedent ( txt ) . split ( '<STR_LIT:\n>' ) : <EOL> viewlist . append ( line , name ) <EOL> desc = nodes . section ( classes = [ "<STR_LIT>" ] ) <EOL> self . state . nested_parse ( viewlist , self . content_offset , desc ) <EOL> container += para <EOL> container += desc <EOL> container . extend ( self . nodes_for_spec ( option ) ) <EOL> tokens . append ( container ) <EOL> elif isinstance ( spec , sb . optional_spec ) : <EOL> tokens . extend ( self . nodes_for_spec ( spec . spec ) ) <EOL> elif isinstance ( spec , sb . container_spec ) : <EOL> tokens . extend ( self . nodes_for_spec ( spec . spec ) ) <EOL> elif isinstance ( spec , sb . dictof ) : <EOL> tokens . extend ( self . nodes_for_spec ( spec . value_spec ) ) <EOL> return tokens <EOL> def setup ( app ) : <EOL> """<STR_LIT>""" <EOL> app . add_directive ( '<STR_LIT>' , ShowSpecsDirective ) </s>
