class TreeNode(BaseObject): name = Field(str) children = Field(TreeNodeChildrenList, default=TreeNodeChildrenList, coerce=True) def add_child(self, *, label=None, node): self.children.append(TreeNodeChild(label=label, node=node))
class Exception(_Exception): msg = Field(str) # NB: Traceback is just an exception context # contexts = Field(ExceptionContextList, default=None, coerce=True) context = Field(_Exception, None) cause = Field(_Exception, None)
class TracebackPoint(BaseObject): name = Field(str) filename = Field(str) lineno = Field(int, default=None) colno = Field(int, default=None) address = Field(str, default=None) context = Field(bool, default=False) lines = Field(typed.StrList, default=None, coerce=True) line_numbers = Field(typed.IntList, default=None, coerce=True) locals = Field(Dict, default=None) def load_source(self, window=3, lines=None): self.lines = self.line_numbers = None if (self.lineno and ((self.filename and not self.filename.startswith('<') and not self.filename.endswith('>')) or lines)): lineno = self.lineno if not lines: linecache.checkcache(self.filename) sourcelines = linecache.getlines(self.filename, globals()) else: sourcelines = lines lines = [] line_numbers = [] start = max(1, lineno - window) end = min(len(sourcelines), lineno + window) + 1 for i in range(start, end): lines.append(sourcelines[i - 1].rstrip()) line_numbers.append(i) if lines: self.lines = typed.StrList(lines) self.line_numbers = typed.IntList(line_numbers)
class Diff(DocMarkup): lines = Field(typed.StrList, coerce=True) @classmethod def get_diff(cls, a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=10): lines = difflib.unified_diff(a, b, fromfile, tofile, fromfiledate, tofiledate, n) lines = [line.rstrip() for line in lines] if lines: return cls(lines=lines) else: return Text(text='No differences')
class Section(DocMarkup): title = Field(str, coerce=True, default=None) body = Field(base.MarkupList, coerce=True) collapsed = Field(bool, coerce=True, default=False)
class Marker(DocMarkup): text = Field(str)
class TreeNodeChild(BaseObject): label = Field(str, default=None) node = Field(base.Markup)
class Traceback(BaseObject): items = Field(TracebackPointList, default=TracebackPointList, coerce=True)
class SpecialListNode(_SpecialListNode): node = Field(_SpecialListNode, default=None)
class BaseObject(LangMarkup): """Base language object with ``id``, but without ``attributes``.""" id = Field(int, default=None, coerce=True)
class Ref(LangMarkup): ref = Field(int, coerce=True) refname = Field(str, default=None) def __repr__(self): return '<{} {} {}>'.format('Ref', self.refname, self.ref)
class String(LangMarkup): str = Field(str, default=None, coerce=True)
class Number(LangMarkup): num = Field(str, default=None, coerce=True)
class ExceptionContext(BaseObject): title = Field(str, default='Context') body = Field(base.MarkupList, coerce=True)
class Text(DocMarkup): text = Field(str)
class SourceCode(DocMarkup): text = Field(str)
class Object(BaseObject): class_module = Field(str) classname = Field(str) repr = Field(str, default=None) attributes = Field(base.MarkupMapping, default=None, coerce=True)
class ValueDiff(DocMarkup): before = Field(str) after = Field(str)
class List(BaseObject): items = Field(base.MarkupList, default=base.MarkupList, coerce=True) trimmed = Field(bool, default=False)
class SerializationError(Markup): """An error during object serialization occurred.""" text = Field(str) cls = Field(str)
class Dict(BaseObject): items = Field(base.MarkupMapping, default=base.MarkupMapping, coerce=True) trimmed = Field(bool, default=False)