99 :license: Python license.
1010"""
1111
12- ISSUE_URI = 'https://bugs.python.org/issue%s'
13- SOURCE_URI = 'https://hg.python.org/cpython/file/3.4/%s'
12+ import re
13+ import codecs
14+ from os import path
15+ from time import asctime
16+ from pprint import pformat
17+ from docutils .io import StringOutput
18+ from docutils .utils import new_document
1419
1520from docutils import nodes , utils
1621
22+ from sphinx import addnodes
23+ from sphinx .builders import Builder
1724from sphinx .util .nodes import split_explicit_title
1825from sphinx .util .compat import Directive
1926from sphinx .writers .html import HTMLTranslator
27+ from sphinx .writers .text import TextWriter
2028from sphinx .writers .latex import LaTeXTranslator
29+ from sphinx .domains .python import PyModulelevel , PyClassmember
30+
31+ # Support for checking for suspicious markup
32+
33+ import suspicious
34+
35+
36+ ISSUE_URI = 'https://bugs.python.org/issue%s'
37+ SOURCE_URI = 'https://hg.python.org/cpython/file/3.4/%s'
2138
2239# monkey-patch reST parser to disable alphabetic and roman enumerated lists
2340from docutils .parsers .rst .states import Body
2946# monkey-patch HTML and LaTeX translators to keep doctest blocks in the
3047# doctest docs themselves
3148orig_visit_literal_block = HTMLTranslator .visit_literal_block
49+ orig_depart_literal_block = LaTeXTranslator .depart_literal_block
50+
51+
3252def new_visit_literal_block (self , node ):
3353 meta = self .builder .env .metadata [self .builder .current_docname ]
3454 old_trim_doctest_flags = self .highlighter .trim_doctest_flags
@@ -39,9 +59,7 @@ def new_visit_literal_block(self, node):
3959 finally :
4060 self .highlighter .trim_doctest_flags = old_trim_doctest_flags
4161
42- HTMLTranslator .visit_literal_block = new_visit_literal_block
4362
44- orig_depart_literal_block = LaTeXTranslator .depart_literal_block
4563def new_depart_literal_block (self , node ):
4664 meta = self .builder .env .metadata [self .curfilestack [- 1 ]]
4765 old_trim_doctest_flags = self .highlighter .trim_doctest_flags
@@ -52,8 +70,11 @@ def new_depart_literal_block(self, node):
5270 finally :
5371 self .highlighter .trim_doctest_flags = old_trim_doctest_flags
5472
73+
74+ HTMLTranslator .visit_literal_block = new_visit_literal_block
5575LaTeXTranslator .depart_literal_block = new_depart_literal_block
5676
77+
5778# Support for marking up and linking to bugs.python.org issues
5879
5980def issue_role (typ , rawtext , text , lineno , inliner , options = {}, content = []):
@@ -101,9 +122,6 @@ def run(self):
101122
102123# Support for documenting decorators
103124
104- from sphinx import addnodes
105- from sphinx .domains .python import PyModulelevel , PyClassmember
106-
107125class PyDecoratorMixin (object ):
108126 def handle_signature (self , sig , signode ):
109127 ret = super (PyDecoratorMixin , self ).handle_signature (sig , signode )
@@ -113,12 +131,14 @@ def handle_signature(self, sig, signode):
113131 def needs_arglist (self ):
114132 return False
115133
134+
116135class PyDecoratorFunction (PyDecoratorMixin , PyModulelevel ):
117136 def run (self ):
118137 # a decorator function is a function after all
119138 self .name = 'py:function'
120139 return PyModulelevel .run (self )
121140
141+
122142class PyDecoratorMethod (PyDecoratorMixin , PyClassmember ):
123143 def run (self ):
124144 self .name = 'py:method'
@@ -162,7 +182,8 @@ def run(self):
162182 classes = ['versionmodified' ]))
163183 else :
164184 para = nodes .paragraph ('' , '' ,
165- nodes .inline ('' , '%s.' % text , classes = ['versionmodified' ]))
185+ nodes .inline ('' , '%s.' % text ,
186+ classes = ['versionmodified' ]))
166187 if len (node ):
167188 node .insert (0 , para )
168189 else :
@@ -174,12 +195,10 @@ def run(self):
174195
175196# Support for including Misc/NEWS
176197
177- import re
178- import codecs
179-
180198issue_re = re .compile ('([Ii])ssue #([0-9]+)' )
181199whatsnew_re = re .compile (r"(?im)^what's new in (.*?)\??$" )
182200
201+
183202class MiscNews (Directive ):
184203 has_content = False
185204 required_arguments = 1
@@ -233,15 +252,6 @@ def run(self):
233252 'typesseq' , 'typesseq-mutable' , 'unary' , 'while' , 'with' , 'yield'
234253]
235254
236- from os import path
237- from time import asctime
238- from pprint import pformat
239- from docutils .io import StringOutput
240- from docutils .utils import new_document
241-
242- from sphinx .builders import Builder
243- from sphinx .writers .text import TextWriter
244-
245255
246256class PydocTopicsBuilder (Builder ):
247257 name = 'pydoc-topics'
@@ -281,17 +291,11 @@ def finish(self):
281291 f .close ()
282292
283293
284- # Support for checking for suspicious markup
285-
286- import suspicious
287-
288-
289294# Support for documenting Opcodes
290295
291- import re
292-
293296opcode_sig_re = re .compile (r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?' )
294297
298+
295299def parse_opcode_signature (env , sig , signode ):
296300 """Transform an opcode signature into RST nodes."""
297301 m = opcode_sig_re .match (sig )
@@ -311,12 +315,13 @@ def parse_opcode_signature(env, sig, signode):
311315pdbcmd_sig_re = re .compile (r'([a-z()!]+)\s*(.*)' )
312316
313317# later...
314- #pdbargs_tokens_re = re.compile(r'''[a-zA-Z]+ | # identifiers
318+ # pdbargs_tokens_re = re.compile(r'''[a-zA-Z]+ | # identifiers
315319# [.,:]+ | # punctuation
316320# [\[\]()] | # parens
317321# \s+ # whitespace
318322# ''', re.X)
319323
324+
320325def parse_pdb_command (env , sig , signode ):
321326 """Transform a pdb command signature into RST nodes."""
322327 m = pdbcmd_sig_re .match (sig )
0 commit comments