Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: third_party/libxslt/python/tests/extfunc.py

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove suppressions, have landed in blink now Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/python -u
2 import sys
3 import string
4 import libxml2
5 # Memory debug specific
6 libxml2.debugMemory(1)
7 import libxslt
8
9 nodeName = None
10
11 def f(ctx, str):
12 global nodeName
13
14 #
15 # Small check to verify the context is correcly accessed
16 #
17 try:
18 pctxt = libxslt.xpathParserContext(_obj=ctx)
19 ctxt = pctxt.context()
20 tctxt = ctxt.transformContext()
21 nodeName = tctxt.insertNode().name
22 except:
23 pass
24
25 return string.upper(str)
26
27 libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)
28
29 styledoc = libxml2.parseDoc("""
30 <xsl:stylesheet version='1.0'
31 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
32 xmlns:foo='http://example.com/foo'
33 exclude-result-prefixes='foo'>
34
35 <xsl:param name='bar'>failure</xsl:param>
36 <xsl:template match='/'>
37 <article><xsl:value-of select='foo:foo($bar)'/></article>
38 </xsl:template>
39 </xsl:stylesheet>
40 """)
41 style = libxslt.parseStylesheetDoc(styledoc)
42 doc = libxml2.parseDoc("<doc/>")
43 result = style.applyStylesheet(doc, { "bar": "'success'" })
44 style.freeStylesheet()
45 doc.freeDoc()
46
47 root = result.children
48 if root.name != "article":
49 print "Unexpected root node name"
50 sys.exit(1)
51 if root.content != "SUCCESS":
52 print "Unexpected root node content, extension function failed"
53 sys.exit(1)
54 if nodeName != 'article':
55 print "The function callback failed to access its context"
56 sys.exit(1)
57
58 result.freeDoc()
59
60 # Memory debug specific
61 libxslt.cleanup()
62 if libxml2.debugMemory(1) == 0:
63 print "OK"
64 else:
65 print "Memory leak %d bytes" % (libxml2.debugMemory(1))
66 libxml2.dumpMemory()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698