Takayuki Shimizukawa avatar Takayuki Shimizukawa committed e5ca41c

fix: reporting correct line number implementation (6fc25e0e3a5c) was not worked with docutils 0.7, 0.8.

Comments (0)

Files changed (1)


     def __init__(self, source, line):
         self.source, self.line = source, line
+        try:
+            from docutils import __version__ as du_version
+            v = tuple([int(x) for x in du_version.split('.')[:2]])
+        except ImportError:
+            v = (99, 99)
+        self.du_version = v
+    def set_reporter(self, document):
+        if self.du_version < (0, 9):
+            document.reporter.locator = self.get_source_and_line
+        else:
+            document.reporter.get_source_and_line = self.get_source_and_line
     def get_source_and_line(self, lineno=None):
         return self.source, self.line
                 # dummy literal node will discard by 'patch = patch[0]'
             patch = new_document(source, settings)
-            patch.reporter.get_source_and_line = CustomLocaleReporter(
-                    node.source, node.line).get_source_and_line
+            CustomLocaleReporter(node.source, node.line).set_reporter(patch)
             parser.parse(msgstr, patch)
             patch = patch[0]
             # XXX doctest and other block markup
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.