Mercurial > mez_xml
annotate mez_xml.py @ 5:d310e097c6de tip
Replace & with &
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 02 Feb 2014 22:12:15 +0800 |
parents | 3679d2d8443a |
children |
rev | line source |
---|---|
0
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 from xml.dom.minidom import parse |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 import re |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 reo_attr_rep = re.compile('\\$\\{([a-zA-Z_][a-zA-Z0-9_]*)\\}') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 reserved_keywords = {'commit': None, 'gen_doc': None} |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 def clz_name(fn): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 from os import path |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 return path.basename(fn).split('.')[0] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 def _check_reserved(name): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 if name.startswith('_') or reserved_keywords.has_key(name): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 raise NameError, '%s is a reserved keyword' % (name,) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 class mez_xml(object): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 def __init__(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 super(mez_xml, self).__init__() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 def template_head(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 self.output_cmd_line('from mez_xml.tools import nez_web') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 self.output_cmd_line('') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 self.output_cmd_line('class %s(nez_web):' % (self.cname,)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 self.dig() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 self.output_cmd_line('def __init__(self, ofo):') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 self.dig() |
5 | 28 self.output_cmd_line('super(self.__class__, self).__init__()') |
0
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 self.output_cmd_line('self.ofo = ofo') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 self.output_cmd_line('pass') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 self.back() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 self.output_cmd_line('') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 def template_tail(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 self.output_cmd_line('pass') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 self.back() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 self.output_cmd_line('') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 def subtree_start(self, cname): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 self.output_cmd_line('def %s(self, pdata, cdata):' % (cname)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 self.dig() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 self.output_cmd_line('def temp(data):') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 self.dig() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 self.frag_start() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 def subtree_stop(self, cname): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 self.frag_stop() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 self.output_cmd_line('pass') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 self.back() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 self.output_cmd_line('self._feed_subtree(temp, pdata, cdata)') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 self.output_cmd_line('pass') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 self.back() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 self.output_cmd_line('') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 def _expand_vars(self, data, _tp): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 mo = reo_attr_rep.search(data) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 pos = 0 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 while mo: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 if pos != mo.start(): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 self.output(data[pos:mo.start()]) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 self.frag_stop() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 name = mo.group(1) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 subnames = name.split('.') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 first = subnames[0] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 self.output_cmd_line('odata = data.setdefault(\'%s\', {})' % (first)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 for subname in subnames[1:]: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 self.output_cmd_line('odata = odata.setdefault(\'%s\', {})' % (subname)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 self.output_cmd_line('self.ofo.write(self._esc_%s(odata))' % (_tp)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 self.frag_start() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 pos = mo.end() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 for subname in subnames: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 _check_reserved(subname) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 #if not self.all_names.has_key(name): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 #if not self.all_attrnames.has_key(name): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 # self.travel_q.append((name, None)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
83 # self.all_attrnames[name] = None |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 # pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 #pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 #else: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 #raise NameError, '%s is redefined' % (name,) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 mo = reo_attr_rep.search(data, pos) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 self.output(data[pos:]) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 def _expand_comm(self, data): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
94 self._expand_vars(data, 'comm') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 def _expand_param(self, data): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
98 self._expand_vars(data, 'param') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
99 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
100 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
101 def _expand_text(self, data,): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 self._expand_vars(data, 'text') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 def _expand_cdata(self, data): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
106 self._expand_vars(data, 'cdata') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
107 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
108 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 def gen_attrs(self, attrs): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 for i in range(attrs.length): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
111 attr = attrs.item(i) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 self.output(' ' + attr.name) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
113 val = attr.nodeValue |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
114 if val: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
115 self.output('="') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
116 self._expand_param(val) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
117 self.output('"') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
118 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
119 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 def tag_start(self, no): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
123 from xml.dom import Node |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
124 nt = no.nodeType |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 if nt == Node.CDATA_SECTION_NODE: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
126 self.output('<![CDATA[') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
127 self._expand_cdata(no.data) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
128 self.output(']]>') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
129 elif nt == Node.COMMENT_NODE: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
130 self.output('<!--') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
131 self._expand_comm(no.data); |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
132 self.output('-->') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
133 elif nt == Node.TEXT_NODE: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
134 self._expand_text(no.data); |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
135 elif nt == Node.ELEMENT_NODE: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
136 self.output('<' + no.tagName) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
137 self.gen_attrs(no.attributes) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
138 self.output('>') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
139 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
141 def tag_stop(self, no): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
142 from xml.dom import Node |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
143 nt = no.nodeType |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 if nt == Node.ELEMENT_NODE: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
145 self.output('</%s>' % (no.tagName,)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
146 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
147 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
148 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
149 def frag_start(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
150 self.output_cmd('self.ofo.write(\'\'\'') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
151 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
152 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
153 def frag_stop(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
154 self.output_raw('\'\'\')\n') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
155 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
156 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
157 def call_subtree(self, no): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
158 name = no.getAttribute('ezid') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
159 self.frag_stop() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
160 subnames = name.split('.') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
161 first = subnames[0] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
162 self.output_cmd_line('cdata = data.setdefault(\'%s\', {})' % (first)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
163 for subname in subnames[1:]: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
164 self.output_cmd_line('cdata = cdata.setdefault(\'%s\', {})' % (subname)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
165 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
166 last = subnames[-1] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
167 self.output_cmd_line('self.%s(data, cdata)' % (last)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
168 self.frag_start() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
169 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
170 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
171 def gen_node_template(self, name, node): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
172 from xml.dom import Node |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
173 fw_q = [node] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
174 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
175 def trackback(no): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
176 while no != node and no.parentNode and not no.nextSibling: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
177 no = no.parentNode |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
178 self.tag_stop(no) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
179 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
180 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
181 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
182 first = True |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
183 while fw_q: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
184 no = fw_q.pop() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
185 if (not first) and no.nodeType == Node.ELEMENT_NODE and no.hasAttributes() and no.hasAttribute('ezid'): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
186 name = no.getAttribute('ezid').split('.')[-1] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
187 _check_reserved(name) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
188 if not self.all_names.has_key(name) and not self.all_attrnames.has_key(name): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
189 self.travel_q.append((name, no)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
190 self.all_names[name] = None |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
191 else: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
192 raise NameError, '%s is redefined' % (name,) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
193 self.call_subtree(no) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
194 trackback(no) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
195 else: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
196 self.tag_start(no) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
197 if not no.hasChildNodes(): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
198 self.tag_stop(no) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
199 trackback(no) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
200 else: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
201 children = [no.childNodes.item(i) for i in range(no.childNodes.length)] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
202 children.reverse() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
203 fw_q.extend(children) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
204 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
205 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
206 first = False |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
207 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
208 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
209 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
210 def dig(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
211 self.indent = self.indent + 4 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
212 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
213 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
214 def back(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
215 self.indent = self.indent - 4 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
216 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
217 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
218 def output_cmd(self, msg): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
219 self.ofo.write(' ' * self.indent) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
220 self.ofo.write(msg) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
221 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
222 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
223 def output_cmd_line(self, msg): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
224 self.ofo.write(' ' * self.indent) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
225 self.ofo.write(msg) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
226 self.ofo.write('\n') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
227 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
228 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
229 def output_raw(self, msg): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
230 self.ofo.write(msg) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
231 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
232 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
233 def output(self, msg): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
234 parts = msg.split('\\') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
235 if len(parts) > 0: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
236 msg = '\\\\'.join(parts) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
237 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
238 if len(msg) > 0 and msg[-1] == '\'': |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
239 msg = msg[:-1] + '\\\'' |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
240 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
241 parts = msg.split('\'\'\'') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 if len(parts) > 1: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
243 msg = '\\\'\\\'\\\''.join(parts) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
244 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
245 self.ofo.write(msg) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
246 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
247 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
248 def start(self, fn, ifo, ofo): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
249 self.ofo = ofo |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
250 self.indent = 0 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
251 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 cname = clz_name(fn) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
253 dom = parse(ifo) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 self.travel_q = [('_root', dom)] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 self.cname = cname |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
256 self.all_names = {} |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
257 self.all_attrnames = {} |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
258 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
259 self.travel_tree() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
260 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
261 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 def travel_tree(self): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 self.template_head() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
264 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
265 travel_q = self.travel_q |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
266 while travel_q: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
267 name, node = travel_q[0] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
268 self.subtree_start(name) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
269 del travel_q[0] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
270 if node: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
271 self.gen_node_template(name, node) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
272 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
273 self.subtree_stop(name) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
274 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
275 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
276 self.template_tail() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
277 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
278 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
279 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
280 if __name__ == '__main__': |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
281 import sys |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 import locale |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
283 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
284 if len(sys.argv) != 2: |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
285 sys.exit(1) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
287 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
288 class fakefile(object): |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
289 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
291 fn = sys.argv[1] |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
292 fo = file(fn, 'r') |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 encoding = locale.getpreferredencoding() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
294 stdout = fakefile() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
295 oldwrite = sys.stdout.write |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
296 stdout.write = lambda x: oldwrite(x.encode(encoding)) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 if encoding != 'ascii': |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
299 print >> stdout, '# -*- coding: %s' % (encoding,) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 pass |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 mex = mez_xml() |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 mex.start(fn, fo, stdout) |
3679d2d8443a
Import from CVS and goto mez_xml-0.4
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
304 pass |