1
|
1 |
if __name__=='__main__':
|
|
2 |
import pyRXP, traceback, os, sys, pprint
|
|
3 |
sys.stderr=sys.stdout
|
|
4 |
p=pyRXP.Parser()
|
|
5 |
print '''import pyRXP'''
|
|
6 |
print '''p=pyRXP.Parser()'''
|
|
7 |
|
|
8 |
code = ['''pyRXP.version''',
|
|
9 |
'''pyRXP.RXPVersion''',
|
|
10 |
'''p('<tag>content</tag>')''',
|
|
11 |
'''p('<tag1><tag2>content</tag2></tag1>')''',
|
|
12 |
-1,'''pprint.pprint(p('<tag1><tag2>content</tag2></tag1>'))''',
|
|
13 |
'''p('<tag>my contents</tag>')''',
|
|
14 |
'''p('<tag></tag>')''',
|
|
15 |
'''p('<tag/>')''',
|
|
16 |
'''p('<outerTag><innerTag>bb</innerTag>aaa<singleTag/></outerTag>')''',
|
|
17 |
-1,'''pprint.pprint(p('<outerTag><innerTag>bb</innerTag>aaa<singleTag/></outerTag>'))''',
|
|
18 |
'''p('<tag/><!-- this is a comment about the tag -->')''',
|
|
19 |
'''p('<!-- this is a comment -->')''',
|
|
20 |
'''p('<a>aaa</a') # note the missing '>''',
|
|
21 |
'''p('<a></a><b></b>')''',
|
|
22 |
'''p('<outer><a></a><b></b></outer>')''',
|
|
23 |
'''os.getcwd()''',
|
|
24 |
'''os.listdir('.')''',
|
|
25 |
-1,'''dtd = open('tinydtd.dtd', 'r').read()''',
|
|
26 |
'''dtd''',
|
|
27 |
-1,'''fn=open('sample1.xml', 'r').read()''',
|
|
28 |
'''fn''',
|
|
29 |
'''p(fn)''',
|
|
30 |
-1,'''fn=open('sample2.xml', 'r').read()''',
|
|
31 |
'''fn''',
|
|
32 |
'''p(fn)''',
|
|
33 |
-1,'''fn=open('sample4.xml', 'r').read()''',
|
|
34 |
'''fn''',
|
|
35 |
'''p(fn,NoNoDTDWarning=0)''',
|
|
36 |
-1,'''fn=open('sample3.xml', 'r').read()''',
|
|
37 |
'''fn''',
|
|
38 |
'''p(fn)''',
|
|
39 |
'''p('<a></a><b></b>',AllowMultipleElements = 0)''',
|
|
40 |
'''p('<a></a><b></b>',AllowMultipleElements=1)''',
|
|
41 |
'''p('<a></A>',CaseInsensitive=1)''',
|
|
42 |
'''p('<a></A>',CaseInsensitive=0)''',
|
|
43 |
'''p('<a>ϧ</a>',ErrorOnBadCharacterEntities=0)''',
|
|
44 |
'''p('<a>ϧ</a>',ErrorOnBadCharacterEntities=1)''',
|
|
45 |
'''p('<a>&dud;</a>',ErrorOnUndefinedEntities=0)''',
|
|
46 |
'''p('<a>&dud;</a>',ErrorOnUndefinedEntities=1)''',
|
|
47 |
'''p('<a>m</a>',ExpandCharacterEntities=1)''',
|
|
48 |
'''p('<a>m</a>',ExpandCharacterEntities=0)''',
|
|
49 |
'''p('<a>&</a>',ExpandGeneralEntities=0)''',
|
|
50 |
'''p('<a>&</a>',ExpandGeneralEntities=1)''',
|
|
51 |
'''p('<a>&</a>',IgnoreEntities=0)''',
|
|
52 |
'''p('<a>&</a>',IgnoreEntities=1)''',
|
|
53 |
'''p('<a><!-- this is a comment --></a>',ReturnComments=1)''',
|
|
54 |
'''p('<a><!-- this is a comment --></a>',ReturnComments=0)''',
|
|
55 |
'''p('<a>causes an error</b>',SimpleErrorFormat=0)''',
|
|
56 |
'''p('<a>causes an error</b>',SimpleErrorFormat=1)''',
|
|
57 |
'''p('<a>&</a>',XMLPredefinedEntities=1)''',
|
|
58 |
'''p('<a>&</a>',XMLPredefinedEntities=0)''',
|
|
59 |
]
|
|
60 |
po = 0
|
|
61 |
i = 0
|
|
62 |
for c in code:
|
|
63 |
if type(c) is type(1):
|
|
64 |
po=1
|
|
65 |
else:
|
|
66 |
i += 1
|
|
67 |
print '>>> '+c
|
|
68 |
if po:
|
|
69 |
po = 0
|
|
70 |
exec c in globals(), locals()
|
|
71 |
else:
|
|
72 |
try:
|
|
73 |
__x = eval(c)
|
|
74 |
print __x
|
|
75 |
except:
|
|
76 |
traceback.print_exc()
|