<s> """<STR_LIT>""" <EOL> import warnings <EOL> from docutils import nodes <EOL> from docutils . writers . manpage import ( <EOL> MACRO_DEF , <EOL> Writer , <EOL> Translator as BaseTranslator <EOL> ) <EOL> from sphinx import addnodes <EOL> from sphinx . locale import admonitionlabels , _ <EOL> from sphinx . util . compat import docutils_version <EOL> from sphinx . util . i18n import format_date <EOL> class ManualPageWriter ( Writer ) : <EOL> def __init__ ( self , builder ) : <EOL> Writer . __init__ ( self ) <EOL> self . builder = builder <EOL> self . translator_class = ( <EOL> self . builder . translator_class or ManualPageTranslator ) <EOL> def translate ( self ) : <EOL> transform = NestedInlineTransform ( self . document ) <EOL> transform . apply ( ) <EOL> visitor = self . translator_class ( self . builder , self . document ) <EOL> self . visitor = visitor <EOL> self . document . walkabout ( visitor ) <EOL> self . output = visitor . astext ( ) <EOL> class NestedInlineTransform ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , document ) : <EOL> self . document = document <EOL> def apply ( self ) : <EOL> def is_inline ( node ) : <EOL> return isinstance ( node , ( nodes . literal , nodes . emphasis , nodes . strong ) ) <EOL> for node in self . document . traverse ( is_inline ) : <EOL> if any ( is_inline ( subnode ) for subnode in node ) : <EOL> pos = node . parent . index ( node ) <EOL> for subnode in reversed ( node [ <NUM_LIT:1> : ] ) : <EOL> node . remove ( subnode ) <EOL> if is_inline ( subnode ) : <EOL> node . parent . insert ( pos + <NUM_LIT:1> , subnode ) <EOL> else : <EOL> newnode = node . __class__ ( '<STR_LIT>' , subnode , ** node . attributes ) <EOL> node . parent . insert ( pos + <NUM_LIT:1> , newnode ) <EOL> class ManualPageTranslator ( BaseTranslator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , builder , * args , ** kwds ) : <EOL> BaseTranslator . __init__ ( self , * args , ** kwds ) <EOL> self . builder = builder <EOL> self . in_productionlist = <NUM_LIT:0> <EOL> self . section_level = - <NUM_LIT:1> <EOL> self . _docinfo [ '<STR_LIT:title>' ] = self . document . settings . title <EOL> self . _docinfo [ '<STR_LIT>' ] = self . document . settings . subtitle <EOL> if self . document . settings . authors : <EOL> self . _docinfo [ '<STR_LIT>' ] = self . document . settings . authors <EOL> self . _docinfo [ '<STR_LIT>' ] = self . document . settings . section <EOL> self . _docinfo [ '<STR_LIT>' ] = self . _docinfo [ '<STR_LIT:title>' ] . upper ( ) <EOL> if builder . config . today : <EOL> self . _docinfo [ '<STR_LIT:date>' ] = builder . config . today <EOL> else : <EOL> self . _docinfo [ '<STR_LIT:date>' ] = format_date ( builder . config . today_fmt or _ ( '<STR_LIT>' ) , <EOL> language = builder . config . language ) <EOL> self . _docinfo [ '<STR_LIT>' ] = builder . config . copyright <EOL> self . _docinfo [ '<STR_LIT:version>' ] = builder . config . version <EOL> self . _docinfo [ '<STR_LIT>' ] = builder . config . project <EOL> if docutils_version < ( <NUM_LIT:0> , <NUM_LIT:11> ) : <EOL> self . body . append ( MACRO_DEF ) <EOL> for label , translation in admonitionlabels . items ( ) : <EOL> self . language . labels [ label ] = self . deunicode ( translation ) <EOL> def header ( self ) : <EOL> tmpl = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return tmpl % self . _docinfo <EOL> def visit_start_of_file ( self , node ) : <EOL> pass <EOL> def depart_start_of_file ( self , node ) : <EOL> pass <EOL> def visit_desc ( self , node ) : <EOL> self . visit_definition_list ( node ) <EOL> def depart_desc ( self , node ) : <EOL> self . depart_definition_list ( node ) <EOL> def visit_desc_signature ( self , node ) : <EOL> self . visit_definition_list_item ( node ) <EOL> self . visit_term ( node ) <EOL> def depart_desc_signature ( self , node ) : <EOL> self . depart_term ( node ) <EOL> def visit_desc_addname ( self , node ) : <EOL> pass <EOL> def depart_desc_addname ( self , node ) : <EOL> pass <EOL> def visit_desc_type ( self , node ) : <EOL> pass <EOL> def depart_desc_type ( self , node ) : <EOL> pass <EOL> def visit_desc_returns ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def depart_desc_returns ( self , node ) : <EOL> pass <EOL> def visit_desc_name ( self , node ) : <EOL> pass <EOL> def depart_desc_name ( self , node ) : <EOL> pass <EOL> def visit_desc_parameterlist ( self , node ) : <EOL> self . body . append ( '<STR_LIT:(>' ) <EOL> self . first_param = <NUM_LIT:1> <EOL> def depart_desc_parameterlist ( self , node ) : <EOL> self . body . append ( '<STR_LIT:)>' ) <EOL> def visit_desc_parameter ( self , node ) : <EOL> if not self . first_param : <EOL> self . body . append ( '<STR_LIT:U+002CU+0020>' ) <EOL> else : <EOL> self . first_param = <NUM_LIT:0> <EOL> def depart_desc_parameter ( self , node ) : <EOL> pass <EOL> def visit_desc_optional ( self , node ) : <EOL> self . body . append ( '<STR_LIT:[>' ) <EOL> def depart_desc_optional ( self , node ) : <EOL> self . body . append ( '<STR_LIT:]>' ) <EOL> def visit_desc_annotation ( self , node ) : <EOL> pass <EOL> def depart_desc_annotation ( self , node ) : <EOL> pass <EOL> def visit_desc_content ( self , node ) : <EOL> self . visit_definition ( node ) <EOL> def depart_desc_content ( self , node ) : <EOL> self . depart_definition ( node ) <EOL> def visit_versionmodified ( self , node ) : <EOL> self . visit_paragraph ( node ) <EOL> def depart_versionmodified ( self , node ) : <EOL> self . depart_paragraph ( node ) <EOL> def visit_term ( self , node ) : <EOL> if node . traverse ( nodes . strong ) : <EOL> self . body . append ( '<STR_LIT:\n>' ) <EOL> else : <EOL> BaseTranslator . visit_term ( self , node ) <EOL> def visit_termsep ( self , node ) : <EOL> warnings . warn ( '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> self . body . append ( '<STR_LIT:U+002CU+0020>' ) <EOL> raise nodes . SkipNode <EOL> def visit_comment ( self , node ) : <EOL> raise nodes . SkipNode <EOL> def visit_footnote ( self , node ) : <EOL> self . ensure_eol ( ) <EOL> BaseTranslator . visit_footnote ( self , node ) <EOL> def visit_rubric ( self , node ) : <EOL> self . ensure_eol ( ) <EOL> if len ( node . children ) == <NUM_LIT:1> : <EOL> rubtitle = node . children [ <NUM_LIT:0> ] . astext ( ) <EOL> if rubtitle in ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) : <EOL> self . body . append ( '<STR_LIT>' + self . deunicode ( rubtitle ) . upper ( ) + <EOL> '<STR_LIT:\n>' ) <EOL> raise nodes . SkipNode <EOL> else : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def depart_rubric ( self , node ) : <EOL> pass <EOL> def visit_seealso ( self , node ) : <EOL> self . visit_admonition ( node , '<STR_LIT>' ) <EOL> def depart_seealso ( self , node ) : <EOL> self . depart_admonition ( node ) <EOL> def visit_productionlist ( self , node ) : <EOL> self . ensure_eol ( ) <EOL> names = [ ] <EOL> self . in_productionlist += <NUM_LIT:1> <EOL> self . body . append ( '<STR_LIT>' ) <EOL> for production in node : <EOL> names . append ( production [ '<STR_LIT>' ] ) <EOL> maxlen = max ( len ( name ) for name in names ) <EOL> lastname = None <EOL> for production in node : <EOL> if production [ '<STR_LIT>' ] : <EOL> lastname = production [ '<STR_LIT>' ] . ljust ( maxlen ) <EOL> self . body . append ( self . defs [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . body . append ( self . deunicode ( lastname ) ) <EOL> self . body . append ( self . defs [ '<STR_LIT>' ] [ <NUM_LIT:1> ] ) <EOL> self . body . append ( '<STR_LIT>' ) <EOL> elif lastname is not None : <EOL> self . body . append ( '<STR_LIT>' % ( '<STR_LIT:U+0020>' * len ( lastname ) ) ) <EOL> production . walkabout ( self ) <EOL> self . body . append ( '<STR_LIT:\n>' ) <EOL> self . body . append ( '<STR_LIT>' ) <EOL> self . in_productionlist -= <NUM_LIT:1> <EOL> raise nodes . SkipNode <EOL> def visit_production ( self , node ) : <EOL> pass <EOL> def depart_production ( self , node ) : <EOL> pass <EOL> def visit_image ( self , node ) : <EOL> if '<STR_LIT>' in node . attributes : <EOL> self . body . append ( _ ( '<STR_LIT>' ) % node [ '<STR_LIT>' ] + '<STR_LIT:\n>' ) <EOL> self . body . append ( _ ( '<STR_LIT>' ) + '<STR_LIT:\n>' ) <EOL> raise nodes . SkipNode <EOL> def visit_reference ( self , node ) : <EOL> self . body . append ( self . defs [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . visit_Text ( node ) <EOL> self . body . append ( self . defs [ '<STR_LIT>' ] [ <NUM_LIT:1> ] ) <EOL> uri = node . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if uri . startswith ( '<STR_LIT>' ) or uri . startswith ( '<STR_LIT>' ) or uri . startswith ( '<STR_LIT>' ) or uri . startswith ( '<STR_LIT>' ) : <EOL> if self . builder . config . man_show_urls and node . astext ( ) != uri : <EOL> if uri . startswith ( '<STR_LIT>' ) : <EOL> uri = uri [ <NUM_LIT:7> : ] <EOL> self . body . extend ( [ <EOL> '<STR_LIT>' , <EOL> self . defs [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , uri , self . defs [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , <EOL> '<STR_LIT:>>' ] ) <EOL> raise nodes . SkipNode <EOL> def visit_number_reference ( self , node ) : <EOL> text = nodes . Text ( node . get ( '<STR_LIT:title>' , '<STR_LIT:#>' ) ) <EOL> self . visit_Text ( text ) <EOL> raise nodes . SkipNode <EOL> def visit_centered ( self , node ) : <EOL> self . ensure_eol ( ) <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def depart_centered ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def visit_compact_paragraph ( self , node ) : <EOL> pass <EOL> def depart_compact_paragraph ( self , node ) : <EOL> pass <EOL> def visit_highlightlang ( self , node ) : <EOL> pass <EOL> def depart_highlightlang ( self , node ) : <EOL> pass <EOL> def visit_download_reference ( self , node ) : <EOL> pass <EOL> def depart_download_reference ( self , node ) : <EOL> pass <EOL> def visit_toctree ( self , node ) : <EOL> raise nodes . SkipNode <EOL> def visit_index ( self , node ) : <EOL> raise nodes . SkipNode <EOL> def visit_tabular_col_spec ( self , node ) : <EOL> raise nodes . SkipNode <EOL> def visit_glossary ( self , node ) : <EOL> pass <EOL> def depart_glossary ( self , node ) : <EOL> pass <EOL> def visit_acks ( self , node ) : <EOL> self . ensure_eol ( ) <EOL> self . body . append ( '<STR_LIT:U+002CU+0020>' . join ( n . astext ( ) <EOL> for n in node . children [ <NUM_LIT:0> ] . children ) + '<STR_LIT:.>' ) <EOL> self . body . append ( '<STR_LIT:\n>' ) <EOL> raise nodes . SkipNode <EOL> def visit_hlist ( self , node ) : <EOL> self . visit_bullet_list ( node ) <EOL> def depart_hlist ( self , node ) : <EOL> self . depart_bullet_list ( node ) <EOL> def visit_hlistcol ( self , node ) : <EOL> pass <EOL> def depart_hlistcol ( self , node ) : <EOL> pass <EOL> def visit_literal_emphasis ( self , node ) : <EOL> return self . visit_emphasis ( node ) <EOL> def depart_literal_emphasis ( self , node ) : <EOL> return self . depart_emphasis ( node ) <EOL> def visit_literal_strong ( self , node ) : <EOL> return self . visit_strong ( node ) <EOL> def depart_literal_strong ( self , node ) : <EOL> return self . depart_strong ( node ) <EOL> def visit_abbreviation ( self , node ) : <EOL> pass <EOL> def depart_abbreviation ( self , node ) : <EOL> pass <EOL> def visit_manpage ( self , node ) : <EOL> return self . visit_strong ( node ) <EOL> def depart_manpage ( self , node ) : <EOL> return self . depart_strong ( node ) <EOL> def visit_title ( self , node ) : <EOL> if isinstance ( node . parent , addnodes . seealso ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> return <EOL> elif isinstance ( node . parent , nodes . section ) : <EOL> if self . section_level == <NUM_LIT:0> : <EOL> raise nodes . SkipNode <EOL> elif self . section_level == <NUM_LIT:1> : <EOL> self . body . append ( '<STR_LIT>' % <EOL> self . deunicode ( node . astext ( ) . upper ( ) ) ) <EOL> raise nodes . SkipNode <EOL> return BaseTranslator . visit_title ( self , node ) <EOL> def depart_title ( self , node ) : <EOL> if isinstance ( node . parent , addnodes . seealso ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> return <EOL> return BaseTranslator . depart_title ( self , node ) <EOL> def visit_raw ( self , node ) : <EOL> if '<STR_LIT>' in node . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( ) : <EOL> self . body . append ( node . astext ( ) ) <EOL> raise nodes . SkipNode <EOL> def visit_meta ( self , node ) : <EOL> raise nodes . SkipNode <EOL> def visit_inline ( self , node ) : <EOL> pass <EOL> def depart_inline ( self , node ) : <EOL> pass <EOL> def visit_math ( self , node ) : <EOL> self . builder . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise nodes . SkipNode <EOL> visit_math_block = visit_math <EOL> def unknown_visit ( self , node ) : <EOL> raise NotImplementedError ( '<STR_LIT>' + node . __class__ . __name__ ) </s>
