<s> """<STR_LIT>""" <EOL> import json <EOL> import os <EOL> import re <EOL> from docutils import nodes <EOL> from docutils . parsers . rst import directives <EOL> from sphinx import addnodes <EOL> from sphinx . builders . html import StandaloneHTMLBuilder <EOL> from sphinx . domains . std import Cmdoption <EOL> from sphinx . util . compat import Directive <EOL> from sphinx . util . console import bold <EOL> from sphinx . util . nodes import set_source_info <EOL> from sphinx . writers . html import SmartyPantsHTMLTranslator <EOL> simple_option_desc_re = re . compile ( <EOL> r'<STR_LIT>' ) <EOL> def setup ( app ) : <EOL> app . add_crossref_type ( <EOL> directivename = "<STR_LIT>" , <EOL> rolename = "<STR_LIT>" , <EOL> indextemplate = "<STR_LIT>" , <EOL> ) <EOL> app . add_crossref_type ( <EOL> directivename = "<STR_LIT>" , <EOL> rolename = "<STR_LIT>" , <EOL> indextemplate = "<STR_LIT>" <EOL> ) <EOL> app . add_crossref_type ( <EOL> directivename = "<STR_LIT>" , <EOL> rolename = "<STR_LIT>" , <EOL> indextemplate = "<STR_LIT>" <EOL> ) <EOL> app . add_crossref_type ( <EOL> directivename = "<STR_LIT>" , <EOL> rolename = "<STR_LIT>" , <EOL> indextemplate = "<STR_LIT>" , <EOL> ) <EOL> app . add_description_unit ( <EOL> directivename = "<STR_LIT>" , <EOL> rolename = "<STR_LIT>" , <EOL> indextemplate = "<STR_LIT>" , <EOL> parse_node = parse_django_admin_node , <EOL> ) <EOL> app . add_directive ( '<STR_LIT>' , Cmdoption ) <EOL> app . add_config_value ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> app . add_directive ( '<STR_LIT>' , VersionDirective ) <EOL> app . add_directive ( '<STR_LIT>' , VersionDirective ) <EOL> app . add_builder ( DjangoStandaloneHTMLBuilder ) <EOL> app . add_directive ( '<STR_LIT>' , SnippetWithFilename ) <EOL> app . add_node ( snippet_with_filename , <EOL> html = ( visit_snippet , depart_snippet_literal ) , <EOL> latex = ( visit_snippet_latex , depart_snippet_latex ) , <EOL> man = ( visit_snippet_literal , depart_snippet_literal ) , <EOL> text = ( visit_snippet_literal , depart_snippet_literal ) , <EOL> texinfo = ( visit_snippet_literal , depart_snippet_literal ) ) <EOL> return { '<STR_LIT>' : True } <EOL> class snippet_with_filename ( nodes . literal_block ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def visit_snippet_literal ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . visit_literal_block ( node ) <EOL> def depart_snippet_literal ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . depart_literal_block ( node ) <EOL> def visit_snippet ( self , node ) : <EOL> """<STR_LIT>""" <EOL> lang = self . highlightlang <EOL> linenos = node . rawsource . count ( '<STR_LIT:\n>' ) >= self . highlightlinenothreshold - <NUM_LIT:1> <EOL> fname = node [ '<STR_LIT:filename>' ] <EOL> highlight_args = node . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' in node : <EOL> lang = node [ '<STR_LIT>' ] <EOL> highlight_args [ '<STR_LIT>' ] = True <EOL> if '<STR_LIT>' in node : <EOL> linenos = node [ '<STR_LIT>' ] <EOL> def warner ( msg ) : <EOL> self . builder . warn ( msg , ( self . builder . current_docname , node . line ) ) <EOL> highlighted = self . highlighter . highlight_block ( node . rawsource , lang , <EOL> warn = warner , <EOL> linenos = linenos , <EOL> ** highlight_args ) <EOL> starttag = self . starttag ( node , '<STR_LIT>' , suffix = '<STR_LIT>' , <EOL> CLASS = '<STR_LIT>' % lang ) <EOL> self . body . append ( starttag ) <EOL> self . body . append ( '<STR_LIT>' '<STR_LIT>' % ( fname , ) ) <EOL> self . body . append ( highlighted ) <EOL> self . body . append ( '<STR_LIT>' ) <EOL> raise nodes . SkipNode <EOL> def visit_snippet_latex ( self , node ) : <EOL> """<STR_LIT>""" <EOL> code = node . rawsource . rstrip ( '<STR_LIT:\n>' ) <EOL> lang = self . hlsettingstack [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> linenos = code . count ( '<STR_LIT:\n>' ) >= self . hlsettingstack [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] - <NUM_LIT:1> <EOL> fname = node [ '<STR_LIT:filename>' ] <EOL> highlight_args = node . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' in node : <EOL> lang = node [ '<STR_LIT>' ] <EOL> highlight_args [ '<STR_LIT>' ] = True <EOL> if '<STR_LIT>' in node : <EOL> linenos = node [ '<STR_LIT>' ] <EOL> def warner ( msg ) : <EOL> self . builder . warn ( msg , ( self . curfilestack [ - <NUM_LIT:1> ] , node . line ) ) <EOL> hlcode = self . highlighter . highlight_block ( code , lang , warn = warner , <EOL> linenos = linenos , <EOL> ** highlight_args ) <EOL> self . body . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> fname . replace ( '<STR_LIT:_>' , r'<STR_LIT>' ) , <EOL> ) <EOL> ) <EOL> if self . table : <EOL> hlcode = hlcode . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . table . has_problematic = True <EOL> self . table . has_verbatim = True <EOL> hlcode = hlcode . rstrip ( ) [ : - <NUM_LIT> ] <EOL> hlcode = hlcode . rstrip ( ) + '<STR_LIT:\n>' <EOL> self . body . append ( '<STR_LIT:\n>' + hlcode + '<STR_LIT>' % <EOL> ( self . table and '<STR_LIT>' or '<STR_LIT>' ) ) <EOL> raise nodes . SkipNode <EOL> def depart_snippet_latex ( self , node ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SnippetWithFilename ( Directive ) : <EOL> """<STR_LIT>""" <EOL> has_content = True <EOL> optional_arguments = <NUM_LIT:1> <EOL> option_spec = { '<STR_LIT:filename>' : directives . unchanged_required } <EOL> def run ( self ) : <EOL> code = '<STR_LIT:\n>' . join ( self . content ) <EOL> literal = snippet_with_filename ( code , code ) <EOL> if self . arguments : <EOL> literal [ '<STR_LIT>' ] = self . arguments [ <NUM_LIT:0> ] <EOL> literal [ '<STR_LIT:filename>' ] = self . options [ '<STR_LIT:filename>' ] <EOL> set_source_info ( self , literal ) <EOL> return [ literal ] <EOL> class VersionDirective ( Directive ) : <EOL> has_content = True <EOL> required_arguments = <NUM_LIT:1> <EOL> optional_arguments = <NUM_LIT:1> <EOL> final_argument_whitespace = True <EOL> option_spec = { } <EOL> def run ( self ) : <EOL> if len ( self . arguments ) > <NUM_LIT:1> : <EOL> msg = """<STR_LIT>""" . format ( directive_name = self . name ) <EOL> raise self . error ( msg ) <EOL> env = self . state . document . settings . env <EOL> ret = [ ] <EOL> node = addnodes . versionmodified ( ) <EOL> ret . append ( node ) <EOL> if self . arguments [ <NUM_LIT:0> ] == env . config . django_next_version : <EOL> node [ '<STR_LIT:version>' ] = "<STR_LIT>" <EOL> else : <EOL> node [ '<STR_LIT:version>' ] = self . arguments [ <NUM_LIT:0> ] <EOL> node [ '<STR_LIT:type>' ] = self . name <EOL> if self . content : <EOL> self . state . nested_parse ( self . content , self . content_offset , node ) <EOL> env . note_versionchange ( node [ '<STR_LIT:type>' ] , node [ '<STR_LIT:version>' ] , node , self . lineno ) <EOL> return ret <EOL> class DjangoHTMLTranslator ( SmartyPantsHTMLTranslator ) : <EOL> """<STR_LIT>""" <EOL> def visit_table ( self , node ) : <EOL> self . context . append ( self . compact_p ) <EOL> self . compact_p = True <EOL> self . _table_row_index = <NUM_LIT:0> <EOL> self . body . append ( self . starttag ( node , '<STR_LIT>' , CLASS = '<STR_LIT>' ) ) <EOL> def depart_table ( self , node ) : <EOL> self . compact_p = self . context . pop ( ) <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def visit_desc_parameterlist ( self , node ) : <EOL> self . body . append ( '<STR_LIT:(>' ) <EOL> self . first_param = <NUM_LIT:1> <EOL> self . optional_param_level = <NUM_LIT:0> <EOL> self . param_separator = node . child_text_separator <EOL> self . required_params_left = sum ( [ isinstance ( c , addnodes . desc_parameter ) <EOL> for c in node . children ] ) <EOL> def depart_desc_parameterlist ( self , node ) : <EOL> self . body . append ( '<STR_LIT:)>' ) <EOL> version_text = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def visit_versionmodified ( self , node ) : <EOL> self . body . append ( <EOL> self . starttag ( node , '<STR_LIT>' , CLASS = node [ '<STR_LIT:type>' ] ) <EOL> ) <EOL> version_text = self . version_text . get ( node [ '<STR_LIT:type>' ] ) <EOL> if version_text : <EOL> title = "<STR_LIT>" % ( <EOL> version_text % node [ '<STR_LIT:version>' ] , <EOL> "<STR_LIT::>" if len ( node ) else "<STR_LIT:.>" <EOL> ) <EOL> self . body . append ( '<STR_LIT>' % title ) <EOL> def depart_versionmodified ( self , node ) : <EOL> self . body . append ( "<STR_LIT>" ) <EOL> def visit_section ( self , node ) : <EOL> old_ids = node . get ( '<STR_LIT>' , [ ] ) <EOL> node [ '<STR_LIT>' ] = [ '<STR_LIT>' + i for i in old_ids ] <EOL> node [ '<STR_LIT>' ] . extend ( old_ids ) <EOL> SmartyPantsHTMLTranslator . visit_section ( self , node ) <EOL> node [ '<STR_LIT>' ] = old_ids <EOL> def parse_django_admin_node ( env , sig , signode ) : <EOL> command = sig . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] <EOL> env . ref_context [ '<STR_LIT>' ] = command <EOL> title = "<STR_LIT>" % sig <EOL> signode += addnodes . desc_name ( title , title ) <EOL> return command <EOL> class DjangoStandaloneHTMLBuilder ( StandaloneHTMLBuilder ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> def finish ( self ) : <EOL> super ( DjangoStandaloneHTMLBuilder , self ) . finish ( ) <EOL> self . info ( bold ( "<STR_LIT>" ) ) <EOL> xrefs = self . env . domaindata [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> templatebuiltins = { <EOL> "<STR_LIT>" : [ n for ( ( t , n ) , ( l , a ) ) in xrefs . items ( ) <EOL> if t == "<STR_LIT>" and l == "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ n for ( ( t , n ) , ( l , a ) ) in xrefs . items ( ) <EOL> if t == "<STR_LIT>" and l == "<STR_LIT>" ] , <EOL> } <EOL> outfilename = os . path . join ( self . outdir , "<STR_LIT>" ) <EOL> with open ( outfilename , '<STR_LIT:w>' ) as fp : <EOL> fp . write ( '<STR_LIT>' ) <EOL> json . dump ( templatebuiltins , fp ) <EOL> fp . write ( '<STR_LIT>' ) </s>
