Ticket #14033: 14033.2.diff

File 14033.2.diff, 3.8 KB (added by Ramiro Morales, 14 years ago)

Fixed bare except clauses.

  • docs/_ext/djangodocs.py

    diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py
    a b  
    1919from sphinx.builders.html import StandaloneHTMLBuilder
    2020from sphinx.writers.html import SmartyPantsHTMLTranslator
    2121from sphinx.util.console import bold
     22from sphinx.util.compat import Directive
    2223
    2324
    2425def setup(app):
     
    5556        parse_node    = parse_django_adminopt_node,
    5657    )
    5758    app.add_config_value('django_next_version', '0.0', True)
    58     app.add_directive('versionadded', parse_version_directive, 1, (1, 1, 1))
    59     app.add_directive('versionchanged', parse_version_directive, 1, (1, 1, 1))
     59    app.add_directive('versionadded', VersionDirective)
     60    app.add_directive('versionchanged', VersionDirective)
    6061    app.add_transform(SuppressBlockquotes)
    6162    app.add_builder(DjangoStandaloneHTMLBuilder)
    6263
    63 def parse_version_directive(name, arguments, options, content, lineno,
    64                       content_offset, block_text, state, state_machine):
    65     env = state.document.settings.env
    66     is_nextversion = env.config.django_next_version == arguments[0]
    67     ret = []
    68     node = addnodes.versionmodified()
    69     ret.append(node)
    70     if not is_nextversion:
    71         if len(arguments) == 1:
    72             linktext = 'Please, see the release notes <releases-%s>' % (arguments[0])
    73             try:
    74                 xrefs = roles.XRefRole()('ref', linktext, linktext, lineno, state) # Sphinx >= 1.0
    75             except:
    76                 xrefs = roles.xfileref_role('ref', linktext, linktext, lineno, state) # Sphinx < 1.0
    77             node.extend(xrefs[0])
    78         node['version'] = arguments[0]
    79     else:
    80         node['version'] = "Development version"
    81     node['type'] = name
    82     if len(arguments) == 2:
    83         inodes, messages = state.inline_text(arguments[1], lineno+1)
    84         node.extend(inodes)
    85         if content:
    86             state.nested_parse(content, content_offset, node)
    87         ret = ret + messages
    88     env.note_versionchange(node['type'], node['version'], node, lineno)
    89     return ret
     64
     65class VersionDirective(Directive):
     66    has_content = True
     67    required_arguments = 1
     68    optional_arguments = 1
     69    final_argument_whitespace = True
     70    option_spec = {}
     71
     72    def run(self):
     73        env = self.state.document.settings.env
     74        arg0 = self.arguments[0]
     75        is_nextversion = env.config.django_next_version == arg0
     76        ret = []
     77        node = addnodes.versionmodified()
     78        ret.append(node)
     79        if not is_nextversion:
     80            if len(self.arguments) == 1:
     81                linktext = 'Please, see the release notes <releases-%s>' % (arg0)
     82                try:
     83                    xrefs = roles.XRefRole()('std:ref', linktext, linktext, self.lineno, self.state) # Sphinx >= 1.0
     84                except AttributeError:
     85                    xrefs = roles.xfileref_role('ref', linktext, linktext, self.lineno, self.state) # Sphinx < 1.0
     86                node.extend(xrefs[0])
     87            node['version'] = arg0
     88        else:
     89            node['version'] = "Development version"
     90        node['type'] = self.name
     91        if len(self.arguments) == 2:
     92            inodes, messages = self.state.inline_text(self.arguments[1], self.lineno+1)
     93            node.extend(inodes)
     94            if self.content:
     95                self.state.nested_parse(self.content, self.content_offset, node)
     96            ret = ret + messages
     97        env.note_versionchange(node['type'], node['version'], node, self.lineno)
     98        return ret
    9099
    91100
    92101class SuppressBlockquotes(transforms.Transform):
     
    185194    """A copy of sphinx.directives.CmdoptionDesc.parse_signature()"""
    186195    try:
    187196        from sphinx.domains.std import option_desc_re # Sphinx >= 1.0
    188     except:
     197    except ImportError:
    189198        from sphinx.directives.desc import option_desc_re # Sphinx < 1.0
    190199    count = 0
    191200    firstname = ''
Back to Top