<s> """<STR_LIT>""" <EOL> import json <EOL> import os <EOL> import re <EOL> from sphinx import addnodes , __version__ as sphinx_ver <EOL> from sphinx . builders . html import StandaloneHTMLBuilder <EOL> from sphinx . writers . html import SmartyPantsHTMLTranslator <EOL> from sphinx . util . console import bold <EOL> from sphinx . util . compat import Directive <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_description_unit ( <EOL> directivename = "<STR_LIT>" , <EOL> rolename = "<STR_LIT>" , <EOL> indextemplate = "<STR_LIT>" , <EOL> parse_node = parse_django_adminopt_node , <EOL> ) <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> 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 . param_separator = node . child_text_separator <EOL> def depart_desc_parameterlist ( self , node ) : <EOL> self . body . append ( '<STR_LIT:)>' ) <EOL> if sphinx_ver < '<STR_LIT>' : <EOL> def visit_literal_block ( self , node ) : <EOL> self . no_smarty += <NUM_LIT:1> <EOL> SmartyPantsHTMLTranslator . visit_literal_block ( self , node ) <EOL> def depart_literal_block ( self , node ) : <EOL> SmartyPantsHTMLTranslator . depart_literal_block ( self , node ) <EOL> self . no_smarty -= <NUM_LIT:1> <EOL> version_text = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <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> title = "<STR_LIT>" % ( <EOL> self . version_text [ node [ '<STR_LIT:type>' ] ] % 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 . _django_curr_admin_command = command <EOL> title = "<STR_LIT>" % sig <EOL> signode += addnodes . desc_name ( title , title ) <EOL> return sig <EOL> def parse_django_adminopt_node ( env , sig , signode ) : <EOL> """<STR_LIT>""" <EOL> from sphinx . domains . std import option_desc_re <EOL> count = <NUM_LIT:0> <EOL> firstname = '<STR_LIT>' <EOL> for m in option_desc_re . finditer ( sig ) : <EOL> optname , args = m . groups ( ) <EOL> if count : <EOL> signode += addnodes . desc_addname ( '<STR_LIT:U+002CU+0020>' , '<STR_LIT:U+002CU+0020>' ) <EOL> signode += addnodes . desc_name ( optname , optname ) <EOL> signode += addnodes . desc_addname ( args , args ) <EOL> if not count : <EOL> firstname = optname <EOL> count += <NUM_LIT:1> <EOL> if not count : <EOL> for m in simple_option_desc_re . finditer ( sig ) : <EOL> optname , args = m . groups ( ) <EOL> if count : <EOL> signode += addnodes . desc_addname ( '<STR_LIT:U+002CU+0020>' , '<STR_LIT:U+002CU+0020>' ) <EOL> signode += addnodes . desc_name ( optname , optname ) <EOL> signode += addnodes . desc_addname ( args , args ) <EOL> if not count : <EOL> firstname = optname <EOL> count += <NUM_LIT:1> <EOL> if not firstname : <EOL> raise ValueError <EOL> return firstname <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>
