Python docutils.statemachine.StringList() Examples
The following are 30
code examples of docutils.statemachine.StringList().
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.statemachine
, or try the search function
.
Example #1
Source File: __init__.py From sphinxcontrib-programoutput with BSD 2-Clause "Simplified" License | 6 votes |
def _container_wrapper(directive, literal_node, caption): container_node = nodes.container('', literal_block=True, classes=['literal-block-wrapper']) parsed = nodes.Element() directive.state.nested_parse(StringList([caption], source=''), directive.content_offset, parsed) if isinstance(parsed[0], nodes.system_message): # pragma: no cover # TODO: Figure out if this is really possible and how to produce # it in a test case. msg = 'Invalid caption: %s' % parsed[0].astext() raise ValueError(msg) assert isinstance(parsed[0], nodes.Element) caption_node = nodes.caption(parsed[0].rawsource, '', *parsed[0].children) caption_node.source = literal_node.source caption_node.line = literal_node.line container_node += caption_node container_node += literal_node return container_node
Example #2
Source File: tables.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #3
Source File: tables.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #4
Source File: tables.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #5
Source File: tables.py From bash-lambda-layer with MIT License | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #6
Source File: tables.py From blackmamba with MIT License | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #7
Source File: tables.py From aws-extender with MIT License | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #8
Source File: autotested.py From exhale with BSD 3-Clause "New" or "Revised" License | 6 votes |
def run(self): if len(self.content) != 0: raise ValueError("`autotested` directive does not allow any arguments.") # Seriously there _HAS_ to be a better way to do this... # Creating something of length 1 so that I can rage-replace it self.content = StringList("?") self.content[0] = textwrap.dedent('''\ This method is tested automatically for every derived type of :class:`~testing.base.ExhaleTestCase` that is not decorated with :func:`~testing.decorators.no_run`. The metaclass :class:`~testing.base.ExhaleTestCaseMetaclass` generates a testing method ``test_common`` that invokes this method. ''') autotested_node = autotested("\n".join(self.content)) autotested_node += nodes.title(_("Automatically Tested"), _("Automatically Tested")) self.state.nested_parse(self.content, self.content_offset, autotested_node) return [autotested_node]
Example #9
Source File: tables.py From deepWordBug with Apache License 2.0 | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #10
Source File: api_doc_gen.py From zenpy with GNU General Public License v3.0 | 6 votes |
def run(self): zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer") node_list = [] doc_sections = self.generate_sections(zenpy_client) output = '.. py:class:: Zenpy%s\n\n' % inspect.signature(zenpy_client.__class__) output += ' %s' % zenpy_client.__doc__ node = container() self.state.nested_parse(StringList(output.split('\n')), 0, node) node_list.append(node) for doc_section in doc_sections: node = paragraph() self.state.nested_parse(StringList(doc_section.split('\n')), 0, node) node_list.append(node) return node_list
Example #11
Source File: directive.py From cotk with Apache License 2.0 | 6 votes |
def __init__(self, env: BuildEnvironment, reporter: Reporter, options: Options, lineno: int, state: Any = None) -> None: self.env = env self.reporter = reporter self.genopt = options self.lineno = lineno self.filename_set = set() # type: Set[str] self.result = StringList() if state: self.state = state else: # create fake object for self.state.document.settings.tab_width warnings.warn('DocumenterBridge requires a state object on instantiation.', RemovedInSphinx40Warning) settings = Struct(tab_width=8) document = Struct(settings=settings) self.state = Struct(document=document)
Example #12
Source File: tables.py From faces with GNU General Public License v2.0 | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #13
Source File: tables.py From faces with GNU General Public License v2.0 | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #14
Source File: tables.py From aws-builders-fair-projects with Apache License 2.0 | 6 votes |
def parse_csv_data_into_rows(self, csv_data, dialect, source): # csv.py doesn't do Unicode; encode temporarily as UTF-8 csv_reader = csv.reader([self.encode_for_csv(line + '\n') for line in csv_data], dialect=dialect) rows = [] max_cols = 0 for row in csv_reader: row_data = [] for cell in row: # decode UTF-8 back to Unicode cell_text = self.decode_from_csv(cell) cell_data = (0, 0, 0, statemachine.StringList( cell_text.splitlines(), source=source)) row_data.append(cell_data) rows.append(row_data) max_cols = max(max_cols, len(row)) return rows, max_cols
Example #15
Source File: __init__.py From cotk with Apache License 2.0 | 5 votes |
def add_content(self, more_content: Any, no_docstring: bool = False) -> None: if self.doc_as_attr: classname = safe_getattr(self.object, '__qualname__', None) if not classname: classname = safe_getattr(self.object, '__name__', None) if classname: module = safe_getattr(self.object, '__module__', None) parentmodule = safe_getattr(self.parent, '__module__', None) if module and module != parentmodule: classname = str(module) + '.' + str(classname) content = StringList([_('alias of :class:`%s`') % classname], source='') super().add_content(content, no_docstring=True) else: super().add_content(more_content)
Example #16
Source File: api_doc_gen.py From zenpy with GNU General Public License v3.0 | 5 votes |
def run(self): zenpy_client = Zenpy(subdomain="party", email="face@toe", password="Yer") node_list = [] cache_node = container() cache_sections = self.generate_cache_sections(zenpy_client) for cache_section in cache_sections: node = paragraph() self.state.nested_parse(StringList(cache_section.split('\n')), 0, node) node_list.append(node) node_list.append(cache_node) return node_list
Example #17
Source File: sphinx_cfg_options.py From tenpy with GNU General Public License v3.0 | 5 votes |
def _parse_inline(state, line, info): source = StringList([line], items=[info]) node = nodes.paragraph() state.nested_parse(source, 0, node) par = node[0] assert isinstance(node, nodes.paragraph) par = node[0] assert isinstance(node, nodes.paragraph) return par.children
Example #18
Source File: custom_directives.py From ray with Apache License 2.0 | 5 votes |
def run(self): # Cutoff the `tooltip` after 195 chars. if "tooltip" in self.options: tooltip = self.options["tooltip"] if len(self.options["tooltip"]) > 195: tooltip = tooltip[:195] + "..." else: raise ValueError("Need to provide :tooltip: under " "`.. customgalleryitem::`.") # Generate `thumbnail` used in the gallery. if "figure" in self.options: env = self.state.document.settings.env rel_figname, figname = env.relfn2path(self.options["figure"]) thumb_dir = os.path.join(env.srcdir, "_static/thumbs/") os.makedirs(thumb_dir, exist_ok=True) image_path = os.path.join(thumb_dir, os.path.basename(figname)) sphinx_gallery.gen_rst.scale_image(figname, image_path, 400, 280) thumbnail = os.path.relpath(image_path, env.srcdir) # https://stackoverflow.com/questions/52138336/sphinx-reference-to-an-image-from-different-locations thumbnail = "/" + thumbnail else: # "/" is the top level srcdir thumbnail = "/_static/img/thumbnails/default.png" if "description" in self.options: description = self.options["description"] else: raise ValueError("Need to provide :description: under " "`customgalleryitem::`.") thumbnail_rst = GALLERY_TEMPLATE.format( tooltip=tooltip, thumbnail=thumbnail, description=description) thumbnail = StringList(thumbnail_rst.split("\n")) thumb = nodes.paragraph() self.state.nested_parse(thumbnail, self.content_offset, thumb) return [thumb]
Example #19
Source File: directive.py From cotk with Apache License 2.0 | 5 votes |
def parse_generated_content(state: RSTState, content: StringList, documenter: Documenter ) -> List[Node]: """Parse a generated content by Documenter.""" with switch_source_input(state, content): if documenter.titles_allowed: node = nodes.section() # type: Element # necessary so that the child nodes get the right source/line set node.document = state.document nested_parse_with_titles(state, content, node) else: node = nodes.paragraph() node.document = state.document state.nested_parse(content, 0, node) return node.children
Example #20
Source File: directives.py From pennylane with Apache License 2.0 | 5 votes |
def run(self): try: if 'name' in self.options: name = self.options['name'] if 'description' in self.options: description = self.options['description'] else: raise ValueError('description not found') if 'link' in self.options: link = self.options['link'] else: link = "code/qml_templates" except FileNotFoundError as e: print(e) return [] except ValueError as e: print(e) raise return [] thumbnail_rst = TITLE_CARD_TEMPLATE.format(name=name, description=description, link=link) thumbnail = StringList(thumbnail_rst.split('\n')) thumb = nodes.paragraph() self.state.nested_parse(thumbnail, self.content_offset, thumb) return [thumb]
Example #21
Source File: sphinx_skl2onnx_extension.py From sklearn-onnx with MIT License | 5 votes |
def run(self): from sklearn import __version__ as skver found = missing_ops() nbconverters = 0 supported = set(build_sklearn_operator_name_map()) rows = [".. list-table::", " :header-rows: 1", " :widths: 10 7 4", "", " * - Name", " - Package", " - Supported"] for name, sub, cl in found: rows.append(" * - " + name) rows.append(" - " + sub) if cl in supported: rows.append(" - Yes") nbconverters += 1 else: rows.append(" -") rows.append("") rows.append("scikit-learn's version is **{0}**.".format(skver)) rows.append("{0}/{1} models are covered.".format(nbconverters, len(found))) node = nodes.container() st = StringList(rows) nested_parse_with_titles(self.state, st, node) main = nodes.container() main += node return [main]
Example #22
Source File: directives.py From pennylane with Apache License 2.0 | 5 votes |
def run(self): try: if 'figure' in self.options: thumbnail = self.options['figure'] else: thumbnail = '_static/thumbs/code.png' if 'description' in self.options: description = self.options['description'] else: raise ValueError('description not found') if 'link' in self.options: link = self.options['link'] else: link = "code/qml_templates" except FileNotFoundError as e: print(e) return [] except ValueError as e: print(e) raise return [] thumbnail_rst = GALLERY_TEMPLATE.format(thumbnail=thumbnail, description=description, link=link) thumbnail = StringList(thumbnail_rst.split('\n')) thumb = nodes.paragraph() self.state.nested_parse(thumbnail, self.content_offset, thumb) return [thumb]
Example #23
Source File: directives.py From pennylane with Apache License 2.0 | 5 votes |
def run(self): rst = USAGE_DETAILS_TEMPLATE.format(content="\n".join(self.content)) string_list = StringList(rst.split('\n')) node = nodes.section() self.state.nested_parse(string_list, self.content_offset, node) return [node]
Example #24
Source File: directives.py From pennylane-qiskit with Apache License 2.0 | 5 votes |
def run(self): try: if 'name' in self.options: name = self.options['name'] if 'description' in self.options: description = self.options['description'] else: raise ValueError('description not found') if 'link' in self.options: link = self.options['link'] else: link = "code/qml_templates" except FileNotFoundError as e: print(e) return [] except ValueError as e: print(e) raise return [] thumbnail_rst = GALLERY_TEMPLATE.format(name=name, description=description, link=link) thumbnail = StringList(thumbnail_rst.split('\n')) thumb = nodes.paragraph() self.state.nested_parse(thumbnail, self.content_offset, thumb) return [thumb]
Example #25
Source File: m2r.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse(self, inputstrings, document): if isinstance(inputstrings, statemachine.StringList): inputstring = '\n'.join(inputstrings) else: inputstring = inputstrings config = document.settings.env.config converter = M2R( no_underscore_emphasis=config.no_underscore_emphasis, parse_relative_links=config.m2r_parse_relative_links ) super(M2RParser, self).parse(converter(inputstring), document)
Example #26
Source File: renderers.py From sphinx-js with MIT License | 5 votes |
def __init__(self, directive, app, arguments=None, content=None, options=None): # Fix crash when calling eval_rst with CommonMarkParser: if not hasattr(directive.state.document.settings, 'tab_width'): directive.state.document.settings.tab_width = 8 self._directive = directive # content, arguments, options, app: all need to be accessible to # template_vars, so we bring them in on construction and stow them away # on the instance so calls to template_vars don't need to concern # themselves with what it needs. self._app = app self._partial_path, self._explicit_formal_params = PathVisitor().parse(arguments[0]) self._content = content or StringList() self._options = options or {}
Example #27
Source File: ext.py From safekit with MIT License | 5 votes |
def _nested_parse_paragraph(self, text): content = nodes.paragraph() self.state.nested_parse(StringList(text.split("\n")), 0, content) return content
Example #28
Source File: ext.py From safekit with MIT License | 5 votes |
def _nested_parse_paragraph(self, text): content = nodes.paragraph() self.state.nested_parse(StringList(text.split("\n")), 0, content) return content
Example #29
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 #30
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]