desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Translate docutils encoding name into latex\'s.
Default fallback method is remove "-" and "_" chars from docutils_encoding.'
| def to_latex_encoding(self, docutils_encoding):
| tr = {'iso-8859-1': 'latin1', 'iso-8859-2': 'latin2', 'iso-8859-3': 'latin3', 'iso-8859-4': 'latin4', 'iso-8859-5': 'iso88595', 'iso-8859-9': 'latin5', 'iso-8859-15': 'latin9', 'mac_cyrillic': 'maccyr', 'windows-1251': 'cp1251', 'koi8-r': 'koi8-r', 'koi8-u': 'koi8-u', 'windows-1250': 'cp1250', 'windows-1252': 'cp12... |
'Encode special characters (``# $ % & ~ _ ^ \ { }``) in `text` & return'
| def encode(self, text):
| if self.verbatim:
return text
if (not self.__dict__.has_key('encode_re_braces')):
self.encode_re_braces = re.compile('([{}])')
text = self.encode_re_braces.sub('{\\\\\\1}', text)
if (not self.__dict__.has_key('encode_re_bslash')):
self.encode_re_bslash = re.compile('(?<!{)(\\\\)(... |
'Cleanse, encode, and return attribute value text.'
| def attval(self, text, whitespace=re.compile('[\n\r DCTB \x0b\x0c]')):
| return self.encode(whitespace.sub(' ', text))
|
'Render a literal-block.
Literal blocks are used for "::"-prefixed literal-indented
blocks of text, where the inline markup is not recognized,
but are also the product of the parsed-literal directive,
where the markup is respected.'
| def visit_literal_block(self, node):
| if (not self.active_table.is_open()):
self.body.append('\\begin{quote}')
self.context.append('\\end{quote}\n')
else:
self.body.append('\n')
self.context.append('\n')
if (self.settings.use_verbatim_when_possible and (len(node) == 1) and isinstance(node[0], nodes.Text)):
... |
'The delimiter betweeen an option and its argument.'
| def visit_option_argument(self, node):
| self.body.append(node.get('delimiter', ' '))
|
'Append latex href and pdfbookmarks for titles.'
| def bookmark(self, node):
| if node.parent['ids']:
for id in node.parent['ids']:
self.body.append(('\\hypertarget{%s}{}\n' % id))
if (not self.use_latex_toc):
l = self.section_level
if (l > 0):
l = (l - 1)
text = self.encode(node.astext())
for id in no... |
'Section and other titles.'
| def visit_title(self, node):
| if isinstance(node.parent, nodes.topic):
self.bookmark(node)
if (('contents' in self.topic_classes) and self.use_latex_toc):
self.body.append('\\renewcommand{\\contentsname}{')
self.context.append('}\n\\tableofcontents\n\n\\bigskip\n')
elif (('abstract' in self.topic_... |
'This writer supports all format-specific elements.'
| def supports(self, format):
| return 1
|
'Override to parse `inputstring` into document tree `document`.'
| def parse(self, inputstring, document):
| raise NotImplementedError('subclass must override this method')
|
'Initial parse setup. Call at start of `self.parse()`.'
| def setup_parse(self, inputstring, document):
| self.inputstring = inputstring
self.document = document
document.reporter.attach_observer(document.note_parse_message)
|
'Finalize parse details. Call at end of `self.parse()`.'
| def finish_parse(self):
| self.document.reporter.detach_observer(self.document.note_parse_message)
|
'Parse `input_lines` and modify the `document` node in place.
Extend `StateMachineWS.run()`: set up parse-global data and
run the StateMachine.'
| def run(self, input_lines, document, input_offset=0, match_titles=1, inliner=None):
| self.language = languages.get_language(document.settings.language_code)
self.match_titles = match_titles
if (inliner is None):
inliner = Inliner()
inliner.init_customizations(document.settings)
self.memo = Struct(document=document, reporter=document.reporter, language=self.language, title_st... |
'Parse `input_lines` and populate a `docutils.nodes.document` instance.
Extend `StateMachineWS.run()`: set up document-wide data.'
| def run(self, input_lines, input_offset, memo, node, match_titles=1):
| self.match_titles = match_titles
self.memo = memo
self.document = memo.document
self.attach_observer(self.document.note_source)
self.reporter = memo.reporter
self.language = memo.language
self.node = node
results = StateMachineWS.run(self, input_lines, input_offset)
assert (results =... |
'Jump to input line `abs_line_offset`, ignoring jumps past the end.'
| def goto_line(self, abs_line_offset):
| try:
self.state_machine.goto_line(abs_line_offset)
except EOFError:
pass
|
'Override `StateWS.no_match` to generate a system message.
This code should never be run.'
| def no_match(self, context, transitions):
| self.reporter.severe(('Internal error: no transition pattern match. State: "%s"; transitions: %s; context: %s; current line: %r.' % (self.__class__.__name__, transitions, context, self.state_machine.line)), line=self.state_machine.abs_line_number())
return (context,... |
'Called at beginning of file.'
| def bof(self, context):
| return ([], [])
|
'Create a new StateMachine rooted at `node` and run it over the input
`block`.'
| def nested_parse(self, block, input_offset, node, match_titles=0, state_machine_class=None, state_machine_kwargs=None):
| if (state_machine_class is None):
state_machine_class = self.nested_sm
if (state_machine_kwargs is None):
state_machine_kwargs = self.nested_sm_kwargs
block_length = len(block)
state_machine = state_machine_class(debug=self.debug, **state_machine_kwargs)
state_machine.run(block, inpu... |
'Create a new StateMachine rooted at `node` and run it over the input
`block`. Also keep track of optional intermediate blank lines and the
required final one.'
| def nested_list_parse(self, block, input_offset, node, initial_state, blank_finish, blank_finish_state=None, extra_settings={}, match_titles=0, state_machine_class=None, state_machine_kwargs=None):
| if (state_machine_class is None):
state_machine_class = self.nested_sm
if (state_machine_kwargs is None):
state_machine_kwargs = self.nested_sm_kwargs.copy()
state_machine_kwargs['initial_state'] = initial_state
state_machine = state_machine_class(debug=self.debug, **state_machine_kwargs... |
'Check for a valid subsection and create one if it checks out.'
| def section(self, title, source, style, lineno, messages):
| if self.check_subsection(source, style, lineno):
self.new_subsection(title, lineno, messages)
|
'Check for a valid subsection header. Return 1 (true) or None (false).
When a new section is reached that isn\'t a subsection of the current
section, back up the line count (use ``previous_line(-x)``), then
``raise EOFError``. The current StateMachine will finish, then the
calling StateMachine can re-examine the titl... | def check_subsection(self, source, style, lineno):
| memo = self.memo
title_styles = memo.title_styles
mylevel = memo.section_level
try:
level = (title_styles.index(style) + 1)
except ValueError:
if (len(title_styles) == memo.section_level):
title_styles.append(style)
return 1
else:
self.pare... |
'Append new subsection to document tree. On return, check level.'
| def new_subsection(self, title, lineno, messages):
| memo = self.memo
mylevel = memo.section_level
memo.section_level += 1
section_node = nodes.section()
self.parent += section_node
(textnodes, title_messages) = self.inline_text(title, lineno)
titlenode = nodes.title(title, '', *textnodes)
name = normalize_name(titlenode.astext())
sect... |
'Return a list (paragraph & messages) & a boolean: literal_block next?'
| def paragraph(self, lines, lineno):
| data = '\n'.join(lines).rstrip()
if re.search('(?<!\\\\)(\\\\\\\\)*::$', data):
if (len(data) == 2):
return ([], 1)
elif (data[(-3)] in ' \n'):
text = data[:(-3)].rstrip()
else:
text = data[:(-1)]
literalnext = 1
else:
text = dat... |
'Return 2 lists: nodes (text and inline elements), and system_messages.'
| def inline_text(self, text, lineno):
| return self.inliner.parse(text, lineno, self.memo, self.parent)
|
'Setting-based customizations; run when parsing begins.'
| def init_customizations(self, settings):
| if settings.pep_references:
self.implicit_dispatch.append((self.patterns.pep, self.pep_reference))
if settings.rfc_references:
self.implicit_dispatch.append((self.patterns.rfc, self.rfc_reference))
|
'Return 2 lists: nodes (text and inline elements), and system_messages.
Using `self.patterns.initial`, a pattern which matches start-strings
(emphasis, strong, interpreted, phrase reference, literal,
substitution reference, and inline target) and complete constructs
(simple reference, footnote reference), search for a ... | def parse(self, text, lineno, memo, parent):
| self.reporter = memo.reporter
self.document = memo.document
self.language = memo.language
self.parent = parent
pattern_search = self.patterns.initial.search
dispatch = self.dispatch
remaining = escape2null(text)
processed = []
unprocessed = []
messages = []
while remaining:
... |
'Return 1 if inline markup start-string is \'quoted\', 0 if not.'
| def quoted_start(self, match):
| string = match.string
start = match.start()
end = match.end()
if (start == 0):
return 0
prestart = string[(start - 1)]
try:
poststart = string[end]
if (self.openers.index(prestart) == self.closers.index(poststart)):
return 1
except IndexError:
retu... |
'Handles `nodes.footnote_reference` and `nodes.citation_reference`
elements.'
| def footnote_reference(self, match, lineno):
| label = match.group('footnotelabel')
refname = normalize_name(label)
string = match.string
before = string[:match.start('whole')]
remaining = string[match.end('whole'):]
if match.group('citationlabel'):
refnode = nodes.citation_reference(('[%s]_' % label), refname=refname)
refnod... |
'Check each of the patterns in `self.implicit_dispatch` for a match,
and dispatch to the stored method for the pattern. Recursively check
the text before and after the match. Return a list of `nodes.Text`
and inline element nodes.'
| def implicit_inline(self, text, lineno):
| if (not text):
return []
for (pattern, method) in self.implicit_dispatch:
match = pattern.search(text)
if match:
try:
return ((self.implicit_inline(text[:match.start()], lineno) + method(match, lineno)) + self.implicit_inline(text[match.end():], lineno))
... |
'Block quote.'
| def indent(self, match, context, next_state):
| (indented, indent, line_offset, blank_finish) = self.state_machine.get_indented()
elements = self.block_quote(indented, line_offset)
self.parent += elements
if (not blank_finish):
self.parent += self.unindent_warning('Block quote')
return (context, next_state, [])
|
'Check for a block quote attribution and split it off:
* First line after a blank line must begin with a dash ("--", "---",
em-dash; matches `self.attribution_pattern`).
* Every line after that must have consistent indentation.
* Attributions must be preceded by block quote content.
Return a tuple of: (block quote cont... | def split_attribution(self, indented, line_offset):
| blank = None
nonblank_seen = False
for i in range(len(indented)):
line = indented[i].rstrip()
if line:
if (nonblank_seen and (blank == (i - 1))):
match = self.attribution_pattern.match(line)
if match:
(attribution_end, indent) =... |
'Check attribution shape.
Return the index past the end of the attribution, and the indent.'
| def check_attribution(self, indented, attribution_start):
| indent = None
i = (attribution_start + 1)
for i in range((attribution_start + 1), len(indented)):
line = indented[i].rstrip()
if (not line):
break
if (indent is None):
indent = (len(line) - len(line.lstrip()))
elif ((len(line) - len(line.lstrip())) != ... |
'Bullet list item.'
| def bullet(self, match, context, next_state):
| bulletlist = nodes.bullet_list()
self.parent += bulletlist
bulletlist['bullet'] = match.string[0]
(i, blank_finish) = self.list_item(match.end())
bulletlist += i
offset = (self.state_machine.line_offset + 1)
(new_line_offset, blank_finish) = self.nested_list_parse(self.state_machine.input_li... |
'Enumerated List Item'
| def enumerator(self, match, context, next_state):
| (format, sequence, text, ordinal) = self.parse_enumerator(match)
if (not self.is_enumerated_list_item(ordinal, sequence, format)):
raise statemachine.TransitionCorrection('text')
enumlist = nodes.enumerated_list()
self.parent += enumlist
if (sequence == '#'):
enumlist['enumtype'] = '... |
'Analyze an enumerator and return the results.
:Return:
- the enumerator format (\'period\', \'parens\', or \'rparen\'),
- the sequence used (\'arabic\', \'loweralpha\', \'upperroman\', etc.),
- the text of the enumerator, stripped of formatting, and
- the ordinal value of the enumerator (\'a\' -> 1, \'ii\' -> 2, etc.;... | def parse_enumerator(self, match, expected_sequence=None):
| groupdict = match.groupdict()
sequence = ''
for format in self.enum.formats:
if groupdict[format]:
break
else:
raise ParserError('enumerator format not matched')
text = groupdict[format][self.enum.formatinfo[format].start:self.enum.formatinfo[format].end]
if ... |
'Check validity based on the ordinal value and the second line.
Return true iff the ordinal is valid and the second line is blank,
indented, or starts with the next enumerator or an auto-enumerator.'
| def is_enumerated_list_item(self, ordinal, sequence, format):
| if (ordinal is None):
return None
try:
next_line = self.state_machine.next_line()
except EOFError:
self.state_machine.previous_line()
return 1
else:
self.state_machine.previous_line()
if (not next_line[:1].strip()):
return 1
result = self.make_enum... |
'Construct and return the next enumerated list item marker, and an
auto-enumerator ("#" instead of the regular enumerator).
Return ``None`` for invalid (out of range) ordinals.'
| def make_enumerator(self, ordinal, sequence, format):
| if (sequence == '#'):
enumerator = '#'
elif (sequence == 'arabic'):
enumerator = str(ordinal)
else:
if sequence.endswith('alpha'):
if (ordinal > 26):
return None
enumerator = chr(((ordinal + ord('a')) - 1))
elif sequence.endswith('roman... |
'Field list item.'
| def field_marker(self, match, context, next_state):
| field_list = nodes.field_list()
self.parent += field_list
(field, blank_finish) = self.field(match)
field_list += field
offset = (self.state_machine.line_offset + 1)
(newline_offset, blank_finish) = self.nested_list_parse(self.state_machine.input_lines[offset:], input_offset=(self.state_machine.... |
'Extract & return field name from a field marker match.'
| def parse_field_marker(self, match):
| field = match.group()[1:]
field = field[:field.rfind(':')]
return field
|
'Option list item.'
| def option_marker(self, match, context, next_state):
| optionlist = nodes.option_list()
try:
(listitem, blank_finish) = self.option_list_item(match)
except MarkupError as (message, lineno):
msg = self.reporter.error(('Invalid option list marker: %s' % message), line=lineno)
self.parent += msg
(indented, indent, line_o... |
'Return a list of `node.option` and `node.option_argument` objects,
parsed from an option marker match.
:Exception: `MarkupError` for invalid option markers.'
| def parse_option_marker(self, match):
| optlist = []
optionstrings = match.group().rstrip().split(', ')
for optionstring in optionstrings:
tokens = optionstring.split()
delimiter = ' '
firstopt = tokens[0].split('=')
if (len(firstopt) > 1):
tokens[:1] = firstopt
delimiter = '='
... |
'First line of a line block.'
| def line_block(self, match, context, next_state):
| block = nodes.line_block()
self.parent += block
lineno = self.state_machine.abs_line_number()
(line, messages, blank_finish) = self.line_block_line(match, lineno)
block += line
self.parent += messages
if (not blank_finish):
offset = (self.state_machine.line_offset + 1)
(new_l... |
'Return one line element of a line_block.'
| def line_block_line(self, match, lineno):
| (indented, indent, line_offset, blank_finish) = self.state_machine.get_first_known_indented(match.end(), until_blank=1)
text = u'\n'.join(indented)
(text_nodes, messages) = self.inline_text(text, lineno)
line = nodes.line(text, '', *text_nodes)
if (match.string.rstrip() != '|'):
line.indent ... |
'Top border of a full table.'
| def grid_table_top(self, match, context, next_state):
| return self.table_top(match, context, next_state, self.isolate_grid_table, tableparser.GridTableParser)
|
'Top border of a simple table.'
| def simple_table_top(self, match, context, next_state):
| return self.table_top(match, context, next_state, self.isolate_simple_table, tableparser.SimpleTableParser)
|
'Top border of a generic table.'
| def table_top(self, match, context, next_state, isolate_function, parser_class):
| (nodelist, blank_finish) = self.table(isolate_function, parser_class)
self.parent += nodelist
if (not blank_finish):
msg = self.reporter.warning('Blank line required after table.', line=(self.state_machine.abs_line_number() + 1))
self.parent += msg
return ([], next_state, [])... |
'Parse a table.'
| def table(self, isolate_function, parser_class):
| (block, messages, blank_finish) = isolate_function()
if block:
try:
parser = parser_class()
tabledata = parser.parse(block)
tableline = ((self.state_machine.abs_line_number() - len(block)) + 1)
table = self.build_table(tabledata, tableline)
nod... |
'Determine the type of reference of a target.
:Return: A 2-tuple, one of:
- \'refname\' and the indirect reference name
- \'refuri\' and the URI
- \'malformed\' and a system_message node'
| def parse_target(self, block, block_text, lineno):
| if (block and (block[(-1)].strip()[(-1):] == '_')):
reference = ' '.join([line.strip() for line in block])
refname = self.is_reference(reference)
if refname:
return ('refname', refname)
reference = ''.join([''.join(line.split()) for line in block])
return ('refuri', un... |
'Returns a 2-tuple: list of nodes, and a "blank finish" boolean.'
| def directive(self, match, **option_presets):
| type_name = match.group(1)
(directive_class, messages) = directives.directive(type_name, self.memo.language, self.document)
self.parent += messages
if directive_class:
return self.run_directive(directive_class, match, type_name, option_presets)
else:
return self.unknown_directive(typ... |
'Parse a directive then run its directive function.
Parameters:
- `directive`: The class implementing the directive. Must be
a subclass of `rst.Directive`.
- `match`: A regular expression match object which matched the first
line of the directive.
- `type_name`: The directive name, as used in the source text.
- `optio... | def run_directive(self, directive, match, type_name, option_presets):
| if isinstance(directive, (FunctionType, MethodType)):
from docutils.parsers.rst import convert_directive_function
directive = convert_directive_function(directive)
lineno = self.state_machine.abs_line_number()
initial_line_offset = self.state_machine.line_offset
(indented, indent, line_o... |
'Parse `datalines` for a field list containing extension options
matching `option_spec`.
:Parameters:
- `option_spec`: a mapping of option name to conversion
function, which should raise an exception on bad input.
- `datalines`: a list of input strings.
:Return:
- Success value, 1 or 0.
- An option dictionary on succes... | def parse_extension_options(self, option_spec, datalines):
| node = nodes.field_list()
(newline_offset, blank_finish) = self.nested_list_parse(datalines, 0, node, initial_state='ExtensionOptions', blank_finish=1)
if (newline_offset != len(datalines)):
return (0, 'invalid option block')
try:
options = utils.extract_extension_options(node, opt... |
'Footnotes, hyperlink targets, directives, comments.'
| def explicit_markup(self, match, context, next_state):
| (nodelist, blank_finish) = self.explicit_construct(match)
self.parent += nodelist
self.explicit_list(blank_finish)
return ([], next_state, [])
|
'Determine which explicit construct this is, parse & return it.'
| def explicit_construct(self, match):
| errors = []
for (method, pattern) in self.explicit.constructs:
expmatch = pattern.match(match.string)
if expmatch:
try:
return method(self, expmatch)
except MarkupError as (message, lineno):
errors.append(self.reporter.warning(message, line... |
'Create a nested state machine for a series of explicit markup
constructs (including anonymous hyperlink targets).'
| def explicit_list(self, blank_finish):
| offset = (self.state_machine.line_offset + 1)
(newline_offset, blank_finish) = self.nested_list_parse(self.state_machine.input_lines[offset:], input_offset=(self.state_machine.abs_line_offset() + 1), node=self.parent, initial_state='Explicit', blank_finish=blank_finish, match_titles=self.state_machine.match_tit... |
'Anonymous hyperlink targets.'
| def anonymous(self, match, context, next_state):
| (nodelist, blank_finish) = self.anonymous_target(match)
self.parent += nodelist
self.explicit_list(blank_finish)
return ([], next_state, [])
|
'Section title overline or transition marker.'
| def line(self, match, context, next_state):
| if self.state_machine.match_titles:
return ([match.string], 'Line', [])
elif (match.string.strip() == '::'):
raise statemachine.TransitionCorrection('text')
elif (len(match.string.strip()) < 4):
msg = self.reporter.info("Unexpected possible title overline or transition... |
'Titles, definition lists, paragraphs.'
| def text(self, match, context, next_state):
| return ([match.string], 'Text', [])
|
'RFC2822-style field list item.'
| def rfc2822(self, match, context, next_state):
| fieldlist = nodes.field_list(classes=['rfc2822'])
self.parent += fieldlist
(field, blank_finish) = self.rfc2822_field(match)
fieldlist += field
offset = (self.state_machine.line_offset + 1)
(newline_offset, blank_finish) = self.nested_list_parse(self.state_machine.input_lines[offset:], input_off... |
'Not a compound element member. Abort this state machine.'
| def invalid_input(self, match=None, context=None, next_state=None):
| self.state_machine.previous_line()
raise EOFError
|
'Bullet list item.'
| def bullet(self, match, context, next_state):
| if (match.string[0] != self.parent['bullet']):
self.invalid_input()
(listitem, blank_finish) = self.list_item(match.end())
self.parent += listitem
self.blank_finish = blank_finish
return ([], next_state, [])
|
'Definition lists.'
| def text(self, match, context, next_state):
| return ([match.string], 'Definition', [])
|
'Enumerated list item.'
| def enumerator(self, match, context, next_state):
| (format, sequence, text, ordinal) = self.parse_enumerator(match, self.parent['enumtype'])
if ((format != self.format) or ((sequence != '#') and ((sequence != self.parent['enumtype']) or self.auto or (ordinal != (self.lastordinal + 1)))) or (not self.is_enumerated_list_item(ordinal, sequence, format))):
... |
'Field list field.'
| def field_marker(self, match, context, next_state):
| (field, blank_finish) = self.field(match)
self.parent += field
self.blank_finish = blank_finish
return ([], next_state, [])
|
'Option list item.'
| def option_marker(self, match, context, next_state):
| try:
(option_list_item, blank_finish) = self.option_list_item(match)
except MarkupError as (message, lineno):
self.invalid_input()
self.parent += option_list_item
self.blank_finish = blank_finish
return ([], next_state, [])
|
'RFC2822-style field list item.'
| def rfc2822(self, match, context, next_state):
| (field, blank_finish) = self.rfc2822_field(match)
self.parent += field
self.blank_finish = blank_finish
return ([], 'RFC2822List', [])
|
'Override `Body.parse_field_body` for simpler parsing.'
| def parse_field_body(self, indented, offset, node):
| lines = []
for line in (list(indented) + ['']):
if line.strip():
lines.append(line)
elif lines:
text = '\n'.join(lines)
node += nodes.paragraph(text, text)
lines = []
|
'New line of line block.'
| def line_block(self, match, context, next_state):
| lineno = self.state_machine.abs_line_number()
(line, messages, blank_finish) = self.line_block_line(match, lineno)
self.parent += line
self.parent.parent += messages
self.blank_finish = blank_finish
return ([], next_state, [])
|
'Footnotes, hyperlink targets, directives, comments.'
| def explicit_markup(self, match, context, next_state):
| (nodelist, blank_finish) = self.explicit_construct(match)
self.parent += nodelist
self.blank_finish = blank_finish
return ([], next_state, [])
|
'Anonymous hyperlink targets.'
| def anonymous(self, match, context, next_state):
| (nodelist, blank_finish) = self.anonymous_target(match)
self.parent += nodelist
self.blank_finish = blank_finish
return ([], next_state, [])
|
'End of paragraph.'
| def blank(self, match, context, next_state):
| (paragraph, literalnext) = self.paragraph(context, (self.state_machine.abs_line_number() - 1))
self.parent += paragraph
if literalnext:
self.parent += self.literal_block()
return ([], 'Body', [])
|
'Definition list item.'
| def indent(self, match, context, next_state):
| definitionlist = nodes.definition_list()
(definitionlistitem, blank_finish) = self.definition_list_item(context)
definitionlist += definitionlistitem
self.parent += definitionlist
offset = (self.state_machine.line_offset + 1)
(newline_offset, blank_finish) = self.nested_list_parse(self.state_mac... |
'Section title.'
| def underline(self, match, context, next_state):
| lineno = self.state_machine.abs_line_number()
title = context[0].rstrip()
underline = match.string.rstrip()
source = ((title + '\n') + underline)
messages = []
if (column_width(title) > len(underline)):
if (len(underline) < 4):
if self.state_machine.match_titles:
... |
'Paragraph.'
| def text(self, match, context, next_state):
| startline = (self.state_machine.abs_line_number() - 1)
msg = None
try:
block = self.state_machine.get_text_block(flush_left=1)
except statemachine.UnexpectedIndentationError as instance:
(block, source, lineno) = instance.args
msg = self.reporter.error('Unexpected indentation.... |
'Return a list of nodes.'
| def literal_block(self):
| (indented, indent, offset, blank_finish) = self.state_machine.get_indented()
while (indented and (not indented[(-1)].strip())):
indented.trim_end()
if (not indented):
return self.quoted_literal_block()
data = '\n'.join(indented)
literal_block = nodes.literal_block(data, data)
lit... |
'Return a definition_list\'s term and optional classifiers.'
| def term(self, lines, lineno):
| assert (len(lines) == 1)
(text_nodes, messages) = self.inline_text(lines[0], lineno)
term_node = nodes.term()
node_list = [term_node]
for i in range(len(text_nodes)):
node = text_nodes[i]
if isinstance(node, nodes.Text):
parts = self.classifier_delimiter.split(node.rawsou... |
'Incomplete construct.'
| def eof(self, context):
| return []
|
'Not a compound element member. Abort this state machine.'
| def invalid_input(self, match=None, context=None, next_state=None):
| raise EOFError
|
'Not a definition.'
| def eof(self, context):
| self.state_machine.previous_line(2)
return []
|
'Definition list item.'
| def indent(self, match, context, next_state):
| (definitionlistitem, blank_finish) = self.definition_list_item(context)
self.parent += definitionlistitem
self.blank_finish = blank_finish
return ([], 'DefinitionList', [])
|
'Transition marker at end of section or document.'
| def eof(self, context):
| marker = context[0].strip()
if self.memo.section_bubble_up_kludge:
self.memo.section_bubble_up_kludge = 0
elif (len(marker) < 4):
self.state_correction(context)
if self.eofcheck:
lineno = (self.state_machine.abs_line_number() - 1)
transition = nodes.transition(rawsource=c... |
'Transition marker.'
| def blank(self, match, context, next_state):
| lineno = (self.state_machine.abs_line_number() - 1)
marker = context[0].strip()
if (len(marker) < 4):
self.state_correction(context)
transition = nodes.transition(rawsource=marker)
transition.line = lineno
self.parent += transition
return ([], 'Body', [])
|
'Potential over- & underlined title.'
| def text(self, match, context, next_state):
| lineno = (self.state_machine.abs_line_number() - 1)
overline = context[0]
title = match.string
underline = ''
try:
underline = self.state_machine.next_line()
except EOFError:
blocktext = ((overline + '\n') + title)
if (len(overline.rstrip()) < 4):
self.short_o... |
'Match arbitrary quote character on the first line only.'
| def initial_quoted(self, match, context, next_state):
| self.remove_transition('initial_quoted')
quote = match.string[0]
pattern = re.compile(re.escape(quote))
self.add_transition('quoted', (pattern, self.quoted, self.__class__.__name__))
self.initial_lineno = self.state_machine.abs_line_number()
return ([match.string], next_state, [])
|
'Match consistent quotes on subsequent lines.'
| def quoted(self, match, context, next_state):
| context.append(match.string)
return (context, next_state, [])
|
'Parse `inputstring` and populate `document`, a document tree.'
| def parse(self, inputstring, document):
| self.setup_parse(inputstring, document)
self.statemachine = states.RSTStateMachine(state_classes=self.state_classes, initial_state=self.initial_state, debug=document.reporter.debug_flag)
inputlines = docutils.statemachine.string2lines(inputstring, tab_width=document.settings.tab_width, convert_whitespace=1)... |
'Initialize with message `message`. `level` is a system message level.'
| def __init__(self, level, message):
| Exception.__init__(self)
self.level = level
self.message = message
|
'Return a DirectiveError suitable for being thrown as an exception.
Call "raise self.directive_error(level, message)" from within
a directive implementation to return one single system message
at level `level`, which automatically gets the directive block
and the line number added.
You\'d often use self.error(message) ... | def directive_error(self, level, message):
| return DirectiveError(level, message)
|
'Throw an ERROR-level DirectiveError if the directive doesn\'t
have contents.'
| def assert_has_content(self):
| if (not self.content):
raise self.error(('Content block expected for the "%s" directive; none found.' % self.name))
|
'Include a reST file as part of the content of this reST file.'
| def run(self):
| if (not self.state.document.settings.file_insertion_enabled):
raise self.warning(('"%s" directive disabled.' % self.name))
source = self.state_machine.input_lines.source(((self.lineno - self.state_machine.input_offset) - 1))
source_dir = os.path.dirname(os.path.abspath(source))
path = dire... |
'Dynamically create and register a custom interpreted text role.'
| def run(self):
| if ((self.content_offset > self.lineno) or (not self.content)):
raise self.error(('"%s" directive requires arguments on the first line.' % self.name))
args = self.content[0]
match = self.argument_pattern.match(args)
if (not match):
raise self.error(('"%s" directiv... |
'Get CSV data from the directive content, from an external
file, or from a URL reference.'
| def get_csv_data(self):
| encoding = self.options.get('encoding', self.state.document.settings.input_encoding)
if self.content:
if (self.options.has_key('file') or self.options.has_key('url')):
error = self.state_machine.reporter.error(('"%s" directive may not both specify an external file ... |
'Meta element.'
| def field_marker(self, match, context, next_state):
| (node, blank_finish) = self.parsemeta(match)
self.parent += node
return ([], next_state, [])
|
'Analyze the text `block` and return a table data structure.
Given a plaintext-graphic table in `block` (list of lines of text; no
whitespace padding), parse the table, construct and return the data
necessary to construct a CALS table or equivalent.
Raise `TableMarkupError` if there is any problem with the markup.'
| def parse(self, block):
| self.setup(block)
self.find_head_body_sep()
self.parse_table()
structure = self.structure_from_cells()
return structure
|
'Look for a head/body row separator line; store the line index.'
| def find_head_body_sep(self):
| for i in range(len(self.block)):
line = self.block[i]
if self.head_body_separator_pat.match(line):
if self.head_body_sep:
raise TableMarkupError(('Multiple head/body row separators in table (at line offset %s and %s); only one all... |
'Start with a queue of upper-left corners, containing the upper-left
corner of the table itself. Trace out one rectangular cell, remember
it, and add its upper-right and lower-left corners to the queue of
potential upper-left corners of further cells. Process the queue in
top-to-bottom order, keeping track of how much ... | def parse_table(self):
| corners = [(0, 0)]
while corners:
(top, left) = corners.pop(0)
if ((top == self.bottom) or (left == self.right) or (top <= self.done[left])):
continue
result = self.scan_cell(top, left)
if (not result):
continue
(bottom, right, rowseps, colseps) = ... |
'For keeping track of how much of each text column has been seen.'
| def mark_done(self, top, left, bottom, right):
| before = (top - 1)
after = (bottom - 1)
for col in range(left, right):
assert (self.done[col] == before)
self.done[col] = after
|
'Each text column should have been completely seen.'
| def check_parse_complete(self):
| last = (self.bottom - 1)
for col in range(self.right):
if (self.done[col] != last):
return None
return 1
|
'Starting at the top-left corner, start tracing out a cell.'
| def scan_cell(self, top, left):
| assert (self.block[top][left] == '+')
result = self.scan_right(top, left)
return result
|
'Look for the top-right corner of the cell, and make note of all column
boundaries (\'+\').'
| def scan_right(self, top, left):
| colseps = {}
line = self.block[top]
for i in range((left + 1), (self.right + 1)):
if (line[i] == '+'):
colseps[i] = [top]
result = self.scan_down(top, left, i)
if result:
(bottom, rowseps, newcolseps) = result
update_dict_of_lists(c... |
'Look for the bottom-right corner of the cell, making note of all row
boundaries.'
| def scan_down(self, top, left, right):
| rowseps = {}
for i in range((top + 1), (self.bottom + 1)):
if (self.block[i][right] == '+'):
rowseps[i] = [right]
result = self.scan_left(top, left, i, right)
if result:
(newrowseps, colseps) = result
update_dict_of_lists(rowseps, newro... |
'Noting column boundaries, look for the bottom-left corner of the cell.
It must line up with the starting point.'
| def scan_left(self, top, left, bottom, right):
| colseps = {}
line = self.block[bottom]
for i in range((right - 1), left, (-1)):
if (line[i] == '+'):
colseps[i] = [bottom]
elif (line[i] != '-'):
return None
if (line[left] != '+'):
return None
result = self.scan_up(top, left, bottom, right)
if (re... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.