Python docutils.nodes.error() Examples
The following are 15
code examples of docutils.nodes.error().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.nodes
, or try the search function
.
Example #1
Source File: conf.py From viznet with MIT License | 6 votes |
def run(self): oldStdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get( 'tab-width', self.state.document.settings.tab_width) source = self.state_machine.input_lines.source( self.lineno - self.state_machine.input_offset - 1) try: exec('\n'.join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines( text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: return [nodes.error(None, nodes.paragraph(text="Unable to execute python code at %s:%d:" % (basename(source), self.lineno)), nodes.paragraph(text=str(sys.exc_info()[1])))] finally: sys.stdout = oldStdout
Example #2
Source File: exec_directive.py From ms_deisotope with Apache License 2.0 | 6 votes |
def run(self): oldStdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1) try: exec('\n'.join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines(text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: return [nodes.error( None, nodes.paragraph(text="Unable to execute python code at %s:%d:" % ( basename(source), self.lineno)), nodes.paragraph(text=str(sys.exc_info()[1])))] finally: sys.stdout = oldStdout
Example #3
Source File: conf.py From oanda-api-v20 with MIT License | 6 votes |
def run(self): oldStdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1) try: exec('\n'.join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines(text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: return [nodes.error(None, nodes.paragraph(text = "Unable to execute python code at %s:%d:" % (basename(source), self.lineno)), nodes.paragraph(text = str(sys.exc_info()[1])))] finally: sys.stdout = oldStdout
Example #4
Source File: conf.py From veros with MIT License | 6 votes |
def run(self): old_stdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1) try: exec('\n'.join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines(text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: warn_text = "Unable to execute python code at %s:%d" % (basename(source), self.lineno) warning = self.state_machine.reporter.warning(warn_text) return [warning, nodes.error(None, nodes.paragraph(text=warn_text), nodes.paragraph(text=str(sys.exc_info()[1])))] finally: sys.stdout = old_stdout
Example #5
Source File: swagger_doc.py From sphinx-swaggerdoc with MIT License | 6 votes |
def run(self): try: methods = self.processSwaggerURL(self.content[0]) entries = [] for method in methods: for operation in method['operations']: entries += self.make_operation(method['path'], operation) return entries except: print('Unable to process URL: %s' % self.content[0]) error = nodes.error('') para = nodes.paragraph() para += nodes.Text('Unable to process URL: ') para += nodes.strong('', self.content[0]) para += nodes.Text('. Please check that the URL is a valid Swagger api-docs URL and it is accesible') error += para return [error]
Example #6
Source File: conf.py From saxo_openapi with MIT License | 6 votes |
def run(self): oldStdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1) try: exec('\n'.join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines(text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: return [nodes.error(None, nodes.paragraph(text = "Unable to execute python code at %s:%d:" % (basename(source), self.lineno)), nodes.paragraph(text = str(sys.exc_info()[1])))] finally: sys.stdout = oldStdout
Example #7
Source File: conf.py From pyuvdata with BSD 2-Clause "Simplified" License | 5 votes |
def run(self): oldStdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get( "tab-width", self.state.document.settings.tab_width ) source = self.state_machine.input_lines.source( self.lineno - self.state_machine.input_offset - 1 ) try: exec("\n".join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines(text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: return [ nodes.error( None, nodes.paragraph( text="Unable to execute python " "code at {file}:{line}".format( file=os.path.basename(source), line=self.lineno ) ), nodes.paragraph(text=str(sys.exc_info()[1])), ) ] finally: sys.stdout = oldStdout
Example #8
Source File: conf.py From veros with MIT License | 5 votes |
def run(self): import importlib import shlex from click.testing import CliRunner arg = self.arguments[0] options = shlex.split(self.options.get('args', '')) try: modname, funcname = arg.split(':') except ValueError: raise self.error('run-click argument must be "module:function"') try: mod = importlib.import_module(modname) func = getattr(mod, funcname) runner = CliRunner() with runner.isolated_filesystem(): result = runner.invoke(func, options) text = result.output if result.exit_code != 0: raise RuntimeError('Command exited with non-zero exit code; output: "%s"' % text) node = nodes.literal_block(text=text) node['language'] = 'text' return [node] except Exception: warn_text = "Error while running command %s %s" % (arg, ' '.join(map(shlex.quote, options))) warning = self.state_machine.reporter.warning(warn_text) return [warning, nodes.error(None, nodes.paragraph(text=warn_text), nodes.paragraph(text=str(sys.exc_info()[1])))]
Example #9
Source File: parsable_text.py From INGInious with GNU Affero General Public License v3.0 | 5 votes |
def run(self): self.assert_has_content() hidden_until = self.arguments[0] try: hidden_until = parse_date(hidden_until) except: raise self.error('Unknown date format in the "%s" directive; ' '%s' % (self.name, hidden_until)) force_show = self.state.document.settings.force_show_hidden_until translation = _get_inginious_translation() after_deadline = hidden_until <= datetime.now() if after_deadline or force_show: output = [] # Add a warning for teachers/tutors/... if not after_deadline and force_show: node = nodes.caution() self.add_name(node) text = translation.gettext("The feedback below will be hidden to the students until {}.").format( hidden_until.strftime("%d/%m/%Y %H:%M:%S")) self.state.nested_parse(StringList(text.split("\n")), 0, node) output.append(node) text = '\n'.join(self.content) node = nodes.compound(text) self.add_name(node) self.state.nested_parse(self.content, self.content_offset, node) output.append(node) return output else: node = nodes.caution() self.add_name(node) text = translation.gettext( "A part of this feedback is hidden until {}. Please come back later and reload the submission to see the full feedback.").format( hidden_until.strftime("%d/%m/%Y %H:%M:%S")) self.state.nested_parse(StringList(text.split("\n")), 0, node) return [node]
Example #10
Source File: dochelpers.py From armi with Apache License 2.0 | 5 votes |
def run(self): try: code = inspect.cleandoc( """ def usermethod(): {} """ ).format("\n ".join(self.content)) exec(code) result = locals()["usermethod"]() if result is None: raise Exception( "Return value needed! The body of your `.. exec::` is used as a " "function call that must return a value." ) para = nodes.container() # tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) lines = statemachine.StringList(result.split("\n")) self.state.nested_parse(lines, self.content_offset, para) return [para] except Exception as e: docname = self.state.document.settings.env.docname return [ nodes.error( None, nodes.paragraph( text="Unable to execute python code at {}:{} ... {}".format( docname, self.lineno, datetime.datetime.now() ) ), nodes.paragraph(text=str(e)), nodes.literal_block(text=str(code)), ) ]
Example #11
Source File: diagrams_common.py From sphinxcontrib-needs with MIT License | 5 votes |
def no_plantuml(node): """Adds a hint that plantuml is not available""" content = nodes.error() para = nodes.paragraph() text = nodes.Text("PlantUML is not available!", "PlantUML is not available!") para += text content.append(para) node.replace_self(content)
Example #12
Source File: swaggerv2_doc.py From sphinx-swaggerdoc with MIT License | 5 votes |
def check_tags(self, selected_tags, tags, api_url): invalid_tags = list(set(selected_tags) - set(tags)) if len(invalid_tags) > 0: msg = self.reporter.error("Error. Tag '%s' not found in Swagger URL %s." % (invalid_tags[0], api_url)) return [msg]
Example #13
Source File: swaggerv2_doc.py From sphinx-swaggerdoc with MIT License | 5 votes |
def run(self): self.reporter = self.state.document.reporter api_url = self.content[0] if len(self.content) > 1: selected_tags = self.content[1:] else: selected_tags = [] try: api_desc = self.processSwaggerURL(api_url) groups = self.group_tags(api_desc) self.check_tags(selected_tags, groups.keys(), api_url) entries = [] for tag_name, methods in groups.items(): if tag_name in selected_tags or len(selected_tags) == 0: section = self.create_section(tag_name) for path, method_type, method in methods: section += self.make_method(path, method_type, method) entries.append(section) return entries except Exception as e: error_message = 'Unable to process URL: %s' % api_url print(error_message) traceback.print_exc() error = nodes.error('') para_error = nodes.paragraph() para_error += nodes.Text(error_message + '. Please check that the URL is a valid Swagger api-docs URL and it is accesible') para_error_detailed = nodes.paragraph() para_error_detailed = nodes.strong('Processing error. See console output for a more detailed error') error += para_error error += para_error_detailed return [error]
Example #14
Source File: conf.py From terracotta with MIT License | 5 votes |
def run(self): old_stdout, sys.stdout = sys.stdout, StringIO() tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) source = self.state_machine.input_lines.source( self.lineno - self.state_machine.input_offset - 1) try: exec('\n'.join(self.content)) text = sys.stdout.getvalue() lines = statemachine.string2lines(text, tab_width, convert_whitespace=True) self.state_machine.insert_input(lines, source) return [] except Exception: warn_text = f'Unable to execute python code at {basename(source)}:{self.lineno}' warning = self.state_machine.reporter.warning(warn_text) return [ warning, nodes.error( None, nodes.paragraph(text=warn_text), nodes.paragraph(text=str(sys.exc_info()[1])) ) ] finally: sys.stdout = old_stdout # -- Setup function ----------------------------------------------------------
Example #15
Source File: parsable_text.py From INGInious with GNU Affero General Public License v3.0 | 4 votes |
def visit_admonition(self, node): """ Support for bootstrap alert/cards """ node['classes'].insert(0, 'admonition') converter = { 'danger': 'danger', 'attention': 'warning', 'caution': 'warning', 'error': 'danger', 'hint': 'info', 'important': 'warning', 'note': 'default', 'tip': 'info', 'warning': 'warning', 'success': 'success', 'info': 'info', 'primary': 'primary', 'secondary': 'secondary', 'light': 'light', 'dark': 'dark' } cls = [x if not x.startswith('admonition-') else x[11:] for x in node['classes']] cls = [converter.get(x) for x in cls if converter.get(x) is not None] if len(cls) == 0: cls = 'info' else: cls = cls[0] if "title" in node and node['title'] != "": self.body.append(self.starttag(node, 'div', CLASS='card mb-3 border-' + cls)) card_color = "bg-" + cls if cls not in ['default', 'light', 'secondary']: card_color += ' text-white' self.body.append(self.starttag(node, 'div', CLASS='card-header ' + card_color)) self.body.append(self.encode(node['title'])) self.body.append('</div>\n') self.body.append(self.starttag(node, 'div', CLASS='card-body')) else: if cls == "default": cls = 'light' self.body.append(self.starttag(node, 'div', CLASS='alert alert-' + cls)) self.set_first_last(node) # drop unneeded title node.children = node.children[1:]