當前位置: 首頁>>代碼示例>>Python>>正文


Python nodes.warning方法代碼示例

本文整理匯總了Python中docutils.nodes.warning方法的典型用法代碼示例。如果您正苦於以下問題:Python nodes.warning方法的具體用法?Python nodes.warning怎麽用?Python nodes.warning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docutils.nodes的用法示例。


在下文中一共展示了nodes.warning方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import warning [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

示例2: _directive_checks

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import warning [as 別名]
def _directive_checks(self):

        # Check if file insertion is enabled
        if not self.state.document.settings.file_insertion_enabled:
            msg = (
                'File and URL access deactivated. '
                'Ignoring directive "{}".'.format(self._get_directive_name())
            )
            warning = nodes.warning(
                '', self.state_machine.reporter.warning(
                    '', nodes.literal_block('', msg),
                    line=self.lineno
                )
            )
            return [warning]

        # Check that no content and argument are used at the same time
        if self.arguments and self.content:
            warning = self.state_machine.reporter.warning(
                '{} directive cannot have both content and a filename '
                'argument.'.format(self._get_directive_name()),
                line=self.lineno
            )
            return [warning]

        # Check that at least one was provided
        if not (self.arguments or self.content):
            warning = self.state_machine.reporter.warning(
                '{} directive must have content or a filename '
                'argument.'.format(self._get_directive_name()),
                line=self.lineno
            )
            return [warning]

        return None 
開發者ID:carlos-jenkins,項目名稱:plantweb,代碼行數:37,代碼來源:directive.py

示例3: run

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import warning [as 別名]
def run(self):
        """ Executes python code for an RST document, taking input from content or from a filename

        :return:
        """
        language = self.options.get('language') or 'python'
        output_language = self.options.get('output_language') or 'none'
        filename = self.options.get('filename')
        code = ''

        if not filename:
            code = '\n'.join(self.content)
        if filename:
            try:
                with open(filename, 'r') as code_file:
                    code = code_file.read()
                    self.warning('code is %s' % code)
            except (IOError, OSError) as err:
                # Raise warning instead of a code block
                error = 'Error opening file: %s, working folder: %s' % (err, os.getcwd())
                self.warning(error)
                return [nodes.warning(error, error)]

        output = []

        # Show the example code
        if not 'hide_code' in self.options:
            input_code = nodes.literal_block(code, code)

            input_code['language'] = language
            input_code['linenos'] = 'linenos' in self.options
            if not 'hide_headers' in self.options:
                suffix = ''
                if not 'hide_filename' in self.options:
                    suffix = '' if filename is None else str(filename)
                output.append(nodes.caption(
                    text='Code %s' % suffix))
            output.append(input_code)

        # Show the code results
        if not 'hide_headers' in self.options:
            output.append(nodes.caption(text='Results'))
        code_results = self.execute_code(code)
        code_results = nodes.literal_block(code_results, code_results)

        code_results['linenos'] = 'linenos' in self.options
        code_results['language'] = output_language
        output.append(code_results)
        return output 
開發者ID:jpsenior,項目名稱:sphinx-execute-code,代碼行數:51,代碼來源:__init__.py

示例4: visit_admonition

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import warning [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.warning方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。