当前位置: 首页>>代码示例>>Python>>正文


Python nodes.error方法代码示例

本文整理汇总了Python中docutils.nodes.error方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.error方法的具体用法?Python nodes.error怎么用?Python nodes.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docutils.nodes的用法示例。


在下文中一共展示了nodes.error方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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 
开发者ID:GiggleLiu,项目名称:viznet,代码行数:21,代码来源:conf.py

示例2: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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 
开发者ID:mobiusklein,项目名称:ms_deisotope,代码行数:22,代码来源:exec_directive.py

示例3: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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 
开发者ID:hootnot,项目名称:oanda-api-v20,代码行数:18,代码来源:conf.py

示例4: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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 
开发者ID:team-ocean,项目名称:veros,代码行数:20,代码来源:conf.py

示例5: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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] 
开发者ID:unaguil,项目名称:sphinx-swaggerdoc,代码行数:22,代码来源:swagger_doc.py

示例6: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:33,代码来源:conf.py

示例7: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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] 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:43,代码来源:parsable_text.py

示例8: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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)),
                )
            ] 
开发者ID:terrapower,项目名称:armi,代码行数:38,代码来源:dochelpers.py

示例9: no_plantuml

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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) 
开发者ID:useblocks,项目名称:sphinxcontrib-needs,代码行数:10,代码来源:diagrams_common.py

示例10: check_tags

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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] 
开发者ID:unaguil,项目名称:sphinx-swaggerdoc,代码行数:7,代码来源:swaggerv2_doc.py

示例11: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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] 
开发者ID:unaguil,项目名称:sphinx-swaggerdoc,代码行数:43,代码来源:swaggerv2_doc.py

示例12: run

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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 ---------------------------------------------------------- 
开发者ID:DHI-GRAS,项目名称:terracotta,代码行数:31,代码来源:conf.py

示例13: visit_admonition

# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import error [as 别名]
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:] 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:48,代码来源:parsable_text.py


注:本文中的docutils.nodes.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。