ScannerError ( pass no-op. , MarkedYAMLError, , . error.py:
class MarkedYAMLError(YAMLError):
def __init__(self, context=None, context_mark=None,
problem=None, problem_mark=None, note=None):
self.context = context
self.context_mark = context_mark
self.problem = problem
self.problem_mark = problem_mark
self.note = note
def __str__(self):
lines = []
if self.context is not None:
lines.append(self.context)
if self.context_mark is not None \
and (self.problem is None or self.problem_mark is None
or self.context_mark.name != self.problem_mark.name
or self.context_mark.line != self.problem_mark.line
or self.context_mark.column != self.problem_mark.column):
lines.append(str(self.context_mark))
if self.problem is not None:
lines.append(self.problem)
if self.problem_mark is not None:
lines.append(str(self.problem_mark))
if self.note is not None:
lines.append(self.note)
return '\n'.join(lines)
txt.yaml:
hallo: 1
bye
a test.py:
import ruamel.yaml as yaml
txt = open('txt.yaml')
data = yaml.load(txt, yaml.SafeLoader)
:
...
ruamel.yaml.scanner.ScannerError: while scanning a simple key
in "txt.yaml", line 2, column 1
could not find expected ':'
in "txt.yaml", line 3, column 1
, test.py:
import ruamel.yaml as yaml
txt = open('txt.yaml').read()
data = yaml.load(txt, yaml.SafeLoader)
:
...
ruamel.yaml.scanner.ScannerError: while scanning a simple key
in "<byte string>", line 2, column 1:
bye
^
could not find expected ':'
in "<byte string>", line 3, column 1:
^
, get_mark() (in reader.py) , , :
def get_mark(self):
if self.stream is None:
return Mark(self.name, self.index, self.line, self.column,
self.buffer, self.pointer)
else:
return Mark(self.name, self.index, self.line, self.column,
None, None)
context_mark. , . , , YAML , .
YAML - , , , .
grep def method_name(, ( ).
PyYAML ruamel.yaml, .
>