Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo in emitter attr name #747

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions lib/yaml/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

__all__ = ['Emitter', 'EmitterError']

import warnings

from .error import YAMLError
from .events import *


class EmitterError(YAMLError):
pass


class ScalarAnalysis:
def __init__(self, scalar, empty, multiline,
allow_flow_plain, allow_block_plain,
Expand All @@ -28,6 +32,7 @@ def __init__(self, scalar, empty, multiline,
self.allow_double_quoted = allow_double_quoted
self.allow_block = allow_block


class Emitter:

DEFAULT_TAG_PREFIXES = {
Expand Down Expand Up @@ -69,12 +74,12 @@ def __init__(self, stream, canonical=None, indent=None, width=None,
# Characteristics of the last emitted character:
# - current position.
# - is it a whitespace?
# - is it an indention character
# - is it an indentation character
# (indentation space, '-', '?', or ':')?
self.line = 0
self.column = 0
self.whitespace = True
self.indention = True
self.indentation = True

# Whether the document requires an explicit document indicator
self.open_ended = False
Expand Down Expand Up @@ -103,6 +108,17 @@ def __init__(self, stream, canonical=None, indent=None, width=None,
self.analysis = None
self.style = None

# backward-compatibility
@property
def indention(self):
warnings.warn("Emitter.indention attribute is deprecated and will be removed in a future release; use Emitter.indentation instead", DeprecationWarning)
return self.indentation

@indention.setter
def indention(self, value):
warnings.warn("Emitter.indention attribute is deprecated and will be removed in a future release; use Emitter.indentation instead", DeprecationWarning)
self.indentation = value

def dispose(self):
# Reset the state attributes (to clear self-references)
self.states = []
Expand Down Expand Up @@ -366,7 +382,7 @@ def expect_flow_mapping_value(self):
# Block sequence handlers.

def expect_block_sequence(self):
indentless = (self.mapping_context and not self.indention)
indentless = (self.mapping_context and not self.indentation)
self.increase_indent(flow=False, indentless=indentless)
self.state = self.expect_first_block_sequence_item

Expand All @@ -379,7 +395,7 @@ def expect_block_sequence_item(self, first=False):
self.state = self.states.pop()
else:
self.write_indent()
self.write_indicator('-', True, indention=True)
self.write_indicator('-', True, indentation=True)
self.states.append(self.expect_block_sequence_item)
self.expect_node(sequence=True)

Expand All @@ -402,7 +418,7 @@ def expect_block_mapping_key(self, first=False):
self.states.append(self.expect_block_mapping_simple_value)
self.expect_node(mapping=True, simple_key=True)
else:
self.write_indicator('?', True, indention=True)
self.write_indicator('?', True, indentation=True)
self.states.append(self.expect_block_mapping_value)
self.expect_node(mapping=True)

Expand All @@ -413,7 +429,7 @@ def expect_block_mapping_simple_value(self):

def expect_block_mapping_value(self):
self.write_indent()
self.write_indicator(':', True, indention=True)
self.write_indicator(':', True, indentation=True)
self.states.append(self.expect_block_mapping_key)
self.expect_node(mapping=True)

Expand Down Expand Up @@ -798,13 +814,13 @@ def write_stream_end(self):
self.flush_stream()

def write_indicator(self, indicator, need_whitespace,
whitespace=False, indention=False):
whitespace=False, indentation=False):
if self.whitespace or not need_whitespace:
data = indicator
else:
data = ' '+indicator
self.whitespace = whitespace
self.indention = self.indention and indention
self.indentation = self.indentation and indentation
self.column += len(data)
self.open_ended = False
if self.encoding:
Expand All @@ -813,7 +829,7 @@ def write_indicator(self, indicator, need_whitespace,

def write_indent(self):
indent = self.indent or 0
if not self.indention or self.column > indent \
if not self.indentation or self.column > indent \
or (self.column == indent and not self.whitespace):
self.write_line_break()
if self.column < indent:
Expand All @@ -828,7 +844,7 @@ def write_line_break(self, data=None):
if data is None:
data = self.best_line_break
self.whitespace = True
self.indention = True
self.indentation = True
self.line += 1
self.column = 0
if self.encoding:
Expand Down Expand Up @@ -967,7 +983,7 @@ def write_double_quoted(self, text, split=True):
self.stream.write(data)
self.write_indent()
self.whitespace = False
self.indention = False
self.indentation = False
if text[start] == ' ':
data = '\\'
self.column += len(data)
Expand Down Expand Up @@ -1089,7 +1105,7 @@ def write_plain(self, text, split=True):
data = data.encode(self.encoding)
self.stream.write(data)
self.whitespace = False
self.indention = False
self.indentation = False
spaces = False
breaks = False
start = end = 0
Expand All @@ -1102,7 +1118,7 @@ def write_plain(self, text, split=True):
if start+1 == end and self.column > self.best_width and split:
self.write_indent()
self.whitespace = False
self.indention = False
self.indentation = False
else:
data = text[start:end]
self.column += len(data)
Expand All @@ -1121,7 +1137,7 @@ def write_plain(self, text, split=True):
self.write_line_break(br)
self.write_indent()
self.whitespace = False
self.indention = False
self.indentation = False
start = end
else:
if ch is None or ch in ' \n\x85\u2028\u2029':
Expand Down