-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlink.py
More file actions
26 lines (23 loc) · 936 Bytes
/
link.py
File metadata and controls
26 lines (23 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from util import debug_trunc
class Link(object):
def __init__(self, **kwargs):
self.id = kwargs.get('id') if 'id' in kwargs else None
self.text = kwargs.get('text').strip() if 'text' in kwargs else None
self.source = kwargs.get('source') if 'source' in kwargs else None
self.target = kwargs.get('target') if 'target' in kwargs else None
self.indent_level = kwargs.get('indent_level') if 'indent_level' in kwargs else None
def __iter__(self):
yield 'id', self.id
yield 'text', self.text
yield 'source', dict(self.source)
yield 'target', dict(self.target)
# for debugging
# def __repr__(self):
# if self.target:
# return "{" + debug_trunc(self.source.text) + "} => " + \
# "{" + debug_trunc(self.text) + "} => " + \
# "{" + debug_trunc(self.target.text) + "}"
# else:
# return "{" + debug_trunc(self.source.text) + "} => " + \
# "{" + debug_trunc(self.text) + "} => " + \
# "{no target}"