Mercurial > cpython-lru_cache-weakref
annotate Modules/_elementtree.c @ 39496:352ffe77b71d legacy-trunk
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 14 Aug 2006 21:42:55 +0000 |
| parents | e11caad7e029 |
| children | d82218554897 |
| rev | line source |
|---|---|
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1 /* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2 * ElementTree |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
3 * $Id: _elementtree.c 2657 2006-03-12 20:50:32Z fredrik $ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
4 * |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
5 * elementtree accelerator |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
6 * |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
7 * History: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
8 * 1999-06-20 fl created (as part of sgmlop) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
9 * 2001-05-29 fl effdom edition |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
10 * 2001-06-05 fl backported to unix; fixed bogus free in clear |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
11 * 2001-07-10 fl added findall helper |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
12 * 2003-02-27 fl elementtree edition (alpha) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
13 * 2004-06-03 fl updates for elementtree 1.2 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
14 * 2005-01-05 fl added universal name cache, Element/SubElement factories |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
15 * 2005-01-06 fl moved python helpers into C module; removed 1.5.2 support |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
16 * 2005-01-07 fl added 2.1 support; work around broken __copy__ in 2.3 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
17 * 2005-01-08 fl added makeelement method; fixed path support |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
18 * 2005-01-10 fl optimized memory usage |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
19 * 2005-01-11 fl first public release (cElementTree 0.8) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
20 * 2005-01-12 fl split element object into base and extras |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
21 * 2005-01-13 fl use tagged pointers for tail/text (cElementTree 0.9) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
22 * 2005-01-17 fl added treebuilder close method |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
23 * 2005-01-17 fl fixed crash in getchildren |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
24 * 2005-01-18 fl removed observer api, added iterparse (cElementTree 0.9.3) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
25 * 2005-01-23 fl revised iterparse api; added namespace event support (0.9.8) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
26 * 2005-01-26 fl added VERSION module property (cElementTree 1.0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
27 * 2005-01-28 fl added remove method (1.0.1) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
28 * 2005-03-01 fl added iselement function; fixed makeelement aliasing (1.0.2) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
29 * 2005-03-13 fl export Comment and ProcessingInstruction/PI helpers |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
30 * 2005-03-26 fl added Comment and PI support to XMLParser |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
31 * 2005-03-27 fl event optimizations; complain about bogus events |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
32 * 2005-08-08 fl fixed read error handling in parse |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
33 * 2005-08-11 fl added runtime test for copy workaround (1.0.3) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
34 * 2005-12-13 fl added expat_capi support (for xml.etree) (1.0.4) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
35 * 2005-12-16 fl added support for non-standard encodings |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
36 * 2006-03-08 fl fixed a couple of potential null-refs and leaks |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
37 * 2006-03-12 fl merge in 2.5 ssize_t changes |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
38 * |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
39 * Copyright (c) 1999-2006 by Secret Labs AB. All rights reserved. |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
40 * Copyright (c) 1999-2006 by Fredrik Lundh. |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
41 * |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
42 * info@pythonware.com |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
43 * http://www.pythonware.com |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
44 */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
45 |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
46 /* Licensed to PSF under a Contributor Agreement. */ |
|
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
47 /* See http://www.python.org/2.4/license for licensing details. */ |
|
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
48 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
49 #include "Python.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
50 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
51 #define VERSION "1.0.6-snapshot" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
52 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
53 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
54 /* configuration */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 /* Leave defined to include the expat-based XMLParser type */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 #define USE_EXPAT |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
58 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
59 /* Define to to all expat calls via pyexpat's embedded expat library */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
60 /* #define USE_PYEXPAT_CAPI */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
61 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
62 /* An element can hold this many children without extra memory |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
63 allocations. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
64 #define STATIC_CHILDREN 4 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
65 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
66 /* For best performance, chose a value so that 80-90% of all nodes |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
67 have no more than the given number of children. Set this to zero |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
68 to minimize the size of the element structure itself (this only |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
69 helps if you have lots of leaf nodes with attributes). */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
70 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
71 /* Also note that pymalloc always allocates blocks in multiples of |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
72 eight bytes. For the current version of cElementTree, this means |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
73 that the number of children should be an even number, at least on |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
74 32-bit platforms. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
75 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
76 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
77 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
78 #if 0 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
79 static int memory = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
80 #define ALLOC(size, comment)\ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
81 do { memory += size; printf("%8d - %s\n", memory, comment); } while (0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
82 #define RELEASE(size, comment)\ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
83 do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
84 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
85 #define ALLOC(size, comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
86 #define RELEASE(size, comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
87 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
88 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
89 /* compiler tweaks */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
90 #if defined(_MSC_VER) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
91 #define LOCAL(type) static __inline type __fastcall |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
92 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
93 #define LOCAL(type) static type |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
94 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
95 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
96 /* compatibility macros */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
97 #if (PY_VERSION_HEX < 0x02050000) |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
98 typedef int Py_ssize_t; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
99 #define lenfunc inquiry |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
100 #endif |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
101 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
102 #if (PY_VERSION_HEX < 0x02040000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
103 #define PyDict_CheckExact PyDict_Check |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
104 #if (PY_VERSION_HEX < 0x02020000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
105 #define PyList_CheckExact PyList_Check |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
106 #define PyString_CheckExact PyString_Check |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
107 #if (PY_VERSION_HEX >= 0x01060000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
108 #define Py_USING_UNICODE /* always enabled for 2.0 and 2.1 */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
109 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
110 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
111 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
112 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
113 #if !defined(Py_RETURN_NONE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
114 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
115 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
116 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
117 /* macros used to store 'join' flags in string object pointers. note |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
118 that all use of text and tail as object pointers must be wrapped in |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
119 JOIN_OBJ. see comments in the ElementObject definition for more |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
120 info. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
121 #define JOIN_GET(p) ((Py_uintptr_t) (p) & 1) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
122 #define JOIN_SET(p, flag) ((void*) ((Py_uintptr_t) (JOIN_OBJ(p)) | (flag))) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
123 #define JOIN_OBJ(p) ((PyObject*) ((Py_uintptr_t) (p) & ~1)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
124 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
125 /* glue functions (see the init function for details) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
126 static PyObject* elementtree_copyelement_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
127 static PyObject* elementtree_deepcopy_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
128 static PyObject* elementtree_getiterator_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
129 static PyObject* elementpath_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
130 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
131 /* helpers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
132 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
133 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
134 deepcopy(PyObject* object, PyObject* memo) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
135 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
136 /* do a deep copy of the given object */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
137 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
138 PyObject* args; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
139 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
140 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
141 if (!elementtree_deepcopy_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
142 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
143 PyExc_RuntimeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
144 "deepcopy helper not found" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
145 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
146 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
147 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
148 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
149 args = PyTuple_New(2); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
150 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
151 return NULL; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
152 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
153 Py_INCREF(object); PyTuple_SET_ITEM(args, 0, (PyObject*) object); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
154 Py_INCREF(memo); PyTuple_SET_ITEM(args, 1, (PyObject*) memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
155 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
156 result = PyObject_CallObject(elementtree_deepcopy_obj, args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
157 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
158 Py_DECREF(args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
159 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
160 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
161 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
162 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
163 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
164 list_join(PyObject* list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
165 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
166 /* join list elements (destroying the list in the process) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
167 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
168 PyObject* joiner; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
169 PyObject* function; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
170 PyObject* args; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
171 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
172 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
173 switch (PyList_GET_SIZE(list)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
174 case 0: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
175 Py_DECREF(list); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
176 return PyString_FromString(""); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
177 case 1: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
178 result = PyList_GET_ITEM(list, 0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
179 Py_INCREF(result); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
180 Py_DECREF(list); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
181 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
182 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
183 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
184 /* two or more elements: slice out a suitable separator from the |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
185 first member, and use that to join the entire list */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
186 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
187 joiner = PySequence_GetSlice(PyList_GET_ITEM(list, 0), 0, 0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
188 if (!joiner) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
189 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
190 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
191 function = PyObject_GetAttrString(joiner, "join"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
192 if (!function) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
193 Py_DECREF(joiner); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
194 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
195 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
196 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
197 args = PyTuple_New(1); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
198 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
199 return NULL; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
200 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
201 PyTuple_SET_ITEM(args, 0, list); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
202 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
203 result = PyObject_CallObject(function, args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
204 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
205 Py_DECREF(args); /* also removes list */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
206 Py_DECREF(function); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
207 Py_DECREF(joiner); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
208 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
209 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
210 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
211 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
212 #if (PY_VERSION_HEX < 0x02020000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
213 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
214 PyDict_Update(PyObject* dict, PyObject* other) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
215 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
216 /* PyDict_Update emulation for 2.1 and earlier */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
217 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
218 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
219 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
220 res = PyObject_CallMethod(dict, "update", "O", other); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
221 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
222 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
223 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
224 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
225 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
226 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
227 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
228 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
229 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
230 /* the element type */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
231 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
232 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
233 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
234 /* attributes (a dictionary object), or None if no attributes */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
235 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
236 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
237 /* child elements */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
238 int length; /* actual number of items */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
239 int allocated; /* allocated items */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
240 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
241 /* this either points to _children or to a malloced buffer */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
242 PyObject* *children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
243 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
244 PyObject* _children[STATIC_CHILDREN]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
245 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
246 } ElementObjectExtra; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
247 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
248 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
249 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
250 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
251 /* element tag (a string). */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
252 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
253 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
254 /* text before first child. note that this is a tagged pointer; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
255 use JOIN_OBJ to get the object pointer. the join flag is used |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
256 to distinguish lists created by the tree builder from lists |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
257 assigned to the attribute by application code; the former |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
258 should be joined before being returned to the user, the latter |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
259 should be left intact. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
260 PyObject* text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
261 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
262 /* text after this element, in parent. note that this is a tagged |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
263 pointer; use JOIN_OBJ to get the object pointer. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
264 PyObject* tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
265 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
266 ElementObjectExtra* extra; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
267 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
268 } ElementObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
269 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
270 staticforward PyTypeObject Element_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
271 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
272 #define Element_CheckExact(op) ((op)->ob_type == &Element_Type) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
273 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
274 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
275 /* element constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
276 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
277 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
278 element_new_extra(ElementObject* self, PyObject* attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
279 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
280 self->extra = PyObject_Malloc(sizeof(ElementObjectExtra)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
281 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
282 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
283 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
284 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
285 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
286 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
287 Py_INCREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
288 self->extra->attrib = attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
289 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
290 self->extra->length = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
291 self->extra->allocated = STATIC_CHILDREN; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
292 self->extra->children = self->extra->_children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
293 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
294 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
295 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
296 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
297 LOCAL(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
298 element_dealloc_extra(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
299 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
300 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
301 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
302 Py_DECREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
303 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
304 for (i = 0; i < self->extra->length; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
305 Py_DECREF(self->extra->children[i]); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
306 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
307 if (self->extra->children != self->extra->_children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
308 PyObject_Free(self->extra->children); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
309 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
310 PyObject_Free(self->extra); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
311 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
312 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
313 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
314 element_new(PyObject* tag, PyObject* attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
315 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
316 ElementObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
317 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
318 self = PyObject_New(ElementObject, &Element_Type); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
319 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
320 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
321 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
322 /* use None for empty dictionaries */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
323 if (PyDict_CheckExact(attrib) && !PyDict_Size(attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
324 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
325 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
326 self->extra = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
327 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
328 if (attrib != Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
329 |
|
38139
f1e24452dbba
Fix problems found by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
330 if (element_new_extra(self, attrib) < 0) { |
|
f1e24452dbba
Fix problems found by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
331 PyObject_Del(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
332 return NULL; |
|
38139
f1e24452dbba
Fix problems found by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
333 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
334 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
335 self->extra->length = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
336 self->extra->allocated = STATIC_CHILDREN; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
337 self->extra->children = self->extra->_children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
338 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
339 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
340 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
341 Py_INCREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
342 self->tag = tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
343 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
344 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
345 self->text = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
346 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
347 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
348 self->tail = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
349 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
350 ALLOC(sizeof(ElementObject), "create element"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
351 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
352 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
353 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
354 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
355 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
356 element_resize(ElementObject* self, int extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
357 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
358 int size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
359 PyObject* *children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
360 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
361 /* make sure self->children can hold the given number of extra |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
362 elements. set an exception and return -1 if allocation failed */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
363 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
364 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
365 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
366 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
367 size = self->extra->length + extra; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
368 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
369 if (size > self->extra->allocated) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
370 /* use Python 2.4's list growth strategy */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
371 size = (size >> 3) + (size < 9 ? 3 : 6) + size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
372 if (self->extra->children != self->extra->_children) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
373 children = PyObject_Realloc(self->extra->children, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
374 size * sizeof(PyObject*)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
375 if (!children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
376 goto nomemory; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
377 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
378 children = PyObject_Malloc(size * sizeof(PyObject*)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
379 if (!children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
380 goto nomemory; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
381 /* copy existing children from static area to malloc buffer */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
382 memcpy(children, self->extra->children, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
383 self->extra->length * sizeof(PyObject*)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
384 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
385 self->extra->children = children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
386 self->extra->allocated = size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
387 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
388 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
389 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
390 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
391 nomemory: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
392 PyErr_NoMemory(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
393 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
394 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
395 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
396 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
397 element_add_subelement(ElementObject* self, PyObject* element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
398 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
399 /* add a child element to a parent */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
400 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
401 if (element_resize(self, 1) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
402 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
403 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
404 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
405 self->extra->children[self->extra->length] = element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
406 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
407 self->extra->length++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
408 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
409 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
410 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
411 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
412 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
413 element_get_attrib(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
414 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
415 /* return borrowed reference to attrib dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
416 /* note: this function assumes that the extra section exists */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
417 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
418 PyObject* res = self->extra->attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
419 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
420 if (res == Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
421 /* create missing dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
422 res = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
423 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
424 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
425 self->extra->attrib = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
426 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
427 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
428 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
429 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
430 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
431 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
432 element_get_text(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
433 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
434 /* return borrowed reference to text attribute */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
435 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
436 PyObject* res = self->text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
437 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
438 if (JOIN_GET(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
439 res = JOIN_OBJ(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
440 if (PyList_CheckExact(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
441 res = list_join(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
442 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
443 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
444 self->text = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
445 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
446 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
447 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
448 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
449 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
450 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
451 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
452 element_get_tail(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
453 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
454 /* return borrowed reference to text attribute */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
455 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
456 PyObject* res = self->tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
457 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
458 if (JOIN_GET(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
459 res = JOIN_OBJ(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
460 if (PyList_CheckExact(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
461 res = list_join(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
462 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
463 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
464 self->tail = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
465 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
466 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
467 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
468 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
469 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
470 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
471 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
472 element(PyObject* self, PyObject* args, PyObject* kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
473 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
474 PyObject* elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
475 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
476 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
477 PyObject* attrib = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
478 if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
479 &PyDict_Type, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
480 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
481 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
482 if (attrib || kw) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
483 attrib = (attrib) ? PyDict_Copy(attrib) : PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
484 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
485 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
486 if (kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
487 PyDict_Update(attrib, kw); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
488 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
489 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
490 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
491 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
492 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
493 elem = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
494 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
495 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
496 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
497 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
498 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
499 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
500 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
501 subelement(PyObject* self, PyObject* args, PyObject* kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
502 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
503 PyObject* elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
504 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
505 ElementObject* parent; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
506 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
507 PyObject* attrib = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
508 if (!PyArg_ParseTuple(args, "O!O|O!:SubElement", |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
509 &Element_Type, &parent, &tag, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
510 &PyDict_Type, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
511 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
512 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
513 if (attrib || kw) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
514 attrib = (attrib) ? PyDict_Copy(attrib) : PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
515 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
516 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
517 if (kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
518 PyDict_Update(attrib, kw); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
519 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
520 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
521 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
522 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
523 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
524 elem = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
525 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
526 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
527 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
528 if (element_add_subelement(parent, elem) < 0) { |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
529 Py_DECREF(elem); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
530 return NULL; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
531 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
532 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
533 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
534 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
535 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
536 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
537 element_dealloc(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
538 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
539 if (self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
540 element_dealloc_extra(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
541 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
542 /* discard attributes */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
543 Py_DECREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
544 Py_DECREF(JOIN_OBJ(self->text)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
545 Py_DECREF(JOIN_OBJ(self->tail)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
546 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
547 RELEASE(sizeof(ElementObject), "destroy element"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
548 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
549 PyObject_Del(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
550 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
551 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
552 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
553 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
554 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
555 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
556 element_append(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
557 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
558 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
559 if (!PyArg_ParseTuple(args, "O!:append", &Element_Type, &element)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
560 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
561 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
562 if (element_add_subelement(self, element) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
563 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
564 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
565 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
566 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
567 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
568 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
569 element_clear(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
570 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
571 if (!PyArg_ParseTuple(args, ":clear")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
572 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
573 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
574 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
575 element_dealloc_extra(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
576 self->extra = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
577 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
578 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
579 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
580 Py_DECREF(JOIN_OBJ(self->text)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
581 self->text = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
582 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
583 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
584 Py_DECREF(JOIN_OBJ(self->tail)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
585 self->tail = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
586 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
587 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
588 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
589 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
590 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
591 element_copy(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
592 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
593 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
594 ElementObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
595 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
596 if (!PyArg_ParseTuple(args, ":__copy__")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
597 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
598 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
599 element = (ElementObject*) element_new( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
600 self->tag, (self->extra) ? self->extra->attrib : Py_None |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
601 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
602 if (!element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
603 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
604 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
605 Py_DECREF(JOIN_OBJ(element->text)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
606 element->text = self->text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
607 Py_INCREF(JOIN_OBJ(element->text)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
608 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
609 Py_DECREF(JOIN_OBJ(element->tail)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
610 element->tail = self->tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
611 Py_INCREF(JOIN_OBJ(element->tail)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
612 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
613 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
614 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
615 if (element_resize(element, self->extra->length) < 0) { |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
616 Py_DECREF(element); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
617 return NULL; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
618 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
619 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
620 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
621 Py_INCREF(self->extra->children[i]); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
622 element->extra->children[i] = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
623 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
624 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
625 element->extra->length = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
626 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
627 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
628 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
629 return (PyObject*) element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
630 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
631 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
632 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
633 element_deepcopy(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
634 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
635 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
636 ElementObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
637 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
638 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
639 PyObject* text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
640 PyObject* tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
641 PyObject* id; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
642 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
643 PyObject* memo; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
644 if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
645 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
646 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
647 tag = deepcopy(self->tag, memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
648 if (!tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
649 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
650 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
651 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
652 attrib = deepcopy(self->extra->attrib, memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
653 if (!attrib) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
654 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
655 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
656 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
657 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
658 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
659 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
660 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
661 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
662 element = (ElementObject*) element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
663 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
664 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
665 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
666 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
667 if (!element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
668 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
669 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
670 text = deepcopy(JOIN_OBJ(self->text), memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
671 if (!text) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
672 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
673 Py_DECREF(element->text); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
674 element->text = JOIN_SET(text, JOIN_GET(self->text)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
675 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
676 tail = deepcopy(JOIN_OBJ(self->tail), memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
677 if (!tail) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
678 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
679 Py_DECREF(element->tail); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
680 element->tail = JOIN_SET(tail, JOIN_GET(self->tail)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
681 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
682 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
683 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
684 if (element_resize(element, self->extra->length) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
685 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
686 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
687 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
688 PyObject* child = deepcopy(self->extra->children[i], memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
689 if (!child) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
690 element->extra->length = i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
691 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
692 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
693 element->extra->children[i] = child; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
694 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
695 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
696 element->extra->length = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
697 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
698 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
699 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
700 /* add object to memo dictionary (so deepcopy won't visit it again) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
701 id = PyInt_FromLong((Py_uintptr_t) self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
702 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
703 i = PyDict_SetItem(memo, id, (PyObject*) element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
704 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
705 Py_DECREF(id); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
706 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
707 if (i < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
708 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
709 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
710 return (PyObject*) element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
711 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
712 error: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
713 Py_DECREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
714 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
715 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
716 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
717 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
718 checkpath(PyObject* tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
719 { |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
720 Py_ssize_t i; |
|
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
721 int check = 1; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
722 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
723 /* check if a tag contains an xpath character */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
724 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
725 #define PATHCHAR(ch) (ch == '/' || ch == '*' || ch == '[' || ch == '@') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
726 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
727 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
728 if (PyUnicode_Check(tag)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
729 Py_UNICODE *p = PyUnicode_AS_UNICODE(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
730 for (i = 0; i < PyUnicode_GET_SIZE(tag); i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
731 if (p[i] == '{') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
732 check = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
733 else if (p[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
734 check = 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
735 else if (check && PATHCHAR(p[i])) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
736 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
737 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
738 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
739 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
740 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
741 if (PyString_Check(tag)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
742 char *p = PyString_AS_STRING(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
743 for (i = 0; i < PyString_GET_SIZE(tag); i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
744 if (p[i] == '{') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
745 check = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
746 else if (p[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
747 check = 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
748 else if (check && PATHCHAR(p[i])) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
749 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
750 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
751 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
752 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
753 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
754 return 1; /* unknown type; might be path expression */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
755 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
756 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
757 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
758 element_find(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
759 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
760 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
761 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
762 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
763 if (!PyArg_ParseTuple(args, "O:find", &tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
764 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
765 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
766 if (checkpath(tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
767 return PyObject_CallMethod( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
768 elementpath_obj, "find", "OO", self, tag |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
769 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
770 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
771 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
772 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
773 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
774 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
775 PyObject* item = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
776 if (Element_CheckExact(item) && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
777 PyObject_Compare(((ElementObject*)item)->tag, tag) == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
778 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
779 return item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
780 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
781 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
782 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
783 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
784 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
785 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
786 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
787 element_findtext(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
788 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
789 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
790 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
791 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
792 PyObject* default_value = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
793 if (!PyArg_ParseTuple(args, "O|O:findtext", &tag, &default_value)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
794 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
795 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
796 if (checkpath(tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
797 return PyObject_CallMethod( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
798 elementpath_obj, "findtext", "OOO", self, tag, default_value |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
799 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
800 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
801 if (!self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
802 Py_INCREF(default_value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
803 return default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
804 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
805 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
806 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
807 ElementObject* item = (ElementObject*) self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
808 if (Element_CheckExact(item) && !PyObject_Compare(item->tag, tag)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
809 PyObject* text = element_get_text(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
810 if (text == Py_None) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
811 return PyString_FromString(""); |
|
39445
e11caad7e029
Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38885
diff
changeset
|
812 Py_XINCREF(text); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
813 return text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
814 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
815 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
816 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
817 Py_INCREF(default_value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
818 return default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
819 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
820 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
821 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
822 element_findall(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
823 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
824 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
825 PyObject* out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
826 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
827 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
828 if (!PyArg_ParseTuple(args, "O:findall", &tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
829 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
830 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
831 if (checkpath(tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
832 return PyObject_CallMethod( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
833 elementpath_obj, "findall", "OO", self, tag |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
834 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
835 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
836 out = PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
837 if (!out) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
838 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
839 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
840 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
841 return out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
842 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
843 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
844 PyObject* item = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
845 if (Element_CheckExact(item) && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
846 PyObject_Compare(((ElementObject*)item)->tag, tag) == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
847 if (PyList_Append(out, item) < 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
848 Py_DECREF(out); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
849 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
850 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
851 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
852 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
853 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
854 return out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
855 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
856 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
857 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
858 element_get(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
859 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
860 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
861 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
862 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
863 PyObject* default_value = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
864 if (!PyArg_ParseTuple(args, "O|O:get", &key, &default_value)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
865 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
866 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
867 if (!self->extra || self->extra->attrib == Py_None) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
868 value = default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
869 else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
870 value = PyDict_GetItem(self->extra->attrib, key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
871 if (!value) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
872 value = default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
873 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
874 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
875 Py_INCREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
876 return value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
877 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
878 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
879 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
880 element_getchildren(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
881 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
882 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
883 PyObject* list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
884 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
885 if (!PyArg_ParseTuple(args, ":getchildren")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
886 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
887 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
888 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
889 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
890 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
891 list = PyList_New(self->extra->length); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
892 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
893 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
894 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
895 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
896 PyObject* item = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
897 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
898 PyList_SET_ITEM(list, i, item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
899 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
900 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
901 return list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
902 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
903 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
904 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
905 element_getiterator(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
906 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
907 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
908 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
909 PyObject* tag = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
910 if (!PyArg_ParseTuple(args, "|O:getiterator", &tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
911 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
912 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
913 if (!elementtree_getiterator_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
914 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
915 PyExc_RuntimeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
916 "getiterator helper not found" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
917 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
918 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
919 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
920 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
921 args = PyTuple_New(2); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
922 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
923 return NULL; |
|
36450
c193283e63bc
Check return results for errors
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
924 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
925 Py_INCREF(self); PyTuple_SET_ITEM(args, 0, (PyObject*) self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
926 Py_INCREF(tag); PyTuple_SET_ITEM(args, 1, (PyObject*) tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
927 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
928 result = PyObject_CallObject(elementtree_getiterator_obj, args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
929 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
930 Py_DECREF(args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
931 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
932 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
933 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
934 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
935 static PyObject* |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
936 element_getitem(PyObject* self_, Py_ssize_t index) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
937 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
938 ElementObject* self = (ElementObject*) self_; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
939 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
940 if (!self->extra || index < 0 || index >= self->extra->length) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
941 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
942 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
943 "child index out of range" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
944 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
945 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
946 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
947 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
948 Py_INCREF(self->extra->children[index]); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
949 return self->extra->children[index]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
950 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
951 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
952 static PyObject* |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
953 element_getslice(PyObject* self_, Py_ssize_t start, Py_ssize_t end) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
954 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
955 ElementObject* self = (ElementObject*) self_; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
956 Py_ssize_t i; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
957 PyObject* list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
958 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
959 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
960 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
961 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
962 /* standard clamping */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
963 if (start < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
964 start = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
965 if (end < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
966 end = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
967 if (end > self->extra->length) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
968 end = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
969 if (start > end) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
970 start = end; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
971 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
972 list = PyList_New(end - start); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
973 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
974 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
975 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
976 for (i = start; i < end; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
977 PyObject* item = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
978 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
979 PyList_SET_ITEM(list, i - start, item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
980 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
981 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
982 return list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
983 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
984 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
985 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
986 element_insert(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
987 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
988 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
989 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
990 int index; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
991 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
992 if (!PyArg_ParseTuple(args, "iO!:insert", &index, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
993 &Element_Type, &element)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
994 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
995 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
996 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
997 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
998 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
999 if (index < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1000 index = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1001 if (index > self->extra->length) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1002 index = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1003 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1004 if (element_resize(self, 1) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1005 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1006 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1007 for (i = self->extra->length; i > index; i--) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1008 self->extra->children[i] = self->extra->children[i-1]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1009 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1010 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1011 self->extra->children[index] = element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1012 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1013 self->extra->length++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1014 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1015 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1016 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1017 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1018 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1019 element_items(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1020 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1021 if (!PyArg_ParseTuple(args, ":items")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1022 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1023 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1024 if (!self->extra || self->extra->attrib == Py_None) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1025 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1026 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1027 return PyDict_Items(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1028 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1029 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1030 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1031 element_keys(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1032 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1033 if (!PyArg_ParseTuple(args, ":keys")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1034 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1035 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1036 if (!self->extra || self->extra->attrib == Py_None) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1037 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1038 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1039 return PyDict_Keys(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1040 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1041 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1042 static Py_ssize_t |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1043 element_length(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1044 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1045 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1046 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1047 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1048 return self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1049 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1050 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1051 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1052 element_makeelement(PyObject* self, PyObject* args, PyObject* kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1053 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1054 PyObject* elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1055 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1056 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1057 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1058 if (!PyArg_ParseTuple(args, "OO:makeelement", &tag, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1059 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1060 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1061 attrib = PyDict_Copy(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1062 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1063 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1064 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1065 elem = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1066 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1067 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1068 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1069 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1070 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1071 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1072 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1073 element_reduce(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1074 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1075 if (!PyArg_ParseTuple(args, ":__reduce__")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1076 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1077 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1078 /* Hack alert: This method is used to work around a __copy__ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1079 problem on certain 2.3 and 2.4 versions. To save time and |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1080 simplify the code, we create the copy in here, and use a dummy |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1081 copyelement helper to trick the copy module into doing the |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1082 right thing. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1083 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1084 if (!elementtree_copyelement_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1085 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1086 PyExc_RuntimeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1087 "copyelement helper not found" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1088 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1089 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1090 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1091 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1092 return Py_BuildValue( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1093 "O(N)", elementtree_copyelement_obj, element_copy(self, args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1094 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1095 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1096 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1097 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1098 element_remove(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1099 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1100 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1101 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1102 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1103 if (!PyArg_ParseTuple(args, "O!:remove", &Element_Type, &element)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1104 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1105 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1106 if (!self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1107 /* element has no children, so raise exception */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1108 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1109 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1110 "list.remove(x): x not in list" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1111 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1112 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1113 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1114 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1115 for (i = 0; i < self->extra->length; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1116 if (self->extra->children[i] == element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1117 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1118 if (PyObject_Compare(self->extra->children[i], element) == 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1119 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1120 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1121 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1122 if (i == self->extra->length) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1123 /* element is not in children, so raise exception */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1124 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1125 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1126 "list.remove(x): x not in list" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1127 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1128 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1129 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1130 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1131 Py_DECREF(self->extra->children[i]); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1132 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1133 self->extra->length--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1134 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1135 for (; i < self->extra->length; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1136 self->extra->children[i] = self->extra->children[i+1]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1137 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1138 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1139 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1140 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1141 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1142 element_repr(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1143 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1144 PyObject* repr; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1145 char buffer[100]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1146 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1147 repr = PyString_FromString("<Element "); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1148 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1149 PyString_ConcatAndDel(&repr, PyObject_Repr(self->tag)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1150 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1151 sprintf(buffer, " at %p>", self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1152 PyString_ConcatAndDel(&repr, PyString_FromString(buffer)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1153 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1154 return repr; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1155 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1156 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1157 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1158 element_set(ElementObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1159 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1160 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1161 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1162 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1163 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1164 if (!PyArg_ParseTuple(args, "OO:set", &key, &value)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1165 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1166 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1167 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1168 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1169 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1170 attrib = element_get_attrib(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1171 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1172 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1173 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1174 if (PyDict_SetItem(attrib, key, value) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1175 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1176 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1177 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1178 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1179 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1180 static int |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1181 element_setslice(PyObject* self_, Py_ssize_t start, Py_ssize_t end, PyObject* item) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1182 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1183 ElementObject* self = (ElementObject*) self_; |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
1184 Py_ssize_t i, new, old; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1185 PyObject* recycle = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1186 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1187 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1188 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1189 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1190 /* standard clamping */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1191 if (start < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1192 start = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1193 if (end < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1194 end = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1195 if (end > self->extra->length) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1196 end = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1197 if (start > end) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1198 start = end; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1199 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1200 old = end - start; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1201 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1202 if (item == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1203 new = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1204 else if (PyList_CheckExact(item)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1205 new = PyList_GET_SIZE(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1206 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1207 /* FIXME: support arbitrary sequences? */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1208 PyErr_Format( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1209 PyExc_TypeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1210 "expected list, not \"%.200s\"", item->ob_type->tp_name |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1211 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1212 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1213 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1214 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1215 if (old > 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1216 /* to avoid recursive calls to this method (via decref), move |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1217 old items to the recycle bin here, and get rid of them when |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1218 we're done modifying the element */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1219 recycle = PyList_New(old); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1220 for (i = 0; i < old; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1221 PyList_SET_ITEM(recycle, i, self->extra->children[i + start]); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1222 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1223 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1224 if (new < old) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1225 /* delete slice */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1226 for (i = end; i < self->extra->length; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1227 self->extra->children[i + new - old] = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1228 } else if (new > old) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1229 /* insert slice */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1230 if (element_resize(self, new - old) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1231 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1232 for (i = self->extra->length-1; i >= end; i--) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1233 self->extra->children[i + new - old] = self->extra->children[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1234 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1235 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1236 /* replace the slice */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1237 for (i = 0; i < new; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1238 PyObject* element = PyList_GET_ITEM(item, i); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1239 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1240 self->extra->children[i + start] = element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1241 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1242 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1243 self->extra->length += new - old; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1244 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1245 /* discard the recycle bin, and everything in it */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1246 Py_XDECREF(recycle); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1247 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1248 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1249 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1250 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1251 static int |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1252 element_setitem(PyObject* self_, Py_ssize_t index, PyObject* item) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1253 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1254 ElementObject* self = (ElementObject*) self_; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1255 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1256 PyObject* old; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1257 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1258 if (!self->extra || index < 0 || index >= self->extra->length) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1259 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1260 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1261 "child assignment index out of range"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1262 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1263 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1264 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1265 old = self->extra->children[index]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1266 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1267 if (item) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1268 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1269 self->extra->children[index] = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1270 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1271 self->extra->length--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1272 for (i = index; i < self->extra->length; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1273 self->extra->children[i] = self->extra->children[i+1]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1274 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1275 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1276 Py_DECREF(old); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1277 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1278 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1279 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1280 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1281 static PyMethodDef element_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1282 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1283 {"clear", (PyCFunction) element_clear, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1284 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1285 {"get", (PyCFunction) element_get, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1286 {"set", (PyCFunction) element_set, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1287 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1288 {"find", (PyCFunction) element_find, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1289 {"findtext", (PyCFunction) element_findtext, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1290 {"findall", (PyCFunction) element_findall, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1291 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1292 {"append", (PyCFunction) element_append, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1293 {"insert", (PyCFunction) element_insert, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1294 {"remove", (PyCFunction) element_remove, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1295 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1296 {"getiterator", (PyCFunction) element_getiterator, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1297 {"getchildren", (PyCFunction) element_getchildren, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1298 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1299 {"items", (PyCFunction) element_items, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1300 {"keys", (PyCFunction) element_keys, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1301 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1302 {"makeelement", (PyCFunction) element_makeelement, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1303 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1304 {"__copy__", (PyCFunction) element_copy, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1305 {"__deepcopy__", (PyCFunction) element_deepcopy, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1306 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1307 /* Some 2.3 and 2.4 versions do not handle the __copy__ method on |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1308 C objects correctly, so we have to fake it using a __reduce__- |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1309 based hack (see the element_reduce implementation above for |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1310 details). */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1311 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1312 /* The behaviour has been changed in 2.3.5 and 2.4.1, so we're |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1313 using a runtime test to figure out if we need to fake things |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1314 or now (see the init code below). The following entry is |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1315 enabled only if the hack is needed. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1316 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1317 {"!__reduce__", (PyCFunction) element_reduce, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1318 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1319 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1320 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1321 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1322 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1323 element_getattr(ElementObject* self, char* name) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1324 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1325 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1326 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1327 res = Py_FindMethod(element_methods, (PyObject*) self, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1328 if (res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1329 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1330 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1331 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1332 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1333 if (strcmp(name, "tag") == 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1334 res = self->tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1335 else if (strcmp(name, "text") == 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1336 res = element_get_text(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1337 else if (strcmp(name, "tail") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1338 res = element_get_tail(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1339 } else if (strcmp(name, "attrib") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1340 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1341 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1342 res = element_get_attrib(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1343 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1344 PyErr_SetString(PyExc_AttributeError, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1345 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1346 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1347 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1348 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1349 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1350 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1351 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1352 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1353 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1354 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1355 static int |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1356 element_setattr(ElementObject* self, const char* name, PyObject* value) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1357 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1358 if (value == NULL) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1359 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1360 PyExc_AttributeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1361 "can't delete element attributes" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1362 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1363 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1364 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1365 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1366 if (strcmp(name, "tag") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1367 Py_DECREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1368 self->tag = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1369 Py_INCREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1370 } else if (strcmp(name, "text") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1371 Py_DECREF(JOIN_OBJ(self->text)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1372 self->text = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1373 Py_INCREF(self->text); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1374 } else if (strcmp(name, "tail") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1375 Py_DECREF(JOIN_OBJ(self->tail)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1376 self->tail = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1377 Py_INCREF(self->tail); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1378 } else if (strcmp(name, "attrib") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1379 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1380 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1381 Py_DECREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1382 self->extra->attrib = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1383 Py_INCREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1384 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1385 PyErr_SetString(PyExc_AttributeError, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1386 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1387 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1388 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1389 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1390 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1391 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1392 static PySequenceMethods element_as_sequence = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1393 (lenfunc) element_length, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1394 0, /* sq_concat */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1395 0, /* sq_repeat */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1396 element_getitem, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1397 element_getslice, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1398 element_setitem, |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1399 element_setslice, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1400 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1401 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1402 statichere PyTypeObject Element_Type = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1403 PyObject_HEAD_INIT(NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1404 0, "Element", sizeof(ElementObject), 0, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1405 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1406 (destructor)element_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1407 0, /* tp_print */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1408 (getattrfunc)element_getattr, /* tp_getattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1409 (setattrfunc)element_setattr, /* tp_setattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1410 0, /* tp_compare */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1411 (reprfunc)element_repr, /* tp_repr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1412 0, /* tp_as_number */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1413 &element_as_sequence, /* tp_as_sequence */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1414 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1415 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1416 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1417 /* the tree builder type */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1418 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1419 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1420 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1421 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1422 PyObject* root; /* root node (first created node) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1423 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1424 ElementObject* this; /* current node */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1425 ElementObject* last; /* most recently created node */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1426 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1427 PyObject* data; /* data collector (string or list), or NULL */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1428 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1429 PyObject* stack; /* element stack */ |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
1430 Py_ssize_t index; /* current stack size (0=empty) */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1431 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1432 /* element tracing */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1433 PyObject* events; /* list of events, or NULL if not collecting */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1434 PyObject* start_event_obj; /* event objects (NULL to ignore) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1435 PyObject* end_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1436 PyObject* start_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1437 PyObject* end_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1438 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1439 } TreeBuilderObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1440 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1441 staticforward PyTypeObject TreeBuilder_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1442 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1443 #define TreeBuilder_CheckExact(op) ((op)->ob_type == &TreeBuilder_Type) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1444 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1445 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1446 /* constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1447 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1448 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1449 treebuilder_new(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1450 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1451 TreeBuilderObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1452 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1453 self = PyObject_New(TreeBuilderObject, &TreeBuilder_Type); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1454 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1455 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1456 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1457 self->root = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1458 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1459 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1460 self->this = (ElementObject*) Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1461 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1462 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1463 self->last = (ElementObject*) Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1464 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1465 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1466 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1467 self->stack = PyList_New(20); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1468 self->index = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1469 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1470 self->events = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1471 self->start_event_obj = self->end_event_obj = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1472 self->start_ns_event_obj = self->end_ns_event_obj = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1473 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1474 ALLOC(sizeof(TreeBuilderObject), "create treebuilder"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1475 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1476 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1477 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1478 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1479 static PyObject* |
|
38560
d4140f79f1c7
"_self" is a said to be a reserved word in Watcom C 10.6. I'm
Fredrik Lundh <fredrik@pythonware.com>
parents:
38139
diff
changeset
|
1480 treebuilder(PyObject* self_, PyObject* args) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1481 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1482 if (!PyArg_ParseTuple(args, ":TreeBuilder")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1483 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1484 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1485 return treebuilder_new(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1486 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1487 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1488 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1489 treebuilder_dealloc(TreeBuilderObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1490 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1491 Py_XDECREF(self->end_ns_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1492 Py_XDECREF(self->start_ns_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1493 Py_XDECREF(self->end_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1494 Py_XDECREF(self->start_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1495 Py_XDECREF(self->events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1496 Py_DECREF(self->stack); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1497 Py_XDECREF(self->data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1498 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1499 Py_DECREF(self->this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1500 Py_XDECREF(self->root); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1501 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1502 RELEASE(sizeof(TreeBuilderObject), "destroy treebuilder"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1503 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1504 PyObject_Del(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1505 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1506 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1507 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1508 /* handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1509 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1510 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1511 treebuilder_handle_xml(TreeBuilderObject* self, PyObject* encoding, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1512 PyObject* standalone) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1513 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1514 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1515 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1516 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1517 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1518 treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1519 PyObject* attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1520 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1521 PyObject* node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1522 PyObject* this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1523 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1524 if (self->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1525 if (self->this == self->last) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1526 Py_DECREF(JOIN_OBJ(self->last->text)); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1527 self->last->text = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1528 self->data, PyList_CheckExact(self->data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1529 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1530 } else { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1531 Py_DECREF(JOIN_OBJ(self->last->tail)); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1532 self->last->tail = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1533 self->data, PyList_CheckExact(self->data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1534 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1535 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1536 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1537 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1538 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1539 node = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1540 if (!node) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1541 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1542 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1543 this = (PyObject*) self->this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1544 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1545 if (this != Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1546 if (element_add_subelement((ElementObject*) this, node) < 0) |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1547 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1548 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1549 if (self->root) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1550 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1551 PyExc_SyntaxError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1552 "multiple elements on top level" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1553 ); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1554 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1555 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1556 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1557 self->root = node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1558 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1559 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1560 if (self->index < PyList_GET_SIZE(self->stack)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1561 if (PyList_SetItem(self->stack, self->index, this) < 0) |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1562 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1563 Py_INCREF(this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1564 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1565 if (PyList_Append(self->stack, this) < 0) |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1566 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1567 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1568 self->index++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1569 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1570 Py_DECREF(this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1571 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1572 self->this = (ElementObject*) node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1573 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1574 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1575 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1576 self->last = (ElementObject*) node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1577 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1578 if (self->start_event_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1579 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1580 PyObject* action = self->start_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1581 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1582 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1583 Py_INCREF(action); PyTuple_SET_ITEM(res, 0, (PyObject*) action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1584 Py_INCREF(node); PyTuple_SET_ITEM(res, 1, (PyObject*) node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1585 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1586 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1587 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1588 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1589 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1590 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1591 return node; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1592 |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1593 error: |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1594 Py_DECREF(node); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1595 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1596 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1597 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1598 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1599 treebuilder_handle_data(TreeBuilderObject* self, PyObject* data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1600 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1601 if (!self->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1602 /* store the first item as is */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1603 Py_INCREF(data); self->data = data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1604 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1605 /* more than one item; use a list to collect items */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1606 if (PyString_CheckExact(self->data) && self->data->ob_refcnt == 1 && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1607 PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1608 /* expat often generates single character data sections; handle |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1609 the most common case by resizing the existing string... */ |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
1610 Py_ssize_t size = PyString_GET_SIZE(self->data); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1611 if (_PyString_Resize(&self->data, size + 1) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1612 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1613 PyString_AS_STRING(self->data)[size] = PyString_AS_STRING(data)[0]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1614 } else if (PyList_CheckExact(self->data)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1615 if (PyList_Append(self->data, data) < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1616 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1617 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1618 PyObject* list = PyList_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1619 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1620 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1621 PyList_SET_ITEM(list, 0, self->data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1622 Py_INCREF(data); PyList_SET_ITEM(list, 1, data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1623 self->data = list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1624 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1625 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1626 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1627 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1628 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1629 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1630 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1631 treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1632 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1633 PyObject* item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1634 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1635 if (self->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1636 if (self->this == self->last) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1637 Py_DECREF(JOIN_OBJ(self->last->text)); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1638 self->last->text = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1639 self->data, PyList_CheckExact(self->data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1640 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1641 } else { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1642 Py_DECREF(JOIN_OBJ(self->last->tail)); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1643 self->last->tail = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1644 self->data, PyList_CheckExact(self->data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1645 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1646 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1647 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1648 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1649 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1650 if (self->index == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1651 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1652 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1653 "pop from empty stack" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1654 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1655 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1656 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1657 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1658 self->index--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1659 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1660 item = PyList_GET_ITEM(self->stack, self->index); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1661 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1662 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1663 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1664 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1665 self->last = (ElementObject*) self->this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1666 self->this = (ElementObject*) item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1667 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1668 if (self->end_event_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1669 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1670 PyObject* action = self->end_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1671 PyObject* node = (PyObject*) self->last; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1672 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1673 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1674 Py_INCREF(action); PyTuple_SET_ITEM(res, 0, (PyObject*) action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1675 Py_INCREF(node); PyTuple_SET_ITEM(res, 1, (PyObject*) node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1676 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1677 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1678 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1679 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1680 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1681 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1682 Py_INCREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1683 return (PyObject*) self->last; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1684 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1685 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1686 LOCAL(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1687 treebuilder_handle_namespace(TreeBuilderObject* self, int start, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1688 const char* prefix, const char *uri) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1689 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1690 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1691 PyObject* action; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1692 PyObject* parcel; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1693 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1694 if (!self->events) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1695 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1696 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1697 if (start) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1698 if (!self->start_ns_event_obj) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1699 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1700 action = self->start_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1701 /* FIXME: prefix and uri use utf-8 encoding! */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1702 parcel = Py_BuildValue("ss", (prefix) ? prefix : "", uri); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1703 if (!parcel) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1704 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1705 Py_INCREF(action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1706 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1707 if (!self->end_ns_event_obj) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1708 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1709 action = self->end_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1710 Py_INCREF(action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1711 parcel = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1712 Py_INCREF(parcel); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1713 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1714 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1715 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1716 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1717 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1718 PyTuple_SET_ITEM(res, 0, action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1719 PyTuple_SET_ITEM(res, 1, parcel); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1720 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1721 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1722 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1723 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1724 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1725 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1726 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1727 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1728 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1729 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1730 treebuilder_data(TreeBuilderObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1731 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1732 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1733 if (!PyArg_ParseTuple(args, "O:data", &data)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1734 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1735 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1736 return treebuilder_handle_data(self, data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1737 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1738 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1739 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1740 treebuilder_end(TreeBuilderObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1741 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1742 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1743 if (!PyArg_ParseTuple(args, "O:end", &tag)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1744 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1745 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1746 return treebuilder_handle_end(self, tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1747 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1748 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1749 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1750 treebuilder_done(TreeBuilderObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1751 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1752 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1753 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1754 /* FIXME: check stack size? */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1755 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1756 if (self->root) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1757 res = self->root; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1758 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1759 res = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1760 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1761 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1762 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1763 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1764 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1765 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1766 treebuilder_close(TreeBuilderObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1767 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1768 if (!PyArg_ParseTuple(args, ":close")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1769 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1770 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1771 return treebuilder_done(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1772 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1773 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1774 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1775 treebuilder_start(TreeBuilderObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1776 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1777 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1778 PyObject* attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1779 if (!PyArg_ParseTuple(args, "O|O:start", &tag, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1780 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1781 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1782 return treebuilder_handle_start(self, tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1783 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1784 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1785 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1786 treebuilder_xml(TreeBuilderObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1787 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1788 PyObject* encoding; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1789 PyObject* standalone; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1790 if (!PyArg_ParseTuple(args, "OO:xml", &encoding, &standalone)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1791 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1792 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1793 return treebuilder_handle_xml(self, encoding, standalone); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1794 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1795 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1796 static PyMethodDef treebuilder_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1797 {"data", (PyCFunction) treebuilder_data, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1798 {"start", (PyCFunction) treebuilder_start, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1799 {"end", (PyCFunction) treebuilder_end, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1800 {"xml", (PyCFunction) treebuilder_xml, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1801 {"close", (PyCFunction) treebuilder_close, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1802 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1803 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1804 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1805 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1806 treebuilder_getattr(TreeBuilderObject* self, char* name) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1807 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1808 return Py_FindMethod(treebuilder_methods, (PyObject*) self, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1809 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1810 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1811 statichere PyTypeObject TreeBuilder_Type = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1812 PyObject_HEAD_INIT(NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1813 0, "TreeBuilder", sizeof(TreeBuilderObject), 0, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1814 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1815 (destructor)treebuilder_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1816 0, /* tp_print */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1817 (getattrfunc)treebuilder_getattr, /* tp_getattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1818 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1819 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1820 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1821 /* the expat interface */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1822 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1823 #if defined(USE_EXPAT) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1824 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1825 #include "expat.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1826 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1827 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1828 #include "pyexpat.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1829 static struct PyExpat_CAPI* expat_capi; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1830 #define EXPAT(func) (expat_capi->func) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1831 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1832 #define EXPAT(func) (XML_##func) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1833 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1834 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1835 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1836 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1837 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1838 XML_Parser parser; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1839 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1840 PyObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1841 PyObject* entity; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1842 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1843 PyObject* names; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1844 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1845 PyObject* handle_xml; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1846 PyObject* handle_start; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1847 PyObject* handle_data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1848 PyObject* handle_end; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1849 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1850 PyObject* handle_comment; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1851 PyObject* handle_pi; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1852 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1853 } XMLParserObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1854 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1855 staticforward PyTypeObject XMLParser_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1856 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1857 /* helpers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1858 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1859 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1860 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1861 checkstring(const char* string, int size) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1862 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1863 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1864 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1865 /* check if an 8-bit string contains UTF-8 characters */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1866 for (i = 0; i < size; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1867 if (string[i] & 0x80) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1868 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1869 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1870 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1871 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1872 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1873 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1874 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1875 makestring(const char* string, int size) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1876 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1877 /* convert a UTF-8 string to either a 7-bit ascii string or a |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1878 Unicode string */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1879 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1880 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1881 if (checkstring(string, size)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1882 return PyUnicode_DecodeUTF8(string, size, "strict"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1883 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1884 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1885 return PyString_FromStringAndSize(string, size); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1886 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1887 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1888 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1889 makeuniversal(XMLParserObject* self, const char* string) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1890 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1891 /* convert a UTF-8 tag/attribute name from the expat parser |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1892 to a universal name string */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1893 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1894 int size = strlen(string); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1895 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1896 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1897 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1898 /* look the 'raw' name up in the names dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1899 key = PyString_FromStringAndSize(string, size); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1900 if (!key) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1901 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1902 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1903 value = PyDict_GetItem(self->names, key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1904 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1905 if (value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1906 Py_INCREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1907 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1908 /* new name. convert to universal name, and decode as |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1909 necessary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1910 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1911 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1912 char* p; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1913 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1914 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1915 /* look for namespace separator */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1916 for (i = 0; i < size; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1917 if (string[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1918 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1919 if (i != size) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1920 /* convert to universal name */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1921 tag = PyString_FromStringAndSize(NULL, size+1); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1922 p = PyString_AS_STRING(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1923 p[0] = '{'; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1924 memcpy(p+1, string, size); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1925 size++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1926 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1927 /* plain name; use key as tag */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1928 Py_INCREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1929 tag = key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1930 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1931 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1932 /* decode universal name */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1933 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1934 /* inline makestring, to avoid duplicating the source string if |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1935 it's not an utf-8 string */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1936 p = PyString_AS_STRING(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1937 if (checkstring(p, size)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1938 value = PyUnicode_DecodeUTF8(p, size, "strict"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1939 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1940 if (!value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1941 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1942 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1943 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1944 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1945 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1946 value = tag; /* use tag as is */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1947 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1948 /* add to names dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1949 if (PyDict_SetItem(self->names, key, value) < 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1950 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1951 Py_DECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1952 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1953 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1954 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1955 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1956 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1957 return value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1958 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1959 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1960 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1961 /* handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1962 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1963 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1964 expat_default_handler(XMLParserObject* self, const XML_Char* data_in, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1965 int data_len) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1966 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1967 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1968 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1969 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1970 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1971 if (data_len < 2 || data_in[0] != '&') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1972 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1973 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1974 key = makestring(data_in + 1, data_len - 2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1975 if (!key) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1976 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1977 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1978 value = PyDict_GetItem(self->entity, key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1979 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1980 if (value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1981 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1982 res = treebuilder_handle_data( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1983 (TreeBuilderObject*) self->target, value |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1984 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1985 else if (self->handle_data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1986 res = PyObject_CallFunction(self->handle_data, "O", value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1987 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1988 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1989 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1990 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1991 PyErr_Format( |
|
38885
f19e877281e4
Upgrade pyexpat to expat 2.0.0 (http://python.org/sf/1462338).
Trent Mick <trentm@activestate.com>
parents:
38759
diff
changeset
|
1992 PyExc_SyntaxError, "undefined entity &%s;: line %ld, column %ld", |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1993 PyString_AS_STRING(key), |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1994 EXPAT(GetErrorLineNumber)(self->parser), |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1995 EXPAT(GetErrorColumnNumber)(self->parser) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1996 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1997 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1998 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1999 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2000 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2001 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2002 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2003 expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2004 const XML_Char **attrib_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2005 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2006 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2007 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2008 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2009 int ok; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2010 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2011 /* tag name */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2012 tag = makeuniversal(self, tag_in); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2013 if (!tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2014 return; /* parser will look for errors */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2015 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2016 /* attributes */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2017 if (attrib_in[0]) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2018 attrib = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2019 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2020 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2021 while (attrib_in[0] && attrib_in[1]) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2022 PyObject* key = makeuniversal(self, attrib_in[0]); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2023 PyObject* value = makestring(attrib_in[1], strlen(attrib_in[1])); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2024 if (!key || !value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2025 Py_XDECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2026 Py_XDECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2027 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2028 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2029 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2030 ok = PyDict_SetItem(attrib, key, value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2031 Py_DECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2032 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2033 if (ok < 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2034 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2035 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2036 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2037 attrib_in += 2; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2038 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2039 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2040 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2041 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2042 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2043 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2044 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2045 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2046 res = treebuilder_handle_start((TreeBuilderObject*) self->target, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2047 tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2048 else if (self->handle_start) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2049 res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2050 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2051 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2052 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2053 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2054 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2055 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2056 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2057 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2058 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2059 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2060 expat_data_handler(XMLParserObject* self, const XML_Char* data_in, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2061 int data_len) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2062 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2063 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2064 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2065 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2066 data = makestring(data_in, data_len); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2067 if (!data) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2068 return; /* parser will look for errors */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2069 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2070 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2071 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2072 res = treebuilder_handle_data((TreeBuilderObject*) self->target, data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2073 else if (self->handle_data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2074 res = PyObject_CallFunction(self->handle_data, "O", data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2075 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2076 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2077 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2078 Py_DECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2079 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2080 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2081 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2082 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2083 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2084 expat_end_handler(XMLParserObject* self, const XML_Char* tag_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2085 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2086 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2087 PyObject* res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2088 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2089 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2090 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2091 /* the standard tree builder doesn't look at the end tag */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2092 res = treebuilder_handle_end( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2093 (TreeBuilderObject*) self->target, Py_None |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2094 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2095 else if (self->handle_end) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2096 tag = makeuniversal(self, tag_in); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2097 if (tag) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2098 res = PyObject_CallFunction(self->handle_end, "O", tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2099 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2100 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2101 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2102 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2103 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2104 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2105 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2106 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2107 expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2108 const XML_Char *uri) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2109 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2110 treebuilder_handle_namespace( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2111 (TreeBuilderObject*) self->target, 1, prefix, uri |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2112 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2113 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2114 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2115 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2116 expat_end_ns_handler(XMLParserObject* self, const XML_Char* prefix_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2117 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2118 treebuilder_handle_namespace( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2119 (TreeBuilderObject*) self->target, 0, NULL, NULL |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2120 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2121 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2122 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2123 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2124 expat_comment_handler(XMLParserObject* self, const XML_Char* comment_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2125 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2126 PyObject* comment; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2127 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2128 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2129 if (self->handle_comment) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2130 comment = makestring(comment_in, strlen(comment_in)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2131 if (comment) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2132 res = PyObject_CallFunction(self->handle_comment, "O", comment); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2133 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2134 Py_DECREF(comment); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2135 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2136 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2137 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2138 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2139 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2140 expat_pi_handler(XMLParserObject* self, const XML_Char* target_in, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2141 const XML_Char* data_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2142 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2143 PyObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2144 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2145 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2146 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2147 if (self->handle_pi) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2148 target = makestring(target_in, strlen(target_in)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2149 data = makestring(data_in, strlen(data_in)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2150 if (target && data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2151 res = PyObject_CallFunction(self->handle_pi, "OO", target, data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2152 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2153 Py_DECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2154 Py_DECREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2155 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2156 Py_XDECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2157 Py_XDECREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2158 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2159 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2160 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2161 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2162 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2163 static int |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2164 expat_unknown_encoding_handler(XMLParserObject *self, const XML_Char *name, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2165 XML_Encoding *info) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2166 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2167 PyObject* u; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2168 Py_UNICODE* p; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2169 unsigned char s[256]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2170 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2171 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2172 memset(info, 0, sizeof(XML_Encoding)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2173 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2174 for (i = 0; i < 256; i++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2175 s[i] = i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2176 |
| 36117 | 2177 u = PyUnicode_Decode((char*) s, 256, name, "replace"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2178 if (!u) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2179 return XML_STATUS_ERROR; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2180 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2181 if (PyUnicode_GET_SIZE(u) != 256) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2182 Py_DECREF(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2183 return XML_STATUS_ERROR; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2184 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2185 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2186 p = PyUnicode_AS_UNICODE(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2187 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2188 for (i = 0; i < 256; i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2189 if (p[i] != Py_UNICODE_REPLACEMENT_CHARACTER) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2190 info->map[i] = p[i]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2191 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2192 info->map[i] = -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2193 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2194 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2195 Py_DECREF(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2196 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2197 return XML_STATUS_OK; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2198 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2199 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2200 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2201 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2202 /* constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2203 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2204 static PyObject* |
|
38560
d4140f79f1c7
"_self" is a said to be a reserved word in Watcom C 10.6. I'm
Fredrik Lundh <fredrik@pythonware.com>
parents:
38139
diff
changeset
|
2205 xmlparser(PyObject* self_, PyObject* args, PyObject* kw) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2206 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2207 XMLParserObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2208 /* FIXME: does this need to be static? */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2209 static XML_Memory_Handling_Suite memory_handler; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2210 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2211 PyObject* target = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2212 char* encoding = NULL; |
| 36684 | 2213 static char* kwlist[] = { "target", "encoding", NULL }; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2214 if (!PyArg_ParseTupleAndKeywords(args, kw, "|Oz:XMLParser", kwlist, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2215 &target, &encoding)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2216 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2217 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2218 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2219 if (!expat_capi) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2220 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2221 PyExc_RuntimeError, "cannot load dispatch table from pyexpat" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2222 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2223 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2224 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2225 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2226 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2227 self = PyObject_New(XMLParserObject, &XMLParser_Type); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2228 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2229 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2230 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2231 self->entity = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2232 if (!self->entity) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2233 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2234 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2235 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2236 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2237 self->names = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2238 if (!self->names) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2239 PyObject_Del(self->entity); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2240 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2241 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2242 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2243 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2244 memory_handler.malloc_fcn = PyObject_Malloc; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2245 memory_handler.realloc_fcn = PyObject_Realloc; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2246 memory_handler.free_fcn = PyObject_Free; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2247 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2248 self->parser = EXPAT(ParserCreate_MM)(encoding, &memory_handler, "}"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2249 if (!self->parser) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2250 PyObject_Del(self->names); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2251 PyObject_Del(self->entity); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2252 PyObject_Del(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2253 PyErr_NoMemory(); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2254 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2255 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2256 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2257 /* setup target handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2258 if (!target) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2259 target = treebuilder_new(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2260 if (!target) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2261 EXPAT(ParserFree)(self->parser); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2262 PyObject_Del(self->names); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2263 PyObject_Del(self->entity); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2264 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2265 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2266 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2267 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2268 Py_INCREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2269 self->target = target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2270 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2271 self->handle_xml = PyObject_GetAttrString(target, "xml"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2272 self->handle_start = PyObject_GetAttrString(target, "start"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2273 self->handle_data = PyObject_GetAttrString(target, "data"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2274 self->handle_end = PyObject_GetAttrString(target, "end"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2275 self->handle_comment = PyObject_GetAttrString(target, "comment"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2276 self->handle_pi = PyObject_GetAttrString(target, "pi"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2277 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2278 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2279 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2280 /* configure parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2281 EXPAT(SetUserData)(self->parser, self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2282 EXPAT(SetElementHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2283 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2284 (XML_StartElementHandler) expat_start_handler, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2285 (XML_EndElementHandler) expat_end_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2286 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2287 EXPAT(SetDefaultHandlerExpand)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2288 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2289 (XML_DefaultHandler) expat_default_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2290 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2291 EXPAT(SetCharacterDataHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2292 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2293 (XML_CharacterDataHandler) expat_data_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2294 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2295 if (self->handle_comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2296 EXPAT(SetCommentHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2297 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2298 (XML_CommentHandler) expat_comment_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2299 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2300 if (self->handle_pi) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2301 EXPAT(SetProcessingInstructionHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2302 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2303 (XML_ProcessingInstructionHandler) expat_pi_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2304 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2305 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2306 EXPAT(SetUnknownEncodingHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2307 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2308 (XML_UnknownEncodingHandler) expat_unknown_encoding_handler, NULL |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2309 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2310 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2311 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2312 ALLOC(sizeof(XMLParserObject), "create expatparser"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2313 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2314 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2315 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2316 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2317 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2318 xmlparser_dealloc(XMLParserObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2319 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2320 EXPAT(ParserFree)(self->parser); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2321 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2322 Py_XDECREF(self->handle_pi); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2323 Py_XDECREF(self->handle_comment); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2324 Py_XDECREF(self->handle_end); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2325 Py_XDECREF(self->handle_data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2326 Py_XDECREF(self->handle_start); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2327 Py_XDECREF(self->handle_xml); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2328 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2329 Py_DECREF(self->target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2330 Py_DECREF(self->entity); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2331 Py_DECREF(self->names); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2332 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2333 RELEASE(sizeof(XMLParserObject), "destroy expatparser"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2334 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2335 PyObject_Del(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2336 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2337 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2338 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2339 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2340 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2341 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2342 expat_parse(XMLParserObject* self, char* data, int data_len, int final) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2343 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2344 int ok; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2345 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2346 ok = EXPAT(Parse)(self->parser, data, data_len, final); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2347 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2348 if (PyErr_Occurred()) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2349 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2350 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2351 if (!ok) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2352 PyErr_Format( |
|
38885
f19e877281e4
Upgrade pyexpat to expat 2.0.0 (http://python.org/sf/1462338).
Trent Mick <trentm@activestate.com>
parents:
38759
diff
changeset
|
2353 PyExc_SyntaxError, "%s: line %ld, column %ld", |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2354 EXPAT(ErrorString)(EXPAT(GetErrorCode)(self->parser)), |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2355 EXPAT(GetErrorLineNumber)(self->parser), |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2356 EXPAT(GetErrorColumnNumber)(self->parser) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2357 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2358 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2359 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2360 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2361 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2362 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2363 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2364 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2365 xmlparser_close(XMLParserObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2366 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2367 /* end feeding data to parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2368 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2369 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2370 if (!PyArg_ParseTuple(args, ":close")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2371 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2372 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2373 res = expat_parse(self, "", 0, 1); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2374 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2375 if (res && TreeBuilder_CheckExact(self->target)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2376 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2377 return treebuilder_done((TreeBuilderObject*) self->target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2378 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2379 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2380 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2381 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2382 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2383 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2384 xmlparser_feed(XMLParserObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2385 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2386 /* feed data to parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2387 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2388 char* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2389 int data_len; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2390 if (!PyArg_ParseTuple(args, "s#:feed", &data, &data_len)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2391 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2392 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2393 return expat_parse(self, data, data_len, 0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2394 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2395 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2396 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2397 xmlparser_parse(XMLParserObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2398 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2399 /* (internal) parse until end of input stream */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2400 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2401 PyObject* reader; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2402 PyObject* buffer; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2403 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2404 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2405 PyObject* fileobj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2406 if (!PyArg_ParseTuple(args, "O:_parse", &fileobj)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2407 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2408 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2409 reader = PyObject_GetAttrString(fileobj, "read"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2410 if (!reader) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2411 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2412 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2413 /* read from open file object */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2414 for (;;) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2415 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2416 buffer = PyObject_CallFunction(reader, "i", 64*1024); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2417 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2418 if (!buffer) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2419 /* read failed (e.g. due to KeyboardInterrupt) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2420 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2421 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2422 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2423 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2424 if (!PyString_CheckExact(buffer) || PyString_GET_SIZE(buffer) == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2425 Py_DECREF(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2426 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2427 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2428 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2429 res = expat_parse( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2430 self, PyString_AS_STRING(buffer), PyString_GET_SIZE(buffer), 0 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2431 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2432 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2433 Py_DECREF(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2434 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2435 if (!res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2436 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2437 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2438 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2439 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2440 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2441 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2442 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2443 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2444 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2445 res = expat_parse(self, "", 0, 1); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2446 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2447 if (res && TreeBuilder_CheckExact(self->target)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2448 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2449 return treebuilder_done((TreeBuilderObject*) self->target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2450 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2451 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2452 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2453 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2454 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2455 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2456 xmlparser_setevents(XMLParserObject* self, PyObject* args) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2457 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2458 /* activate element event reporting */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2459 |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
2460 Py_ssize_t i; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2461 TreeBuilderObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2462 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2463 PyObject* events; /* event collector */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2464 PyObject* event_set = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2465 if (!PyArg_ParseTuple(args, "O!|O:_setevents", &PyList_Type, &events, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2466 &event_set)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2467 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2468 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2469 if (!TreeBuilder_CheckExact(self->target)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2470 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2471 PyExc_TypeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2472 "event handling only supported for cElementTree.Treebuilder " |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2473 "targets" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2474 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2475 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2476 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2477 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2478 target = (TreeBuilderObject*) self->target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2479 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2480 Py_INCREF(events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2481 Py_XDECREF(target->events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2482 target->events = events; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2483 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2484 /* clear out existing events */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2485 Py_XDECREF(target->start_event_obj); target->start_event_obj = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2486 Py_XDECREF(target->end_event_obj); target->end_event_obj = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2487 Py_XDECREF(target->start_ns_event_obj); target->start_ns_event_obj = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2488 Py_XDECREF(target->end_ns_event_obj); target->end_ns_event_obj = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2489 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2490 if (event_set == Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2491 /* default is "end" only */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2492 target->end_event_obj = PyString_FromString("end"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2493 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2494 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2495 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2496 if (!PyTuple_Check(event_set)) /* FIXME: handle arbitrary sequences */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2497 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2498 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2499 for (i = 0; i < PyTuple_GET_SIZE(event_set); i++) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2500 PyObject* item = PyTuple_GET_ITEM(event_set, i); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2501 char* event; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2502 if (!PyString_Check(item)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2503 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2504 event = PyString_AS_STRING(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2505 if (strcmp(event, "start") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2506 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2507 target->start_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2508 } else if (strcmp(event, "end") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2509 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2510 Py_XDECREF(target->end_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2511 target->end_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2512 } else if (strcmp(event, "start-ns") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2513 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2514 Py_XDECREF(target->start_ns_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2515 target->start_ns_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2516 EXPAT(SetNamespaceDeclHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2517 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2518 (XML_StartNamespaceDeclHandler) expat_start_ns_handler, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2519 (XML_EndNamespaceDeclHandler) expat_end_ns_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2520 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2521 } else if (strcmp(event, "end-ns") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2522 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2523 Py_XDECREF(target->end_ns_event_obj); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2524 target->end_ns_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2525 EXPAT(SetNamespaceDeclHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2526 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2527 (XML_StartNamespaceDeclHandler) expat_start_ns_handler, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2528 (XML_EndNamespaceDeclHandler) expat_end_ns_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2529 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2530 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2531 PyErr_Format( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2532 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2533 "unknown event '%s'", event |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2534 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2535 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2536 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2537 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2538 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2539 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2540 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2541 error: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2542 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2543 PyExc_TypeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2544 "invalid event tuple" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2545 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2546 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2547 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2548 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2549 static PyMethodDef xmlparser_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2550 {"feed", (PyCFunction) xmlparser_feed, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2551 {"close", (PyCFunction) xmlparser_close, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2552 {"_parse", (PyCFunction) xmlparser_parse, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2553 {"_setevents", (PyCFunction) xmlparser_setevents, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2554 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2555 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2556 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2557 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2558 xmlparser_getattr(XMLParserObject* self, char* name) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2559 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2560 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2561 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2562 res = Py_FindMethod(xmlparser_methods, (PyObject*) self, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2563 if (res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2564 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2565 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2566 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2567 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2568 if (strcmp(name, "entity") == 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2569 res = self->entity; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2570 else if (strcmp(name, "target") == 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2571 res = self->target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2572 else if (strcmp(name, "version") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2573 char buffer[100]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2574 sprintf(buffer, "Expat %d.%d.%d", XML_MAJOR_VERSION, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2575 XML_MINOR_VERSION, XML_MICRO_VERSION); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2576 return PyString_FromString(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2577 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2578 PyErr_SetString(PyExc_AttributeError, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2579 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2580 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2581 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2582 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2583 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2584 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2585 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2586 statichere PyTypeObject XMLParser_Type = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2587 PyObject_HEAD_INIT(NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2588 0, "XMLParser", sizeof(XMLParserObject), 0, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2589 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2590 (destructor)xmlparser_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2591 0, /* tp_print */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2592 (getattrfunc)xmlparser_getattr, /* tp_getattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2593 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2594 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2595 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2596 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2597 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2598 /* python module interface */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2599 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2600 static PyMethodDef _functions[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2601 {"Element", (PyCFunction) element, METH_VARARGS|METH_KEYWORDS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2602 {"SubElement", (PyCFunction) subelement, METH_VARARGS|METH_KEYWORDS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2603 {"TreeBuilder", (PyCFunction) treebuilder, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2604 #if defined(USE_EXPAT) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2605 {"XMLParser", (PyCFunction) xmlparser, METH_VARARGS|METH_KEYWORDS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2606 {"XMLTreeBuilder", (PyCFunction) xmlparser, METH_VARARGS|METH_KEYWORDS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2607 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2608 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2609 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2610 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2611 DL_EXPORT(void) |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2612 init_elementtree(void) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2613 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2614 PyObject* m; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2615 PyObject* g; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2616 char* bootstrap; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2617 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2618 struct PyExpat_CAPI* capi; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2619 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2620 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2621 /* Patch object type */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2622 Element_Type.ob_type = TreeBuilder_Type.ob_type = &PyType_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2623 #if defined(USE_EXPAT) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2624 XMLParser_Type.ob_type = &PyType_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2625 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2626 |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2627 m = Py_InitModule("_elementtree", _functions); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2628 if (!m) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2629 return; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2630 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2631 /* python glue code */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2632 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2633 g = PyDict_New(); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2634 if (!g) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2635 return; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2636 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2637 PyDict_SetItemString(g, "__builtins__", PyEval_GetBuiltins()); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2638 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2639 bootstrap = ( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2640 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2641 #if (PY_VERSION_HEX >= 0x02020000 && PY_VERSION_HEX < 0x02030000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2642 "from __future__ import generators\n" /* enable yield under 2.2 */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2643 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2644 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2645 "from copy import copy, deepcopy\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2646 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2647 "try:\n" |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2648 " from xml.etree import ElementTree\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2649 "except ImportError:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2650 " import ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2651 "ET = ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2652 "del ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2653 |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2654 "import _elementtree as cElementTree\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2655 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2656 "try:\n" /* check if copy works as is */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2657 " copy(cElementTree.Element('x'))\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2658 "except:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2659 " def copyelement(elem):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2660 " return elem\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2661 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2662 "def Comment(text=None):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2663 " element = cElementTree.Element(ET.Comment)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2664 " element.text = text\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2665 " return element\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2666 "cElementTree.Comment = Comment\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2667 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2668 "class ElementTree(ET.ElementTree):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2669 " def parse(self, source, parser=None):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2670 " if not hasattr(source, 'read'):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2671 " source = open(source, 'rb')\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2672 " if parser is not None:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2673 " while 1:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2674 " data = source.read(65536)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2675 " if not data:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2676 " break\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2677 " parser.feed(data)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2678 " self._root = parser.close()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2679 " else:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2680 " parser = cElementTree.XMLParser()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2681 " self._root = parser._parse(source)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2682 " return self._root\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2683 "cElementTree.ElementTree = ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2684 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2685 "def getiterator(node, tag=None):\n" /* helper */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2686 " if tag == '*':\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2687 " tag = None\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2688 #if (PY_VERSION_HEX < 0x02020000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2689 " nodes = []\n" /* 2.1 doesn't have yield */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2690 " if tag is None or node.tag == tag:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2691 " nodes.append(node)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2692 " for node in node:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2693 " nodes.extend(getiterator(node, tag))\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2694 " return nodes\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2695 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2696 " if tag is None or node.tag == tag:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2697 " yield node\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2698 " for node in node:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2699 " for node in getiterator(node, tag):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2700 " yield node\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2701 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2702 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2703 "def parse(source, parser=None):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2704 " tree = ElementTree()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2705 " tree.parse(source, parser)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2706 " return tree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2707 "cElementTree.parse = parse\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2708 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2709 #if (PY_VERSION_HEX < 0x02020000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2710 "if hasattr(ET, 'iterparse'):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2711 " cElementTree.iterparse = ET.iterparse\n" /* delegate on 2.1 */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2712 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2713 "class iterparse(object):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2714 " root = None\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2715 " def __init__(self, file, events=None):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2716 " if not hasattr(file, 'read'):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2717 " file = open(file, 'rb')\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2718 " self._file = file\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2719 " self._events = events\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2720 " def __iter__(self):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2721 " events = []\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2722 " b = cElementTree.TreeBuilder()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2723 " p = cElementTree.XMLParser(b)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2724 " p._setevents(events, self._events)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2725 " while 1:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2726 " data = self._file.read(16384)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2727 " if not data:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2728 " break\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2729 " p.feed(data)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2730 " for event in events:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2731 " yield event\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2732 " del events[:]\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2733 " root = p.close()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2734 " for event in events:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2735 " yield event\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2736 " self.root = root\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2737 "cElementTree.iterparse = iterparse\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2738 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2739 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2740 "def PI(target, text=None):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2741 " element = cElementTree.Element(ET.ProcessingInstruction)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2742 " element.text = target\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2743 " if text:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2744 " element.text = element.text + ' ' + text\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2745 " return element\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2746 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2747 " elem = cElementTree.Element(ET.PI)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2748 " elem.text = text\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2749 " return elem\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2750 "cElementTree.PI = cElementTree.ProcessingInstruction = PI\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2751 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2752 "def XML(text):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2753 " parser = cElementTree.XMLParser()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2754 " parser.feed(text)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2755 " return parser.close()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2756 "cElementTree.XML = cElementTree.fromstring = XML\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2757 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2758 "def XMLID(text):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2759 " tree = XML(text)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2760 " ids = {}\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2761 " for elem in tree.getiterator():\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2762 " id = elem.get('id')\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2763 " if id:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2764 " ids[id] = elem\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2765 " return tree, ids\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2766 "cElementTree.XMLID = XMLID\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2767 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2768 "cElementTree.dump = ET.dump\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2769 "cElementTree.ElementPath = ElementPath = ET.ElementPath\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2770 "cElementTree.iselement = ET.iselement\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2771 "cElementTree.QName = ET.QName\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2772 "cElementTree.tostring = ET.tostring\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2773 "cElementTree.VERSION = '" VERSION "'\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2774 "cElementTree.__version__ = '" VERSION "'\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2775 "cElementTree.XMLParserError = SyntaxError\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2776 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2777 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2778 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2779 PyRun_String(bootstrap, Py_file_input, g, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2780 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2781 elementpath_obj = PyDict_GetItemString(g, "ElementPath"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2782 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2783 elementtree_copyelement_obj = PyDict_GetItemString(g, "copyelement"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2784 if (elementtree_copyelement_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2785 /* reduce hack needed; enable reduce method */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2786 PyMethodDef* mp; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2787 for (mp = element_methods; mp->ml_name; mp++) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2788 if (mp->ml_meth == (PyCFunction) element_reduce) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2789 mp->ml_name = "__reduce__"; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2790 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2791 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2792 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2793 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2794 elementtree_deepcopy_obj = PyDict_GetItemString(g, "deepcopy"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2795 elementtree_getiterator_obj = PyDict_GetItemString(g, "getiterator"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2796 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2797 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2798 /* link against pyexpat, if possible */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2799 capi = PyCObject_Import("pyexpat", "expat_CAPI"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2800 if (capi && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2801 strcmp(capi->magic, PyExpat_CAPI_MAGIC) == 0 && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2802 capi->size <= sizeof(*expat_capi) && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2803 capi->MAJOR_VERSION == XML_MAJOR_VERSION && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2804 capi->MINOR_VERSION == XML_MINOR_VERSION && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2805 capi->MICRO_VERSION == XML_MICRO_VERSION) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2806 expat_capi = capi; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2807 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2808 expat_capi = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2809 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2810 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2811 } |
