def __init__(self, document, termsize=None, **options):
nodes.NodeVisitor.__init__(self, document)
self.document = document
self.output = ''
self.lines = ['']
self.line = 0
self.indent_width = 2
self.termsize = termsize or get_terminal_size((80,20))
self.options = options
self.references = []
self.refcount = 0
self.ctx = self.Context()
self.ctx_stack = []
self.style = self.StyleContext()
self.style_stack = []
python类NodeVisitor()的实例源码
def __init__(self, document, builder):
nodes.NodeVisitor.__init__(self, document)
self.builder = builder
newlines = builder.config.text_newlines
if newlines == 'windows':
self.nl = '\r\n'
elif newlines == 'native':
self.nl = os.linesep
else:
self.nl = '\n'
self.sectionchars = builder.config.text_sectionchars
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.lineblocklevel = 0
self.table = None
def __init__(self, document, cols, rows, width):
nodes.NodeVisitor.__init__(self, document)
self.cols = cols
self.rows = rows
self.width = width
self.height = 0
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.level = 0
self.widths = []
self.heights = []
self.rows = 0
def __init__(self, props, document, **options):
nodes.NodeVisitor.__init__(self, document)
self.props = props
self.level = 0
self.line = 0
self.cursor = 0
self.col = 0
self.row = 0
self.nb_rows = 0
self.options = options
def __init__(self, document, builder, destination, docname, basepath):
nodes.NodeVisitor.__init__(self, document)
self.builder = builder
self.sectionlevel = 0
self.sectioncount = [0, 0, 0, 0, 0, 0]
self.contents = []; #[
self.destination = destination
self.docname = docname
self.basepath = basepath
self.state = ['regular']
def _make_visit_admonition(name):
def visit_admonition(self, node):
# type: (nodes.NodeVisitor, nodes.Node) -> None
# self.end_state(first=admonitionlabels[name] + ': ')
info("visit", node)
return visit_admonition
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, *args, **kw):
nodes.NodeVisitor.__init__(self, *args, **kw)
self.result = []
self.article = Article()
self._main_title_visited = False
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, document, builder):
nodes.NodeVisitor.__init__(self, document)
self.builder = builder
self.init_settings()
self.written_ids = set() # node names and anchors in output
# node names and anchors that should be in output
self.referenced_ids = set()
self.indices = [] # (node name, content)
self.short_ids = {} # anchors --> short ids
self.node_names = {} # node name --> node's name to display
self.node_menus = {} # node name --> node's menu entries
self.rellinks = {} # node name --> (next, previous, up)
self.collect_indices()
self.collect_node_names()
self.collect_node_menus()
self.collect_rellinks()
self.body = []
self.context = []
self.previous_section = None
self.section_level = 0
self.seen_title = False
self.next_section_ids = set()
self.escape_newlines = 0
self.escape_hyphens = 0
self.curfilestack = []
self.footnotestack = []
self.in_footnote = 0
self.handled_abbrs = set()
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.body = []
self.section_level = 0
self.par_level = -1
self.lists = [] # stack of the currents bullets
self.listLevel = len(self.lists)
self.bullet = '*' # next one to add to the next paragraph
self.figures = 0 # Counts figures for reference targets
self.inTable = False
self.turnsInList = 0
self.inDesc = False
self.inList = False
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self._found = False
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def render_symbol_html(self, node, code, options, prefix='symbol',
imgcls=None, alt=None):
# type: (nodes.NodeVisitor, symbolator, unicode, Dict, unicode, unicode, unicode) -> Tuple[unicode, unicode] # NOQA
format = self.builder.config.symbolator_output_format
try:
if format not in ('png', 'svg'):
raise SymbolatorError("symbolator_output_format must be one of 'png', "
"'svg', but is %r" % format)
fname, outfn = render_symbol(self, code, options, format, prefix)
except SymbolatorError as exc:
logger.warning('symbolator code %r: ' % code + str(exc))
raise nodes.SkipNode
if fname is None:
self.body.append(self.encode(code))
else:
if alt is None:
alt = node.get('alt', self.encode(code).strip())
imgcss = imgcls and 'class="%s"' % imgcls or ''
if format == 'svg':
svgtag = '''<object data="%s" type="image/svg+xml">
<p class="warning">%s</p></object>\n''' % (fname, alt)
self.body.append(svgtag)
else:
if 'align' in node:
self.body.append('<div align="%s" class="align-%s">' %
(node['align'], node['align']))
self.body.append('<img src="%s" alt="%s" %s/>\n' %
(fname, alt, imgcss))
if 'align' in node:
self.body.append('</div>\n')
raise nodes.SkipNode
def html_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
render_symbol_html(self, node, node['code'], node['options'])
def render_symbol_latex(self, node, code, options, prefix='symbol'):
# type: (nodes.NodeVisitor, symbolator, unicode, Dict, unicode) -> None
try:
fname, outfn = render_symbol(self, code, options, 'pdf', prefix)
except SymbolatorError as exc:
logger.warning('symbolator code %r: ' % code + str(exc))
raise nodes.SkipNode
is_inline = self.is_inline(node)
if is_inline:
para_separator = ''
else:
para_separator = '\n'
if fname is not None:
post = None # type: unicode
if not is_inline and 'align' in node:
if node['align'] == 'left':
self.body.append('{')
post = '\\hspace*{\\fill}}'
elif node['align'] == 'right':
self.body.append('{\\hspace*{\\fill}')
post = '}'
self.body.append('%s\\includegraphics{%s}%s' %
(para_separator, fname, para_separator))
if post:
self.body.append(post)
raise nodes.SkipNode
def latex_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
render_symbol_latex(self, node, node['code'], node['options'])
def texinfo_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
render_symbol_texinfo(self, node, node['code'], node['options'])
def text_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
if 'alt' in node.attributes:
self.add_text(_('[symbol: %s]') % node['alt'])
else:
self.add_text(_('[symbol]'))
raise nodes.SkipNode
def man_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
if 'alt' in node.attributes:
self.body.append(_('[symbol: %s]') % node['alt'])
else:
self.body.append(_('[symbol]'))
raise nodes.SkipNode
textwriter.py 文件源码
项目:tf_aws_ecs_instance_draining_on_scale_in
作者: terraform-community-modules
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
def __init__(self, props, document, **options):
nodes.NodeVisitor.__init__(self, document)
self.props = props
self.level = 0
self.lines = ['']
self.line = 0
self.cursor = 0
self.col = 0
self.row = 0
self.nb_rows = 0
self.options = options
def unicode_intersection(char, next):
switch = {
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
(' ', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
('?', '?'): '?',
(' ', '?'): '?',
('?', '?'): '?',
}
return switch[(u(char), u(next))]
if options.get('unicode', False):
self.char_single_rule = '?'
self.char_double_rule = '?'
self.char_vertical_rule = '?'
self.get_intersection = unicode_intersection
self.top_left = '?'
self.top_right = '?'
self.bottom_left = '?'
else:
self.char_single_rule = '-'
self.char_double_rule = '='
self.char_vertical_rule = '|'
self.get_intersection = lambda *args: '+'
self.top_left = self.bottom_left = self.top_right = '+'
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.settings = settings = document.settings
lcode = settings.language_code
self.language = languages.get_language(lcode, document.reporter)
self.meta = [self.generator % docutils.__version__]
self.head_prefix = []
self.html_prolog = []
if settings.xml_declaration:
self.head_prefix.append(self.xml_declaration
% settings.output_encoding)
# self.content_type = ""
# encoding not interpolated:
self.html_prolog.append(self.xml_declaration)
self.head = self.meta[:]
self.stylesheet = [self.stylesheet_call(path)
for path in utils.get_stylesheet_list(settings)]
self.body_prefix = ['</head>\n<body>\n']
# document title, subtitle display
self.body_pre_docinfo = []
# author, date, etc.
self.docinfo = []
self.body = []
self.fragment = []
self.body_suffix = ['</body>\n</html>\n']
self.section_level = 0
self.initial_header_level = int(settings.initial_header_level)
self.math_output = settings.math_output.split()
self.math_output_options = self.math_output[1:]
self.math_output = self.math_output[0].lower()
# A heterogenous stack used in conjunction with the tree traversal.
# Make sure that the pops correspond to the pushes:
self.context = []
self.topic_classes = [] # TODO: replace with self_in_contents
self.colspecs = []
self.compact_p = True
self.compact_simple = False
self.compact_field_list = False
self.in_docinfo = False
self.in_sidebar = False
self.in_footnote_list = False
self.title = []
self.subtitle = []
self.header = []
self.footer = []
self.html_head = [self.content_type] # charset not interpolated
self.html_title = []
self.html_subtitle = []
self.html_body = []
self.in_document_title = 0 # len(self.body) or 0
self.in_mailto = False
self.author_in_authors = False # for html4css1
self.math_header = []
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.settings = settings = document.settings
lcode = settings.language_code
self.language = languages.get_language(lcode, document.reporter)
self.meta = [self.generator % docutils.__version__]
self.head_prefix = []
self.html_prolog = []
if settings.xml_declaration:
self.head_prefix.append(self.xml_declaration
% settings.output_encoding)
# self.content_type = ""
# encoding not interpolated:
self.html_prolog.append(self.xml_declaration)
self.head = self.meta[:]
self.stylesheet = [self.stylesheet_call(path)
for path in utils.get_stylesheet_list(settings)]
self.body_prefix = ['</head>\n<body>\n']
# document title, subtitle display
self.body_pre_docinfo = []
# author, date, etc.
self.docinfo = []
self.body = []
self.fragment = []
self.body_suffix = ['</body>\n</html>\n']
self.section_level = 0
self.initial_header_level = int(settings.initial_header_level)
self.math_output = settings.math_output.split()
self.math_output_options = self.math_output[1:]
self.math_output = self.math_output[0].lower()
self.context = []
"""Heterogeneous stack.
Used by visit_* and depart_* functions in conjunction with the tree
traversal. Make sure that the pops correspond to the pushes."""
self.topic_classes = [] # TODO: replace with self_in_contents
self.colspecs = []
self.compact_p = True
self.compact_simple = False
self.compact_field_list = False
self.in_docinfo = False
self.in_sidebar = False
self.in_footnote_list = False
self.title = []
self.subtitle = []
self.header = []
self.footer = []
self.html_head = [self.content_type] # charset not interpolated
self.html_title = []
self.html_subtitle = []
self.html_body = []
self.in_document_title = 0 # len(self.body) or 0
self.in_mailto = False
self.author_in_authors = False # for html4css1
self.math_header = []
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.settings = settings = document.settings
lcode = settings.language_code
self.language = languages.get_language(lcode, document.reporter)
self.meta = [self.generator % docutils.__version__]
self.head_prefix = []
self.html_prolog = []
if settings.xml_declaration:
self.head_prefix.append(self.xml_declaration
% settings.output_encoding)
# encoding not interpolated:
self.html_prolog.append(self.xml_declaration)
self.head = self.meta[:]
self.stylesheet = [self.stylesheet_call(path)
for path in utils.get_stylesheet_list(settings)]
self.body_prefix = ['</head>\n<body>\n']
# document title, subtitle display
self.body_pre_docinfo = []
# author, date, etc.
self.docinfo = []
self.body = []
self.fragment = []
self.body_suffix = ['</body>\n</html>\n']
self.section_level = 0
self.initial_header_level = int(settings.initial_header_level)
self.math_output = settings.math_output.split()
self.math_output_options = self.math_output[1:]
self.math_output = self.math_output[0].lower()
# A heterogenous stack used in conjunction with the tree traversal.
# Make sure that the pops correspond to the pushes:
self.context = []
self.topic_classes = []
self.colspecs = []
self.compact_p = True
self.compact_simple = False
self.compact_field_list = False
self.in_docinfo = False
self.in_sidebar = False
self.title = []
self.subtitle = []
self.header = []
self.footer = []
self.html_head = [self.content_type] # charset not interpolated
self.html_title = []
self.html_subtitle = []
self.html_body = []
self.in_document_title = 0 # len(self.body) or 0
self.in_mailto = False
self.author_in_authors = False
self.math_header = []