Permalink
Browse files

Remove unused snippet copying stuff

  • Loading branch information...
1 parent 97204ad commit 989ee8a76d2162371be1ea9acdd11cb48a4179d4 @douglasbagnall douglasbagnall committed Oct 10, 2009
Showing with 0 additions and 105 deletions.
  1. +0 −67 lib/booki/xhtml_utils.py
  2. +0 −38 tests/copy_snippet.py
View
@@ -306,70 +306,3 @@ def finish(self):
self.add_to_package('info.json', 'info.json', infojson, 'application/json')
self._close()
-
-def llopsided_copy(parent, start_el, start_stack):
- if start_stack:
- new = parent.makeelement(start_el.tag, **start_el.attrib)
- parent.append(new)
- first_child = start_stack.pop()
- llopsided_copy(new, first_child, start_stack)
- for el in first_child.itersiblings():
- parent.append(copy.deepcopy(el))
- else:
- parent.append(copy.deepcopy(start_el))
-
-
-def rlopsided_copy(parent, end_el, end_stack):
- if end_stack:
- last_child = end_stack.pop()
- for el in end_el.iterchildren():
- if el is last_child:
- break
- parent.append(copy.deepcopy(el))
- new = parent.makeelement(end_el.tag, **end_el.attrib)
- parent.append(new)
- rlopsided_copy(new, last_child, end_stack)
- else:
- parent.append(copy.deepcopy(end_el))
-
-
-
-def xml_snippet(start_tag, end_tag):
- #dbody = new_html_body()
- start_stack = [start_tag] + [x for x in start_tag.iterancestors()]
- end_stack = [end_tag] + [x for x in end_tag.iterancestors()]
- #print start_stack, end_stack
-
- #start_stack.reverse()
- #end_stack.reverse()
- oldroot = start_stack.pop()
- assert oldroot == end_stack.pop()
- root = etree.Element(oldroot.tag)
- context = root
- while start_stack:
- start_el = start_stack.pop()
- end_el = end_stack.pop()
- if start_el is not end_el:
- # The start stack and endstack will never converge, so we
- # may as well stop the loop.
- break
- new = root.makeelement(start_el.tag, **start_el.attrib)
- context.append(new)
- context = new
-
- #so the tree has diverged.
- #need to copy
- # 1. part of this subtree
- # 2. all intervening subtrees - deepcopy
- # 3. part of last subtree
- print start_stack, end_stack, context
-
- llopsided_copy(context, start_el, start_stack)
- for el in start_el.itersiblings():
- if el is end_el or el in end_stack:
- break
- context.append(copy.deepcopy(el)) #actually, being destructive wouldn't matter
- rlopsided_copy(context, end_el, end_stack)
-
- return root
-
View
@@ -1,38 +0,0 @@
-import os, sys
-import re
-from booki import xhtml_utils
-
-from pprint import pformat
-
-from lxml import etree, html
-from lxml.builder import E
-
-
-#doc = html.parse('copy_snippet.html')
-MARKER_CLASS="espri-marker"
-
-def test_copy():
- doc = html.parse('copy_snippet.html')
- elements = []
- for el in doc.iter('hr'):
- ID = el.get('id')
- if ID.startswith('espri-chapter-'):
- chapid = ID[14:]
- elements.append((el, chapid))
-
- print elements
- for s, e in zip(elements, elements[1:]):
- start_tag, sid = s
- end_tag, eid = e
-
- subdoc = xhtml_utils.xml_snippet(start_tag, end_tag)
- string = etree.tostring(subdoc)
- #print string
- f = open('/tmp/%s.html' % sid, 'w')
- f.write(string)
- f.close()
-
-
-
-test_copy()
-

0 comments on commit 989ee8a

Please sign in to comment.