-
Notifications
You must be signed in to change notification settings - Fork 0
/
dna.py
57 lines (43 loc) · 1.3 KB
/
dna.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
11-11-15
"""
from dna_chain import DNACrawler, DNANode
__globals__ = ('DNA', )
class DNA(object):
"""
A language to describe changes:
Two contexts: DNA chain or DNA node
DNA chain: context is chain ( c )
- remove node
( c - NODE )
+ add node
c/a/b (child / sibling after / sibling before)
( c + NODE c/a/b REF_NODE )
^ move node
c/a/b (child / sibling after / sibling before)
( c ^ NODE c/a/b REF_NODE )
DNA node: context is node ( n )
+ add attribute
( n + NAME OBJECT)
- delete attribute
( n - NAME )
^ change attribute
( n ^ NAME OBJECT )
"""
def __init__(self, **kwargs):
self.head = None
self.node_factory = kwargs.get('node_factory', DNANode)
self.__rnas = []
def link(self, rna, update=True):
if rna not in self.__rnas:
self.__rnas.append(rna)
if update:
# TODO: update RNA
pass
def unlink(self, rna):
if rna in self.__rnas:
self.__rnas.remove(rna)
def spawn_crawler(self):
c = DNACrawler(self)
c.attach_to(self.head)
return c