def __init__(self, source, report_level=Reporter.WARNING_LEVEL, halt_level=Reporter.SEVERE_LEVEL, debug=False, error_handler='backslashreplace'): # type: (unicode, int, int, bool, unicode) -> None stream = WarningStream() Reporter.__init__(self, source, report_level, halt_level, stream, debug, error_handler=error_handler)
def set_conditions(self, category, report_level, halt_level, debug=False): # type: (unicode, int, int, bool) -> None Reporter.set_conditions(self, category, report_level, halt_level, debug=debug)
def __init__(self, source, report_level, halt_level, debug=False, error_handler='backslashreplace'): # type: (unicode, int, int, bool, unicode) -> None stream = WarningStream() Reporter.__init__(self, source, report_level, halt_level, stream, debug, error_handler=error_handler) self.source_and_line = None # type: SphinxFileInput
def __init__(self, source, report_level, halt_level, stream=None, debug=0, encoding='ascii', error_handler='replace'): self.messages = [] Reporter.__init__(self, source, report_level, halt_level, stream, debug, encoding, error_handler)
def __init__(self): settings = frontend.OptionParser().get_default_values() settings.report_level = 1 Reporter.__init__( self, source='sphinxcontrib.clearquest', report_level=settings.report_level, halt_level=settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler )
def __init__(self, src='sphinxcontrib.xyz'): settings = frontend.OptionParser().get_default_values() settings.report_level = 1 Reporter.__init__(self, src, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) self.log = logging.getLogger(src)
def _generate_preview(self, page_id, contents): """ Generate a preview for suggested changes. """ handle, pathname = tempfile.mkstemp() os.write(handle, contents.encode('utf-8')) os.close(handle) warning_stream = StringIO.StringIO() env2 = copy.deepcopy(self.env) destination = StringOutput(encoding='utf-8') builder = MockBuilder() builder.config = env2.config writer = HTMLWriter(builder) doctree = env2.read_doc(page_id, pathname, save_parsed=False) doctree = env2.get_and_resolve_doctree(page_id + '.rst', builder, doctree) doctree.settings = OptionParser( defaults=env2.settings, components=(writer, )).get_default_values() doctree.reporter = Reporter(page_id + '.rst', 2, 4, stream=warning_stream) output = writer.write(doctree, destination) writer.assemble_parts() return writer.parts['fragment']
def __init__(self, src='sphinxcontrib.xyz'): settings = frontend.OptionParser().get_default_values() settings.report_level = 1 Reporter.__init__(self, src, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler ) self.log = logging.getLogger(src)
def new_document(): """There is a similar utility in docutils.utils but it supposes a file source (right?), and does not work straight for (at least) html output (?)""" from docutils import frontend #these are only needed here from docutils.utils import Reporter source = None settings = frontend.OptionParser().get_default_values() #these needed for getting a html out - where are the defaults? settings.xml_declaration = False settings.embed_stylesheet = False settings.stylesheet_path = False settings.stylesheet = None settings.initial_header_level = "1" #an attempt to make docutils.nodes.NodeVisitor accept notebook classes #this is one-to-one from docutils.utils new_document reporter = Reporter(source, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter) return document
def __init__(self): app = AttrDict({"config": AttrDict()}) env = AttrDict({"app": app}) settings = AttrDict({"env": env}) reporter = Reporter('', 0, 100) self.document = AttrDict({"settings": settings, "reporter": reporter})
def html_meta_to_nodes( data: Dict[str, Any], document: nodes.document, line: int, reporter: Reporter ) -> List[Union[nodes.pending, nodes.system_message]]: """Replicate the `meta` directive, by converting a dictionary to a list of pending meta nodes See: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#html-metadata """ if not data: return [] try: from sphinx.addnodes import meta as meta_cls except ImportError: from docutils.parsers.rst.directives.html import MetaBody meta_cls = MetaBody.meta # type: ignore output = [] for key, value in data.items(): content = str(value or "") meta_node = meta_cls(content) meta_node.source = document["source"] meta_node.line = line meta_node["content"] = content try: if not content: raise ValueError("No content") for i, key_part in enumerate(key.split()): if "=" not in key_part and i == 0: meta_node["name"] = key_part continue if "=" not in key_part: raise ValueError(f"no '=' in {key_part}") attr_name, attr_val = key_part.split("=", 1) if not (attr_name and attr_val): raise ValueError(f"malformed {key_part}") meta_node[attr_name.lower()] = attr_val except ValueError as error: msg = reporter.error( f'Error parsing meta tag attribute "{key}": {error}.') output.append(msg) continue pending = nodes.pending( Filter, { "component": "writer", "format": "html", "nodes": [meta_node] }, ) document.note_pending(pending) output.append(pending) return output
def __init__(self, github_issues_url): config = AttrDict({"github_pull_url": RequestsURL(github_issues_url)}) app = AttrDict({"config": config}) env = AttrDict({"app": app}) settings = AttrDict({"env": env}) reporter = Reporter('', 0, 100) self.document = AttrDict({"settings": settings, "reporter": reporter})
def get_doctree(self, filename): """Read the doctree for a file from the pickle and return it.""" doctree_filename = path.join(self.doctreedir, filename[:-3] + 'doctree') with file(doctree_filename, 'rb') as f: doctree = pickle.load(f) doctree.reporter = Reporter(filename, 2, 4, stream=self.warning_stream) return doctree
def system_message(self, *args, **kwargs): # type: (Any, Any) -> Any if kwargs.get('line') and isinstance(self.source_and_line, ViewList): # replace source parameter if source is set source, lineno = self.source_and_line.info(kwargs.get('line')) kwargs['source'] = source kwargs['line'] = lineno return Reporter.system_message(self, *args, **kwargs)
def get_doctree(self, docname): # type: (unicode) -> nodes.Node """Read the doctree for a file from the pickle and return it.""" doctree_filename = self.doc2path(docname, self.doctreedir, '.doctree') with open(doctree_filename, 'rb') as f: doctree = pickle.load(f) doctree.settings.env = self doctree.reporter = Reporter(self.doc2path(docname), 2, 5, stream=WarningStream()) return doctree
def get_doctree(self): """Load and return the built docutils.document.""" _path = self.app.doctreedir / (self.nb_name + ".doctree") if not _path.exists(): pytest.fail("doctree not output") doctree = pickle.loads(_path.bytes()) doctree["source"] = self.nb_name doctree.reporter = Reporter(self.nb_name, 1, 5) self.app.env.temp_data["docname"] = self.nb_name doctree.settings.env = self.app.env return doctree
def check_docutils_inliner(po, msgstr): inliner = Inliner() settings = AttrDict({'character_level_inline_markup': False, 'pep_references': None, 'rfc_references': None}) inliner.init_customizations(settings) document = new_document(None) document.settings.syntax_highlight = 'long' stream = StringIO() reporter = Reporter(po.file, report_level=Reporter.WARNING_LEVEL, halt_level=Reporter.SEVERE_LEVEL, stream=stream) memo = Struct(document=document, reporter=reporter, language=None, inliner=inliner) inliner.parse(msgstr, po.current_index, memo, None) return stream.getvalue()
def default_role(docname: str, name: str) -> Generator[None, None, None]: if name: dummy_reporter = Reporter('', 4, 4) role_fn, _ = roles.role(name, english, 0, dummy_reporter) if role_fn: docutils.register_role('', role_fn) else: logger.warning(__('default role %s not found'), name, location=docname) yield docutils.unregister_role('')
def default_role(docname, name): # type: (unicode, unicode) -> Generator if name: dummy_reporter = Reporter('', 4, 4) role_fn, _ = roles.role(name, english, 0, dummy_reporter) if role_fn: roles._roles[''] = role_fn else: logger.warning('default role %s not found', name, location=docname) yield roles._roles.pop('', None) # if a document has set a local default role
def get_doctree(self, docname): """Read the doctree for a file from the pickle and return it.""" doctree_filename = self.doc2path(docname, self.doctreedir, '.doctree') f = open(doctree_filename, 'rb') try: doctree = pickle.load(f) finally: f.close() doctree.reporter = Reporter(self.doc2path(docname), 2, 4, stream=RedirStream(self._warnfunc)) return doctree
def __init__(self, source_link_target, github_source_url): config = AttrDict({ "source_link_target": source_link_target, "github_source_url": RequestsURL(github_source_url), }) app = AttrDict({ "config": config, "builder": AttrDict({ "get_relative_uri": lambda from_, to: to }) }) env = AttrDict({"app": app, "docname": ''}) settings = AttrDict({"env": env}) reporter = Reporter('', 0, 100) self.document = AttrDict({"settings": settings, "reporter": reporter})
def __init__(self, source, report_level, halt_level, debug=False, error_handler='backslashreplace'): stream = WarningStream() Reporter.__init__(self, source, report_level, halt_level, stream, debug, error_handler=error_handler)
def set_conditions(self, category, report_level, halt_level, debug=False): Reporter.set_conditions(self, category, report_level, halt_level, debug=debug)
def __init__(self): # type: () -> None Reporter.__init__(self, '', 999, 4)
'rfc_base_url': 'https://tools.ietf.org/html/', 'input_encoding': 'utf-8-sig', 'doctitle_xform': False, 'sectsubtitle_xform': False, 'halt_level': 5, 'file_insertion_enabled': True, } # This is increased every time an environment attribute is added # or changed to properly invalidate pickle files. # # NOTE: increase base version by 2 to have distinct numbers for Py2 and 3 ENV_VERSION = 51 + (sys.version_info[0] - 2) dummy_reporter = Reporter('', 4, 4) versioning_conditions = { 'none': False, 'text': is_translatable, 'commentable': is_commentable, } # type: Dict[unicode, Union[bool, Callable]] class NoUri(Exception): """Raised by get_relative_uri if there is no URI available.""" pass class BuildEnvironment(object): """
from docutils.utils import Reporter from docutils.writers.html4css1 import Writer #from notebook import document #a singleton may live there source = None settings = frontend.OptionParser().get_default_values() settings.xml_declaration = False settings.embed_stylesheet = False settings.stylesheet_path = False settings.stylesheet = None settings.initial_header_level = "1" reporter = Reporter(source, settings.report_level, settings.halt_level, stream=settings.warning_stream, debug=settings.debug, encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter) title = nodes.title(text="This is the title") subtitle = nodes.subtitle(text=".. with a subtitle") introduction = nodes.section() start = nodes.paragraph(text="The introduction starts with this.") introduction += start background = nodes.section() background += nodes.paragraph( text="This paragraph starts the second section, background.")