summaryrefslogtreecommitdiff
path: root/error.py
diff options
context:
space:
mode:
Diffstat (limited to 'error.py')
-rw-r--r--error.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/error.py b/error.py
index 20c7979..5015828 100644
--- a/error.py
+++ b/error.py
@@ -6,21 +6,40 @@ import warnings
from ruamel.yaml.compat import utf8
-__all__ = ['Mark', 'YAMLError', 'MarkedYAMLError', 'ReusedAnchorWarning',
+__all__ = ['FileMark', 'StringMark', 'CommentMark',
+ 'YAMLError', 'MarkedYAMLError', 'ReusedAnchorWarning',
'UnsafeLoaderWarning']
-class Mark(object):
- def __init__(self, name, index, line, column, buffer, pointer):
+class StreamMark(object):
+ __slots__ = 'name', 'index', 'line', 'column',
+
+ def __init__(self, name, index, line, column):
self.name = name
self.index = index
self.line = line
self.column = column
+
+ def __str__(self):
+ where = " in \"%s\", line %d, column %d" \
+ % (self.name, self.line+1, self.column+1)
+ return where
+
+
+class FileMark(StreamMark):
+ __slots__ = ()
+
+
+class StringMark(StreamMark):
+ __slots__ = 'name', 'index', 'line', 'column', 'buffer', 'pointer',
+
+ def __init__(self, name, index, line, column, buffer, pointer):
+ StreamMark.__init__(self, name, index, line, column)
self.buffer = buffer
self.pointer = pointer
def get_snippet(self, indent=4, max_length=75):
- if self.buffer is None:
+ if self.buffer is None: # always False
return None
head = ''
start = self.pointer
@@ -53,6 +72,13 @@ class Mark(object):
return where
+class CommentMark(object):
+ __slots__ = 'column',
+
+ def __init__(self, column):
+ self.column = column
+
+
class YAMLError(Exception):
pass