from docutils import nodes from added_value.pyobj_role import make_pyobj_role def make_repr_node(rawtext, app, prefixed_name, obj, parent, modname, options): """Render a Python object to text using the repr() function. :param rawtext: Text being replaced with link node. :param app: Sphinx application context :param prefixed_name: The dotted Python name for obj. :param obj: The Python object to be rendered to text. :param parent: The parent Python object of obj. :param module: The name of the module containing obj. :param options: Options dictionary passed to role func. """ text = repr(obj) node = nodes.Text(text, rawsource=rawtext) return node repr_role = make_pyobj_role(make_repr_node)
from docutils import nodes from added_value.pyobj_role import make_pyobj_role def make_literal_repr_node(rawtext, app, prefixed_name, obj, parent, modname, options): """Render a Python object to text using the repr() function. :param rawtext: Text being replaced with link node. :param app: Sphinx application context :param prefixed_name: The dotted Python name for obj. :param obj: The Python object to be rendered to text. :param parent: The parent Python object of obj. :param module: The name of the module containing obj. :param options: Options dictionary passed to role func. """ text = repr(obj) node = nodes.literal(text=text, rawsource=rawtext) return node literal_repr_role = make_pyobj_role(make_literal_repr_node)
from docutils import nodes from added_value.grammatical_conjunctions import list_conjunction, list_conjunction_parts from added_value.pyobj_role import make_pyobj_role def make_literal_all_items_node(rawtext, app, prefixed_name, obj, parent, modname, options): """Render a Python sequence as a comma-separated list, with an "and" for the final item. :param rawtext: Text being replaced with link node. :param app: Sphinx application context :param prefixed_name: The dotted Python name for obj. :param obj: The Python object to be rendered to text. :param parent: The parent Python object of obj. :param module: The name of the module containing obj. :param options: Options dictionary passed to role func. """ new_nodes = list_conjunction_parts( list(obj), separator=", ", conjunction=" and ", separator_factory=lambda o: nodes.Text(str(o)), item_factory=lambda o: nodes.literal(text=str(o))) return new_nodes literal_all_items_role = make_pyobj_role(make_literal_all_items_node)
from docutils import nodes from added_value.pyobj_role import make_pyobj_role def make_str_node(rawtext, app, prefixed_name, obj, parent, modname, options): """Render a Python object to text using the repr() function. :param rawtext: Text being replaced with link node. :param app: Sphinx application context :param prefixed_name: The dotted Python name for obj. :param obj: The Python object to be rendered to text. :param parent: The parent Python object of obj. :param module: The name of the module containing obj. :param options: Options dictionary passed to role func. """ text = str(obj) node = nodes.Text(text, rawsource=rawtext) return node str_role = make_pyobj_role(make_str_node)
from docutils import nodes from added_value.grammatical_conjunctions import list_conjunction from added_value.pyobj_role import make_pyobj_role def make_any_items_node(rawtext, app, prefixed_name, obj, parent, modname, options): """Render a Python sequence as a comma-separated list, with an "or" for the final item. :param rawtext: Text being replaced with link node. :param app: Sphinx application context :param prefixed_name: The dotted Python name for obj. :param obj: The Python object to be rendered to text. :param parent: The parent Python object of obj. :param module: The name of the module containing obj. :param options: Options dictionary passed to role func. """ text = list_conjunction(list(obj), "or") node = nodes.Text(text, rawsource=rawtext) return node any_items_role = make_pyobj_role(make_any_items_node)
from docutils import nodes from added_value.pyobj_role import make_pyobj_role def make_literal_str_node(rawtext, app, prefixed_name, obj, parent, modname, options): """Render a Python object to text using the str() function. :param rawtext: Text being replaced with link node. :param app: Sphinx application context :param prefixed_name: The dotted Python name for obj. :param obj: The Python object to be rendered to text. :param parent: The parent Python object of obj. :param module: The name of the module containing obj. :param options: Options dictionary passed to role func. """ text = repr(obj) node = nodes.literal(text=text, rawsource=rawtext) return node literal_str_role = make_pyobj_role(make_literal_str_node)