Mercurial > cpython-lru_cache-weakref
annotate Modules/_elementtree.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | e1dde980a92c |
| children | b3efc140d8a6 |
| 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 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3 * $Id: _elementtree.c 3473 2009-01-11 22:53:55Z 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 * 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
|
11 * 2004-06-03 fl updates for elementtree 1.2 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
12 * 2005-01-05 fl major optimization effort |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * 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
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * 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
|
22 * 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
|
23 * 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
|
24 * 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
|
25 * 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
|
26 * 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
|
27 * 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
|
28 * 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
|
29 * 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
|
30 * 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
|
31 * 2006-03-12 fl merge in 2.5 ssize_t changes |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
32 * 2007-08-25 fl call custom builder's close method from XMLParser |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
33 * 2007-08-31 fl added iter, extend from ET 1.3 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
34 * 2007-09-01 fl fixed ParseError exception, setslice source type, etc |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
35 * 2007-09-03 fl fixed handling of negative insert indexes |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
36 * 2007-09-04 fl added itertext from ET 1.3 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
37 * 2007-09-06 fl added position attribute to ParseError exception |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
38 * 2008-06-06 fl delay error reporting in iterparse (from Hrvoje Niksic) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
39 * |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
40 * Copyright (c) 1999-2009 by Secret Labs AB. All rights reserved. |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
41 * Copyright (c) 1999-2009 by Fredrik Lundh. |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
42 * |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
43 * info@pythonware.com |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
44 * http://www.pythonware.com |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
45 */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
46 |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
47 /* Licensed to PSF under a Contributor Agreement. */ |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
48 /* See http://www.python.org/psf/license for licensing details. */ |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
49 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
50 #include "Python.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
51 |
| 39528 | 52 #define VERSION "1.0.6" |
|
36050
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 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 /* configuration */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 /* 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
|
58 #define USE_EXPAT |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
59 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
60 /* Define to do all expat calls via pyexpat's embedded expat library */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
61 /* #define USE_PYEXPAT_CAPI */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
62 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
63 /* 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
|
64 allocations. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
65 #define STATIC_CHILDREN 4 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
66 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
67 /* 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
|
68 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
|
69 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
|
70 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
|
71 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
72 /* 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
|
73 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
|
74 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
|
75 32-bit platforms. */ |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
79 #if 0 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
80 static int memory = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
81 #define ALLOC(size, comment)\ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
82 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
|
83 #define RELEASE(size, comment)\ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
84 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
|
85 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
86 #define ALLOC(size, comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
87 #define RELEASE(size, comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
88 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
89 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
90 /* compiler tweaks */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
91 #if defined(_MSC_VER) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
92 #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
|
93 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
94 #define LOCAL(type) static type |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
95 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
96 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
97 /* compatibility macros */ |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
98 #if (PY_VERSION_HEX < 0x02060000) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
99 #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
100 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
101 #endif |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
102 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
103 #if (PY_VERSION_HEX < 0x02050000) |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
104 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
|
105 #define lenfunc inquiry |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
106 #endif |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
107 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
108 #if (PY_VERSION_HEX < 0x02040000) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
109 #define PyDict_CheckExact PyDict_Check |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
110 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
111 #if !defined(Py_RETURN_NONE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
112 #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
|
113 #endif |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
114 #endif |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
115 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
116 /* 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
|
117 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
|
118 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
|
119 info. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
120 #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
|
121 #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
|
122 #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
|
123 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
124 /* glue functions (see the init function for details) */ |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
125 static PyObject* elementtree_parseerror_obj; |
|
36050
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; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
128 static PyObject* elementtree_iter_obj; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
129 static PyObject* elementtree_itertext_obj; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
130 static PyObject* elementpath_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
131 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
132 /* helpers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
133 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
134 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
135 deepcopy(PyObject* object, PyObject* memo) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
136 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
137 /* 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
|
138 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
139 PyObject* args; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
140 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
141 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
142 if (!elementtree_deepcopy_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
143 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
144 PyExc_RuntimeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
145 "deepcopy helper not found" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
146 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
147 return NULL; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
150 args = PyTuple_New(2); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
151 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
152 return NULL; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
153 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
154 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
|
155 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
|
156 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
157 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
|
158 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
159 Py_DECREF(args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
160 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
161 return result; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
164 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
165 list_join(PyObject* list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
166 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
167 /* 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
|
168 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
169 PyObject* joiner; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
170 PyObject* function; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
171 PyObject* args; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
172 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
173 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
174 switch (PyList_GET_SIZE(list)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
175 case 0: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
176 Py_DECREF(list); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
177 return PyString_FromString(""); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
178 case 1: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
179 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
|
180 Py_INCREF(result); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
181 Py_DECREF(list); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
182 return result; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
185 /* 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
|
186 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
|
187 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
188 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
|
189 if (!joiner) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
190 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
191 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
192 function = PyObject_GetAttrString(joiner, "join"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
193 if (!function) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
194 Py_DECREF(joiner); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
195 return NULL; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
198 args = PyTuple_New(1); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
199 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
200 return NULL; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
201 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
202 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
|
203 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
204 result = PyObject_CallObject(function, args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
205 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
206 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
|
207 Py_DECREF(function); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
208 Py_DECREF(joiner); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
209 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
210 return result; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
213 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
214 /* the element type */ |
|
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 typedef struct { |
|
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 /* 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
|
219 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
220 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
221 /* child elements */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
222 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
|
223 int allocated; /* allocated items */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
224 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
225 /* 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
|
226 PyObject* *children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
227 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
228 PyObject* _children[STATIC_CHILDREN]; |
|
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 } ElementObjectExtra; |
|
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 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
234 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
235 /* element tag (a string). */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
236 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
237 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
238 /* 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 should be left intact. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
244 PyObject* text; |
|
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 /* 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
|
247 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
|
248 PyObject* tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
249 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
250 ElementObjectExtra* extra; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
251 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
252 } ElementObject; |
|
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 staticforward PyTypeObject Element_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
255 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
256 #define Element_CheckExact(op) (Py_TYPE(op) == &Element_Type) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
257 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
258 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
259 /* element constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
260 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
261 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
262 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
|
263 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
264 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
|
265 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
266 return -1; |
|
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 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
269 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
270 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
271 Py_INCREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
272 self->extra->attrib = attrib; |
|
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 self->extra->length = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
275 self->extra->allocated = STATIC_CHILDREN; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
276 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
|
277 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
278 return 0; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
281 LOCAL(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
282 element_dealloc_extra(ElementObject* self) |
|
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 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
285 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
286 Py_DECREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
287 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
288 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
|
289 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
|
290 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
291 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
|
292 PyObject_Free(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 PyObject_Free(self->extra); |
|
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(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
298 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
|
299 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
300 ElementObject* self; |
|
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 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
|
303 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
304 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
305 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
306 /* use None for empty dictionaries */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
307 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
|
308 attrib = Py_None; |
|
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 self->extra = NULL; |
|
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 if (attrib != Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
313 |
|
38139
f1e24452dbba
Fix problems found by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
314 if (element_new_extra(self, attrib) < 0) { |
|
f1e24452dbba
Fix problems found by Coverity.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
315 PyObject_Del(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
316 return NULL; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
317 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
318 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
319 self->extra->length = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
320 self->extra->allocated = STATIC_CHILDREN; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
321 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
|
322 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
323 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
324 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
325 Py_INCREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
326 self->tag = tag; |
|
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 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
329 self->text = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
330 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
331 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
332 self->tail = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
333 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
334 ALLOC(sizeof(ElementObject), "create element"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
335 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
336 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
337 } |
|
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 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
340 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
|
341 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
342 int size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
343 PyObject* *children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
344 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
345 /* 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
|
346 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
|
347 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
348 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
349 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
350 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
351 size = self->extra->length + extra; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
352 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
353 if (size > self->extra->allocated) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
354 /* 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
|
355 size = (size >> 3) + (size < 9 ? 3 : 6) + size; |
|
44738
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
356 /* Coverity CID #182 size_error: Allocating 1 bytes to pointer "children" |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
357 * which needs at least 4 bytes. |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
358 * Although it's a false alarm always assume at least one child to |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
359 * be safe. |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
360 */ |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
361 size = size ? size : 1; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
362 if (self->extra->children != self->extra->_children) { |
|
44738
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
363 /* Coverity CID #182 size_error: Allocating 1 bytes to pointer |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
364 * "children", which needs at least 4 bytes. Although it's a |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
365 * false alarm always assume at least one child to be safe. |
|
b4003b6c6d13
Coverity issue CID #182
Christian Heimes <christian@cheimes.de>
parents:
44350
diff
changeset
|
366 */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
367 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
|
368 size * sizeof(PyObject*)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
369 if (!children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
370 goto nomemory; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
371 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
372 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
|
373 if (!children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
374 goto nomemory; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
375 /* 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
|
376 memcpy(children, self->extra->children, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
377 self->extra->length * sizeof(PyObject*)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
378 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
379 self->extra->children = children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
380 self->extra->allocated = size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
381 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
382 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
383 return 0; |
|
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 nomemory: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
386 PyErr_NoMemory(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
387 return -1; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
390 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
391 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
|
392 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
393 /* 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
|
394 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
395 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
|
396 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
397 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
398 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
399 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
|
400 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
401 self->extra->length++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
402 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
403 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
404 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
405 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
406 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
407 element_get_attrib(ElementObject* self) |
|
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 borrowed reference to attrib dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
410 /* 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
|
411 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
412 PyObject* res = self->extra->attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
413 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
414 if (res == Py_None) { |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
415 Py_DECREF(res); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
416 /* create missing dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
417 res = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
418 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
419 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
420 self->extra->attrib = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
421 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
422 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
423 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
424 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
425 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
426 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
427 element_get_text(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
428 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
429 /* 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
|
430 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
431 PyObject* res = self->text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
432 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
433 if (JOIN_GET(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
434 res = JOIN_OBJ(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
435 if (PyList_CheckExact(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
436 res = list_join(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
437 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
438 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
439 self->text = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
440 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
441 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
442 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
443 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
444 } |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
447 element_get_tail(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
448 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
449 /* 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
|
450 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
451 PyObject* res = self->tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
452 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
453 if (JOIN_GET(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
454 res = JOIN_OBJ(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
455 if (PyList_CheckExact(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
456 res = list_join(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
457 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
458 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
459 self->tail = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
460 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
461 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
462 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
463 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
464 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
467 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
|
468 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
469 PyObject* elem; |
|
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 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
472 PyObject* attrib = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
473 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
|
474 &PyDict_Type, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
475 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
476 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
477 if (attrib || kw) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
478 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
|
479 if (!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 if (kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
482 PyDict_Update(attrib, kw); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
483 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
484 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
485 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
486 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
487 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
488 elem = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
489 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
490 Py_DECREF(attrib); |
|
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 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
493 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
496 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
|
497 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
498 PyObject* elem; |
|
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 ElementObject* parent; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
501 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
502 PyObject* attrib = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
503 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
|
504 &Element_Type, &parent, &tag, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
505 &PyDict_Type, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
506 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
507 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
508 if (attrib || kw) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
509 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
|
510 if (!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 if (kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
513 PyDict_Update(attrib, kw); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
514 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
515 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
516 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
517 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
518 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
519 elem = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
520 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
521 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
522 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
523 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
|
524 Py_DECREF(elem); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
525 return NULL; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
526 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
527 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
528 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
529 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
530 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
531 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
532 element_dealloc(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
533 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
534 if (self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
535 element_dealloc_extra(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
536 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
537 /* discard attributes */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
538 Py_DECREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
539 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
|
540 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
|
541 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
542 RELEASE(sizeof(ElementObject), "destroy element"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
543 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
544 PyObject_Del(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
545 } |
|
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 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
548 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
549 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
550 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
551 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
|
552 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
553 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
554 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
|
555 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
556 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
557 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
|
558 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
559 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
560 Py_RETURN_NONE; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
563 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
564 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
|
565 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
566 if (!PyArg_ParseTuple(args, ":clear")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
567 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
568 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
569 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
570 element_dealloc_extra(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
571 self->extra = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
572 } |
|
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 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
575 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
|
576 self->text = Py_None; |
|
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 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
579 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
|
580 self->tail = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
581 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
582 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
583 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
584 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
585 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
586 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
|
587 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
588 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
589 ElementObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
590 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
591 if (!PyArg_ParseTuple(args, ":__copy__")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
592 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
593 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
594 element = (ElementObject*) element_new( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
595 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
|
596 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
597 if (!element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
598 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
599 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
600 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
|
601 element->text = self->text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
602 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
|
603 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
604 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
|
605 element->tail = self->tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
606 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
|
607 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
608 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
609 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
610 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
|
611 Py_DECREF(element); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
612 return NULL; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
613 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
614 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
615 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
|
616 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
|
617 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
|
618 } |
|
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 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
|
621 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
622 } |
|
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 return (PyObject*) element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
625 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
628 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
|
629 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
630 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
631 ElementObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
632 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
633 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
634 PyObject* text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
635 PyObject* tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
636 PyObject* id; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
637 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
638 PyObject* memo; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
639 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
|
640 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
641 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
642 tag = deepcopy(self->tag, memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
643 if (!tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
644 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
645 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
646 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
647 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
|
648 if (!attrib) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
649 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
650 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
651 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
652 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
653 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
654 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
655 } |
|
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 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
|
658 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
659 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
660 Py_DECREF(attrib); |
|
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 if (!element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
663 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
664 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
665 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
|
666 if (!text) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
667 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
668 Py_DECREF(element->text); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
669 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
|
670 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
671 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
|
672 if (!tail) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
673 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
674 Py_DECREF(element->tail); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
675 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
|
676 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
677 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
678 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
679 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
|
680 goto error; |
|
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 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
|
683 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
|
684 if (!child) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
685 element->extra->length = i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
686 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
687 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
688 element->extra->children[i] = child; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
689 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
690 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
691 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
|
692 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
693 } |
|
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 /* 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
|
696 id = PyInt_FromLong((Py_uintptr_t) self); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
697 if (!id) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
698 goto error; |
|
36050
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 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
|
701 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
702 Py_DECREF(id); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
703 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
704 if (i < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
705 goto error; |
|
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 return (PyObject*) element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
708 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
709 error: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
710 Py_DECREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
711 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
712 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
713 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
714 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
715 checkpath(PyObject* tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
716 { |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
717 Py_ssize_t i; |
|
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
718 int check = 1; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
719 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
720 /* 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
|
721 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
722 #define PATHCHAR(ch) \ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
723 (ch == '/' || ch == '*' || ch == '[' || ch == '@' || ch == '.') |
|
36050
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 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
726 if (PyUnicode_Check(tag)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
727 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
|
728 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
|
729 if (p[i] == '{') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
730 check = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
731 else if (p[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
732 check = 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
733 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
|
734 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
735 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
736 return 0; |
|
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 #endif |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
739 if (PyString_Check(tag)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
740 char *p = PyString_AS_STRING(tag); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
741 for (i = 0; i < PyString_GET_SIZE(tag); i++) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
742 if (p[i] == '{') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
743 check = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
744 else if (p[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
745 check = 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
746 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
|
747 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
748 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
749 return 0; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
752 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
|
753 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
754 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
755 static PyObject* |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
756 element_extend(ElementObject* self, PyObject* args) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
757 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
758 PyObject* seq; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
759 Py_ssize_t i, seqlen = 0; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
760 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
761 PyObject* seq_in; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
762 if (!PyArg_ParseTuple(args, "O:extend", &seq_in)) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
763 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
764 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
765 seq = PySequence_Fast(seq_in, ""); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
766 if (!seq) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
767 PyErr_Format( |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
768 PyExc_TypeError, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
769 "expected sequence, not \"%.200s\"", Py_TYPE(seq_in)->tp_name |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
770 ); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
771 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
772 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
773 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
774 seqlen = PySequence_Size(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
775 for (i = 0; i < seqlen; i++) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
776 PyObject* element = PySequence_Fast_GET_ITEM(seq, i); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
777 if (element_add_subelement(self, element) < 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
778 Py_DECREF(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
779 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
780 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
781 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
782 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
783 Py_DECREF(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
784 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
785 Py_RETURN_NONE; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
786 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
787 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
788 static PyObject* |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
789 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
|
790 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
791 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
792 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
793 PyObject* tag; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
794 PyObject* namespaces = Py_None; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
795 if (!PyArg_ParseTuple(args, "O|O:find", &tag, &namespaces)) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
796 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
797 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
798 if (checkpath(tag) || namespaces != Py_None) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
799 return PyObject_CallMethod( |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
800 elementpath_obj, "find", "OOO", self, tag, namespaces |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
801 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
802 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
803 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
804 Py_RETURN_NONE; |
|
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 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
|
808 if (Element_CheckExact(item) && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
809 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
|
810 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
811 return item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
812 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
813 } |
|
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 Py_RETURN_NONE; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
818 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
819 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
|
820 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
821 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
822 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
823 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
824 PyObject* default_value = Py_None; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
825 PyObject* namespaces = Py_None; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
826 if (!PyArg_ParseTuple(args, "O|OO:findtext", &tag, &default_value, &namespaces)) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
827 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
828 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
829 if (checkpath(tag) || namespaces != Py_None) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
830 return PyObject_CallMethod( |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
831 elementpath_obj, "findtext", "OOOO", self, tag, default_value, namespaces |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
832 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
833 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
834 if (!self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
835 Py_INCREF(default_value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
836 return default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
837 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
838 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
839 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
|
840 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
|
841 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
|
842 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
|
843 if (text == Py_None) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
844 return PyString_FromString(""); |
|
39445
e11caad7e029
Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38885
diff
changeset
|
845 Py_XINCREF(text); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
846 return text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
847 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
848 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
849 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
850 Py_INCREF(default_value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
851 return default_value; |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
855 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
|
856 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
857 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
858 PyObject* out; |
|
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* tag; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
861 PyObject* namespaces = Py_None; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
862 if (!PyArg_ParseTuple(args, "O|O:findall", &tag, &namespaces)) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
863 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
864 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
865 if (checkpath(tag) || namespaces != Py_None) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
866 return PyObject_CallMethod( |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
867 elementpath_obj, "findall", "OOO", self, tag, namespaces |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
868 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
869 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
870 out = PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
871 if (!out) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
872 return NULL; |
|
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 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
875 return out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
876 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
877 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
|
878 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
|
879 if (Element_CheckExact(item) && |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
880 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
|
881 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
|
882 Py_DECREF(out); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
883 return NULL; |
|
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 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
886 } |
|
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 return out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
889 } |
|
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 static PyObject* |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
892 element_iterfind(ElementObject* self, PyObject* args) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
893 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
894 PyObject* tag; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
895 PyObject* namespaces = Py_None; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
896 if (!PyArg_ParseTuple(args, "O|O:iterfind", &tag, &namespaces)) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
897 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
898 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
899 return PyObject_CallMethod( |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
900 elementpath_obj, "iterfind", "OOO", self, tag, namespaces |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
901 ); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
902 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
903 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
904 static PyObject* |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
905 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
|
906 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
907 PyObject* value; |
|
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* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
910 PyObject* default_value = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
911 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
|
912 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
913 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
914 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
|
915 value = default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
916 else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
917 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
|
918 if (!value) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
919 value = default_value; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
922 Py_INCREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
923 return value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
924 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
925 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
926 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
927 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
|
928 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
929 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
930 PyObject* list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
931 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
932 /* FIXME: report as deprecated? */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
933 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
934 if (!PyArg_ParseTuple(args, ":getchildren")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
935 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
936 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
937 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
938 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
939 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
940 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
|
941 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
942 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
943 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
944 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
|
945 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
|
946 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
947 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
|
948 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
949 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
950 return list; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
953 static PyObject* |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
954 element_iter(ElementObject* self, PyObject* args) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
955 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
956 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
957 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
958 PyObject* tag = Py_None; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
959 if (!PyArg_ParseTuple(args, "|O:iter", &tag)) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
960 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
961 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
962 if (!elementtree_iter_obj) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
963 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
964 PyExc_RuntimeError, |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
965 "iter helper not found" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
966 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
967 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
968 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
969 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
970 args = PyTuple_New(2); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
971 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
972 return NULL; |
|
36450
c193283e63bc
Check return results for errors
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
973 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
974 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
|
975 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
|
976 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
977 result = PyObject_CallObject(elementtree_iter_obj, args); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
978 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
979 Py_DECREF(args); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
980 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
981 return result; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
982 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
983 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
984 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
985 static PyObject* |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
986 element_itertext(ElementObject* self, PyObject* args) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
987 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
988 PyObject* result; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
989 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
990 if (!PyArg_ParseTuple(args, ":itertext")) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
991 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
992 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
993 if (!elementtree_itertext_obj) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
994 PyErr_SetString( |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
995 PyExc_RuntimeError, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
996 "itertext helper not found" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
997 ); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
998 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
999 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1000 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1001 args = PyTuple_New(1); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1002 if (!args) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1003 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1004 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1005 Py_INCREF(self); PyTuple_SET_ITEM(args, 0, (PyObject*) self); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1006 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1007 result = PyObject_CallObject(elementtree_itertext_obj, args); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1008 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1009 Py_DECREF(args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1010 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1011 return result; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1014 static PyObject* |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1015 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
|
1016 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1017 ElementObject* self = (ElementObject*) self_; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1018 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1019 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
|
1020 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1021 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1022 "child index out of range" |
|
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 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1025 } |
|
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 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
|
1028 return self->extra->children[index]; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1031 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1032 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
|
1033 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1034 int i; |
|
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 int index; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1037 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1038 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
|
1039 &Element_Type, &element)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1040 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1041 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1042 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1043 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1044 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1045 if (index < 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1046 index += self->extra->length; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1047 if (index < 0) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1048 index = 0; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1049 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1050 if (index > self->extra->length) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1051 index = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1052 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1053 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
|
1054 return NULL; |
|
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 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
|
1057 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
|
1058 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1059 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1060 self->extra->children[index] = element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1061 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1062 self->extra->length++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1063 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1064 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1065 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1068 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
|
1069 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1070 if (!PyArg_ParseTuple(args, ":items")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1071 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1072 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1073 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
|
1074 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1075 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1076 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
|
1077 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1078 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1079 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1080 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
|
1081 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1082 if (!PyArg_ParseTuple(args, ":keys")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1083 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1084 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1085 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
|
1086 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1087 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1088 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
|
1089 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1090 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1091 static Py_ssize_t |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1092 element_length(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1093 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1094 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1095 return 0; |
|
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 return self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1098 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1101 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
|
1102 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1103 PyObject* elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1104 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1105 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1106 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1107 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
|
1108 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1109 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1110 attrib = PyDict_Copy(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1111 if (!attrib) |
|
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 elem = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1115 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1116 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1117 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1118 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1119 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1122 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
|
1123 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1124 if (!PyArg_ParseTuple(args, ":__reduce__")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1125 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1126 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1127 /* 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
|
1128 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
|
1129 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
|
1130 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
|
1131 right thing. */ |
|
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 if (!elementtree_copyelement_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1134 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1135 PyExc_RuntimeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1136 "copyelement helper not found" |
|
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 return NULL; |
|
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 return Py_BuildValue( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1142 "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
|
1143 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1144 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1145 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1146 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1147 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
|
1148 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1149 int i; |
|
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 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1152 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
|
1153 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1154 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1155 if (!self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1156 /* 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
|
1157 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1158 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1159 "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
|
1160 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1161 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1162 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1163 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1164 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
|
1165 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
|
1166 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1167 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
|
1168 break; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1171 if (i == self->extra->length) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1172 /* 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
|
1173 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1174 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1175 "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
|
1176 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1177 return NULL; |
|
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 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
|
1181 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1182 self->extra->length--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1183 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1184 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
|
1185 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
|
1186 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1187 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1188 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1191 element_repr(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1192 { |
|
59512
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1193 PyObject *repr, *tag; |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1194 |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1195 tag = PyObject_Repr(self->tag); |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1196 if (!tag) |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1197 return NULL; |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1198 |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1199 repr = PyString_FromFormat("<Element %s at %p>", |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1200 PyString_AS_STRING(tag), self); |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1201 |
|
903d3e633a92
Fix repr of tree Element on windows.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59511
diff
changeset
|
1202 Py_DECREF(tag); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1203 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1204 return repr; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1205 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1206 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1207 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1208 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
|
1209 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1210 PyObject* attrib; |
|
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 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1213 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1214 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
|
1215 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1216 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1217 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1218 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1219 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1220 attrib = element_get_attrib(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1221 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1222 return NULL; |
|
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 (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
|
1225 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1226 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1227 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1228 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1229 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1230 static int |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1231 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
|
1232 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1233 ElementObject* self = (ElementObject*) self_; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1234 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1235 PyObject* old; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1236 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1237 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
|
1238 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1239 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1240 "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
|
1241 return -1; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1244 old = self->extra->children[index]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1245 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1246 if (item) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1247 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1248 self->extra->children[index] = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1249 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1250 self->extra->length--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1251 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
|
1252 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
|
1253 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1254 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1255 Py_DECREF(old); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1256 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1257 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1258 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1259 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1260 static PyObject* |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1261 element_subscr(PyObject* self_, PyObject* item) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1262 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1263 ElementObject* self = (ElementObject*) self_; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1264 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1265 #if (PY_VERSION_HEX < 0x02050000) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1266 if (PyInt_Check(item) || PyLong_Check(item)) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1267 long i = PyInt_AsLong(item); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1268 #else |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1269 if (PyIndex_Check(item)) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1270 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1271 #endif |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1272 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1273 if (i == -1 && PyErr_Occurred()) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1274 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1275 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1276 if (i < 0 && self->extra) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1277 i += self->extra->length; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1278 return element_getitem(self_, i); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1279 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1280 else if (PySlice_Check(item)) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1281 Py_ssize_t start, stop, step, slicelen, cur, i; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1282 PyObject* list; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1283 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1284 if (!self->extra) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1285 return PyList_New(0); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1286 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1287 if (PySlice_GetIndicesEx((PySliceObject *)item, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1288 self->extra->length, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1289 &start, &stop, &step, &slicelen) < 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1290 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1291 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1292 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1293 if (slicelen <= 0) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1294 return PyList_New(0); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1295 else { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1296 list = PyList_New(slicelen); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1297 if (!list) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1298 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1299 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1300 for (cur = start, i = 0; i < slicelen; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1301 cur += step, i++) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1302 PyObject* item = self->extra->children[cur]; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1303 Py_INCREF(item); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1304 PyList_SET_ITEM(list, i, item); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1305 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1306 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1307 return list; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1308 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1309 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1310 else { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1311 PyErr_SetString(PyExc_TypeError, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1312 "element indices must be integers"); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1313 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1314 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1315 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1316 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1317 static int |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1318 element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1319 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1320 ElementObject* self = (ElementObject*) self_; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1321 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1322 #if (PY_VERSION_HEX < 0x02050000) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1323 if (PyInt_Check(item) || PyLong_Check(item)) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1324 long i = PyInt_AsLong(item); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1325 #else |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1326 if (PyIndex_Check(item)) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1327 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1328 #endif |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1329 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1330 if (i == -1 && PyErr_Occurred()) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1331 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1332 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1333 if (i < 0 && self->extra) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1334 i += self->extra->length; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1335 return element_setitem(self_, i, value); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1336 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1337 else if (PySlice_Check(item)) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1338 Py_ssize_t start, stop, step, slicelen, newlen, cur, i; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1339 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1340 PyObject* recycle = NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1341 PyObject* seq = NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1342 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1343 if (!self->extra) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1344 element_new_extra(self, NULL); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1345 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1346 if (PySlice_GetIndicesEx((PySliceObject *)item, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1347 self->extra->length, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1348 &start, &stop, &step, &slicelen) < 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1349 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1350 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1351 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1352 if (value == NULL) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1353 newlen = 0; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1354 else { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1355 seq = PySequence_Fast(value, ""); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1356 if (!seq) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1357 PyErr_Format( |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1358 PyExc_TypeError, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1359 "expected sequence, not \"%.200s\"", Py_TYPE(value)->tp_name |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1360 ); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1361 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1362 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1363 newlen = PySequence_Size(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1364 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1365 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1366 if (step != 1 && newlen != slicelen) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1367 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1368 PyErr_Format(PyExc_ValueError, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1369 #if (PY_VERSION_HEX < 0x02050000) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1370 "attempt to assign sequence of size %d " |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1371 "to extended slice of size %d", |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1372 #else |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1373 "attempt to assign sequence of size %zd " |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1374 "to extended slice of size %zd", |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1375 #endif |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1376 newlen, slicelen |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1377 ); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1378 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1379 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1380 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1381 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1382 /* Resize before creating the recycle bin, to prevent refleaks. */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1383 if (newlen > slicelen) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1384 if (element_resize(self, newlen - slicelen) < 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1385 if (seq) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1386 Py_DECREF(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1387 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1388 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1389 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1390 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1391 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1392 if (slicelen > 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1393 /* to avoid recursive calls to this method (via decref), move |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1394 old items to the recycle bin here, and get rid of them when |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1395 we're done modifying the element */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1396 recycle = PyList_New(slicelen); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1397 if (!recycle) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1398 if (seq) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1399 Py_DECREF(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1400 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1401 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1402 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1403 for (cur = start, i = 0; i < slicelen; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1404 cur += step, i++) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1405 PyList_SET_ITEM(recycle, i, self->extra->children[cur]); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1406 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1407 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1408 if (newlen < slicelen) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1409 /* delete slice */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1410 for (i = stop; i < self->extra->length; i++) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1411 self->extra->children[i + newlen - slicelen] = self->extra->children[i]; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1412 } else if (newlen > slicelen) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1413 /* insert slice */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1414 for (i = self->extra->length-1; i >= stop; i--) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1415 self->extra->children[i + newlen - slicelen] = self->extra->children[i]; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1416 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1417 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1418 /* replace the slice */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1419 for (cur = start, i = 0; i < newlen; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1420 cur += step, i++) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1421 PyObject* element = PySequence_Fast_GET_ITEM(seq, i); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1422 Py_INCREF(element); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1423 self->extra->children[cur] = element; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1424 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1425 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1426 self->extra->length += newlen - slicelen; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1427 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1428 if (seq) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1429 Py_DECREF(seq); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1430 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1431 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1432 /* discard the recycle bin, and everything in it */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1433 Py_XDECREF(recycle); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1434 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1435 return 0; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1436 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1437 else { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1438 PyErr_SetString(PyExc_TypeError, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1439 "element indices must be integers"); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1440 return -1; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1441 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1442 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1443 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1444 static PyMethodDef element_methods[] = { |
|
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 {"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
|
1447 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1448 {"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
|
1449 {"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
|
1450 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1451 {"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
|
1452 {"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
|
1453 {"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
|
1454 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1455 {"append", (PyCFunction) element_append, METH_VARARGS}, |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1456 {"extend", (PyCFunction) element_extend, METH_VARARGS}, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1457 {"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
|
1458 {"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
|
1459 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1460 {"iter", (PyCFunction) element_iter, METH_VARARGS}, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1461 {"itertext", (PyCFunction) element_itertext, METH_VARARGS}, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1462 {"iterfind", (PyCFunction) element_iterfind, METH_VARARGS}, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1463 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1464 {"getiterator", (PyCFunction) element_iter, METH_VARARGS}, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1465 {"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
|
1466 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1467 {"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
|
1468 {"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
|
1469 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1470 {"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
|
1471 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1472 {"__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
|
1473 {"__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
|
1474 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1475 /* 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
|
1476 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
|
1477 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
|
1478 details). */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1479 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1480 /* 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
|
1481 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
|
1482 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
|
1483 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
|
1484 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1485 {"!__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
|
1486 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1487 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1488 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1489 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1490 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1491 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
|
1492 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1493 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1494 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1495 /* handle common attributes first */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1496 if (strcmp(name, "tag") == 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1497 res = self->tag; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1498 Py_INCREF(res); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1499 return res; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1500 } else if (strcmp(name, "text") == 0) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1501 res = element_get_text(self); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1502 Py_INCREF(res); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1503 return res; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1504 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1505 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1506 /* methods */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1507 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
|
1508 if (res) |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1509 return res; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1510 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1511 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1512 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1513 /* less common attributes */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1514 if (strcmp(name, "tail") == 0) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1515 res = element_get_tail(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1516 } 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
|
1517 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1518 element_new_extra(self, NULL); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1519 res = element_get_attrib(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1520 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1521 PyErr_SetString(PyExc_AttributeError, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1522 return NULL; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1525 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1526 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1527 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1528 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1529 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1530 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1531 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1532 static int |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1533 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
|
1534 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1535 if (value == NULL) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1536 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1537 PyExc_AttributeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1538 "can't delete element attributes" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1539 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1540 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1541 } |
|
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 if (strcmp(name, "tag") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1544 Py_DECREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1545 self->tag = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1546 Py_INCREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1547 } 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
|
1548 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
|
1549 self->text = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1550 Py_INCREF(self->text); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1551 } 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
|
1552 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
|
1553 self->tail = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1554 Py_INCREF(self->tail); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1555 } 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
|
1556 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1557 element_new_extra(self, NULL); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1558 Py_DECREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1559 self->extra->attrib = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1560 Py_INCREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1561 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1562 PyErr_SetString(PyExc_AttributeError, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1563 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1564 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1565 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1566 return 0; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1569 static PySequenceMethods element_as_sequence = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1570 (lenfunc) element_length, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1571 0, /* sq_concat */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1572 0, /* sq_repeat */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1573 element_getitem, |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1574 0, |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1575 element_setitem, |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1576 0, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1577 }; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1578 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1579 static PyMappingMethods element_as_mapping = { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1580 (lenfunc) element_length, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1581 (binaryfunc) element_subscr, |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1582 (objobjargproc) element_ass_subscr, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1583 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1584 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1585 statichere PyTypeObject Element_Type = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1586 PyObject_HEAD_INIT(NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1587 0, "Element", sizeof(ElementObject), 0, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1588 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1589 (destructor)element_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1590 0, /* tp_print */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1591 (getattrfunc)element_getattr, /* tp_getattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1592 (setattrfunc)element_setattr, /* tp_setattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1593 0, /* tp_compare */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1594 (reprfunc)element_repr, /* tp_repr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1595 0, /* tp_as_number */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1596 &element_as_sequence, /* tp_as_sequence */ |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1597 &element_as_mapping, /* tp_as_mapping */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1598 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1599 |
|
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 /* the tree builder type */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1602 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1603 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1604 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1605 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1606 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
|
1607 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1608 ElementObject* this; /* current node */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1609 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
|
1610 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1611 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
|
1612 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1613 PyObject* stack; /* element stack */ |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
1614 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
|
1615 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1616 /* element tracing */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1617 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
|
1618 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
|
1619 PyObject* end_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1620 PyObject* start_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1621 PyObject* end_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1622 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1623 } TreeBuilderObject; |
|
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 staticforward PyTypeObject TreeBuilder_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1626 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
1627 #define TreeBuilder_CheckExact(op) (Py_TYPE(op) == &TreeBuilder_Type) |
|
36050
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 /* constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1631 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1632 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1633 treebuilder_new(void) |
|
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 TreeBuilderObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1636 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1637 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
|
1638 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1639 return NULL; |
|
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 self->root = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1642 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1643 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1644 self->this = (ElementObject*) Py_None; |
|
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 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1647 self->last = (ElementObject*) Py_None; |
|
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 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1650 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1651 self->stack = PyList_New(20); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1652 self->index = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1653 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1654 self->events = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1655 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
|
1656 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
|
1657 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1658 ALLOC(sizeof(TreeBuilderObject), "create treebuilder"); |
|
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 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1661 } |
|
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 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
|
1664 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
|
1665 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1666 if (!PyArg_ParseTuple(args, ":TreeBuilder")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1667 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1668 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1669 return treebuilder_new(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1670 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1671 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1672 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1673 treebuilder_dealloc(TreeBuilderObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1674 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1675 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
|
1676 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
|
1677 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
|
1678 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
|
1679 Py_XDECREF(self->events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1680 Py_DECREF(self->stack); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1681 Py_XDECREF(self->data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1682 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1683 Py_DECREF(self->this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1684 Py_XDECREF(self->root); |
|
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 RELEASE(sizeof(TreeBuilderObject), "destroy treebuilder"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1687 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1688 PyObject_Del(self); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1691 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1692 /* handlers */ |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1695 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
|
1696 PyObject* standalone) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1697 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1698 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1699 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1700 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1701 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1702 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
|
1703 PyObject* attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1704 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1705 PyObject* node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1706 PyObject* this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1707 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1708 if (self->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1709 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
|
1710 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
|
1711 self->last->text = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1712 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
|
1713 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1714 } else { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1715 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
|
1716 self->last->tail = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1717 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
|
1718 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1719 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1720 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1721 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1722 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1723 node = element_new(tag, attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1724 if (!node) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1725 return NULL; |
|
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 this = (PyObject*) self->this; |
|
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 if (this != Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1730 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
|
1731 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1732 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1733 if (self->root) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1734 PyErr_SetString( |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1735 elementtree_parseerror_obj, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1736 "multiple elements on top level" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1737 ); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1738 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1739 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1740 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1741 self->root = node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1742 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1743 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1744 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
|
1745 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
|
1746 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1747 Py_INCREF(this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1748 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1749 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
|
1750 goto error; |
|
36050
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 self->index++; |
|
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 Py_DECREF(this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1755 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1756 self->this = (ElementObject*) node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1757 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1758 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1759 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1760 self->last = (ElementObject*) node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1761 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1762 if (self->start_event_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1763 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1764 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
|
1765 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1766 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1767 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
|
1768 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
|
1769 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1770 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1771 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1772 PyErr_Clear(); /* FIXME: propagate error */ |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1775 return node; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1776 |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1777 error: |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1778 Py_DECREF(node); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1779 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1780 } |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1783 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
|
1784 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1785 if (!self->data) { |
| 39528 | 1786 if (self->last == (ElementObject*) Py_None) { |
| 1787 /* ignore calls to data before the first call to start */ | |
| 1788 Py_RETURN_NONE; | |
| 1789 } | |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1790 /* 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
|
1791 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
|
1792 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1793 /* more than one item; use a list to collect items */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1794 if (PyString_CheckExact(self->data) && Py_REFCNT(self->data) == 1 && |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1795 PyString_CheckExact(data) && PyString_GET_SIZE(data) == 1) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1796 /* 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
|
1797 the most common case by resizing the existing string... */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1798 Py_ssize_t size = PyString_GET_SIZE(self->data); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1799 if (_PyString_Resize(&self->data, size + 1) < 0) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1800 return NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1801 PyString_AS_STRING(self->data)[size] = PyString_AS_STRING(data)[0]; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1802 } 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
|
1803 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
|
1804 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1805 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1806 PyObject* list = PyList_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1807 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1808 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1809 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
|
1810 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
|
1811 self->data = list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1812 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1813 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1814 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1815 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1816 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1817 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1818 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1819 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
|
1820 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1821 PyObject* item; |
|
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 (self->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1824 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
|
1825 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
|
1826 self->last->text = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1827 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
|
1828 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1829 } else { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1830 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
|
1831 self->last->tail = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1832 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
|
1833 ); |
|
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 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1836 } |
|
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 if (self->index == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1839 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1840 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1841 "pop from empty stack" |
|
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 return NULL; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1846 self->index--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1847 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1848 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
|
1849 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1850 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1851 Py_DECREF(self->last); |
|
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 self->last = (ElementObject*) self->this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1854 self->this = (ElementObject*) item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1855 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1856 if (self->end_event_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1857 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1858 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
|
1859 PyObject* node = (PyObject*) self->last; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1860 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1861 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1862 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
|
1863 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
|
1864 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1865 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1866 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1867 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1868 } |
|
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 Py_INCREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1871 return (PyObject*) self->last; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1872 } |
|
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(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1875 treebuilder_handle_namespace(TreeBuilderObject* self, int start, |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1876 PyObject *prefix, PyObject *uri) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1877 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1878 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1879 PyObject* action; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1880 PyObject* parcel; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1881 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1882 if (!self->events) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1883 return; |
|
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 if (start) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1886 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
|
1887 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1888 action = self->start_ns_event_obj; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
1889 parcel = Py_BuildValue("OO", prefix, uri); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1890 if (!parcel) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1891 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1892 Py_INCREF(action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1893 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1894 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
|
1895 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1896 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
|
1897 Py_INCREF(action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1898 parcel = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1899 Py_INCREF(parcel); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1900 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1901 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1902 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1903 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1904 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1905 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
|
1906 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
|
1907 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1908 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1909 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1910 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1911 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1912 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1913 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1914 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1915 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1916 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1917 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
|
1918 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1919 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1920 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
|
1921 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1922 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1923 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
|
1924 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1925 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1926 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1927 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
|
1928 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1929 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1930 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
|
1931 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1932 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1933 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
|
1934 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1935 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1936 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1937 treebuilder_done(TreeBuilderObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1938 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1939 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1940 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1941 /* FIXME: check stack size? */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1942 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1943 if (self->root) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1944 res = self->root; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1945 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1946 res = Py_None; |
|
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 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1949 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1950 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1951 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1952 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1953 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
|
1954 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1955 if (!PyArg_ParseTuple(args, ":close")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1956 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1957 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1958 return treebuilder_done(self); |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1962 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
|
1963 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1964 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1965 PyObject* attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1966 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
|
1967 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1968 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1969 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
|
1970 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1971 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1972 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1973 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
|
1974 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1975 PyObject* encoding; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1976 PyObject* standalone; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1977 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
|
1978 return NULL; |
|
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 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
|
1981 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1982 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1983 static PyMethodDef treebuilder_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1984 {"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
|
1985 {"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
|
1986 {"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
|
1987 {"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
|
1988 {"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
|
1989 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1990 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1991 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1992 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1993 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
|
1994 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1995 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
|
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 statichere PyTypeObject TreeBuilder_Type = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1999 PyObject_HEAD_INIT(NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2000 0, "TreeBuilder", sizeof(TreeBuilderObject), 0, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2001 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2002 (destructor)treebuilder_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2003 0, /* tp_print */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2004 (getattrfunc)treebuilder_getattr, /* tp_getattr */ |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2007 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2008 /* the expat interface */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2009 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2010 #if defined(USE_EXPAT) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2011 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2012 #include "expat.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2013 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2014 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2015 #include "pyexpat.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2016 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
|
2017 #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
|
2018 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2019 #define EXPAT(func) (XML_##func) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2020 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2021 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2022 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2023 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2024 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2025 XML_Parser parser; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2026 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2027 PyObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2028 PyObject* entity; |
|
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 PyObject* names; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2031 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2032 PyObject* handle_xml; |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2033 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2034 PyObject* handle_start; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2035 PyObject* handle_data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2036 PyObject* handle_end; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2037 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2038 PyObject* handle_comment; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2039 PyObject* handle_pi; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2040 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2041 PyObject* handle_close; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2042 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2043 } XMLParserObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2044 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2045 staticforward PyTypeObject XMLParser_Type; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2046 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2047 /* helpers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2048 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2049 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2050 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2051 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
|
2052 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2053 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2054 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2055 /* 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
|
2056 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
|
2057 if (string[i] & 0x80) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2058 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2059 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2060 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2061 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2062 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2063 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2064 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2065 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
|
2066 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2067 /* 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
|
2068 Unicode string */ |
|
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 defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2071 if (checkstring(string, size)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2072 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
|
2073 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2074 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2075 return PyString_FromStringAndSize(string, size); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2076 } |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2079 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
|
2080 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2081 /* 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
|
2082 to a universal name string */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2083 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2084 int size = strlen(string); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2085 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2086 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2087 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2088 /* look the 'raw' name up in the names dictionary */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2089 key = PyString_FromStringAndSize(string, size); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2090 if (!key) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2091 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2092 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2093 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
|
2094 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2095 if (value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2096 Py_INCREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2097 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2098 /* 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
|
2099 necessary */ |
|
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 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2102 char* p; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2103 int i; |
|
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 /* look for namespace separator */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2106 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
|
2107 if (string[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2108 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2109 if (i != size) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2110 /* convert to universal name */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2111 tag = PyString_FromStringAndSize(NULL, size+1); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2112 p = PyString_AS_STRING(tag); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2113 p[0] = '{'; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2114 memcpy(p+1, string, size); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2115 size++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2116 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2117 /* 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
|
2118 Py_INCREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2119 tag = key; |
|
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 /* decode universal name */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2123 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2124 /* 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
|
2125 it's not an utf-8 string */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2126 p = PyString_AS_STRING(tag); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2127 if (checkstring(p, size)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2128 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
|
2129 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2130 if (!value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2131 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2132 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2133 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2134 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2135 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2136 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
|
2137 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2138 /* add to names dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2139 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
|
2140 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2141 Py_DECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2142 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2143 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2144 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2145 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2146 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2147 return value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2148 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2149 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2150 static void |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2151 expat_set_error(const char* message, int line, int column) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2152 { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2153 PyObject *error; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2154 PyObject *position; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2155 char buffer[256]; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2156 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2157 sprintf(buffer, "%s: line %d, column %d", message, line, column); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2158 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2159 error = PyObject_CallFunction(elementtree_parseerror_obj, "s", buffer); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2160 if (!error) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2161 return; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2162 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2163 /* add position attribute */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2164 position = Py_BuildValue("(ii)", line, column); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2165 if (!position) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2166 Py_DECREF(error); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2167 return; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2168 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2169 if (PyObject_SetAttrString(error, "position", position) == -1) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2170 Py_DECREF(error); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2171 Py_DECREF(position); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2172 return; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2173 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2174 Py_DECREF(position); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2175 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2176 PyErr_SetObject(elementtree_parseerror_obj, error); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2177 Py_DECREF(error); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2178 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2179 |
|
36050
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 /* handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2182 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2183 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2184 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
|
2185 int data_len) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2186 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2187 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2188 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2189 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2190 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2191 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
|
2192 return; |
|
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 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
|
2195 if (!key) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2196 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2197 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2198 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
|
2199 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2200 if (value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2201 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2202 res = treebuilder_handle_data( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2203 (TreeBuilderObject*) self->target, value |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2204 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2205 else if (self->handle_data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2206 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
|
2207 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2208 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2209 Py_XDECREF(res); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2210 } else if (!PyErr_Occurred()) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2211 /* Report the first error, not the last */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2212 char message[128]; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2213 sprintf(message, "undefined entity &%.100s;", PyString_AS_STRING(key)); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2214 expat_set_error( |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2215 message, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2216 EXPAT(GetErrorLineNumber)(self->parser), |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2217 EXPAT(GetErrorColumnNumber)(self->parser) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2218 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2219 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2220 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2221 Py_DECREF(key); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2224 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2225 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
|
2226 const XML_Char **attrib_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2227 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2228 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2229 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2230 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2231 int ok; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2232 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2233 /* tag name */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2234 tag = makeuniversal(self, tag_in); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2235 if (!tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2236 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
|
2237 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2238 /* attributes */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2239 if (attrib_in[0]) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2240 attrib = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2241 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2242 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2243 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
|
2244 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
|
2245 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
|
2246 if (!key || !value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2247 Py_XDECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2248 Py_XDECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2249 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2250 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2251 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2252 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
|
2253 Py_DECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2254 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2255 if (ok < 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2256 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2257 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2258 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2259 attrib_in += 2; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2260 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2261 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2262 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2263 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2264 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2265 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2266 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2267 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2268 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
|
2269 tag, attrib); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2270 else if (self->handle_start) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2271 if (attrib == Py_None) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2272 Py_DECREF(attrib); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2273 attrib = PyDict_New(); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2274 if (!attrib) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2275 return; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2276 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2277 res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2278 } else |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2279 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2280 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2281 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2282 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2283 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2284 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2285 } |
|
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 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2288 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
|
2289 int data_len) |
|
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 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2292 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2293 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2294 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
|
2295 if (!data) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2296 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
|
2297 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2298 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2299 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2300 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
|
2301 else if (self->handle_data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2302 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
|
2303 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2304 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2305 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2306 Py_DECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2307 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2308 Py_XDECREF(res); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2311 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2312 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
|
2313 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2314 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2315 PyObject* res = NULL; |
|
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 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2318 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2319 /* 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
|
2320 res = treebuilder_handle_end( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2321 (TreeBuilderObject*) self->target, Py_None |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2322 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2323 else if (self->handle_end) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2324 tag = makeuniversal(self, tag_in); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2325 if (tag) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2326 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
|
2327 Py_DECREF(tag); |
|
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 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2330 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2331 Py_XDECREF(res); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2334 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2335 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
|
2336 const XML_Char *uri) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2337 { |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2338 PyObject* sprefix = NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2339 PyObject* suri = NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2340 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2341 suri = makestring(uri, strlen(uri)); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2342 if (!suri) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2343 return; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2344 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2345 if (prefix) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2346 sprefix = makestring(prefix, strlen(prefix)); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2347 else |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2348 sprefix = PyString_FromStringAndSize("", 0); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2349 if (!sprefix) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2350 Py_DECREF(suri); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2351 return; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2352 } |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2353 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2354 treebuilder_handle_namespace( |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2355 (TreeBuilderObject*) self->target, 1, sprefix, suri |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2356 ); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2357 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2358 Py_DECREF(sprefix); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2359 Py_DECREF(suri); |
|
36050
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2362 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2363 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
|
2364 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2365 treebuilder_handle_namespace( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2366 (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
|
2367 ); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2370 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2371 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
|
2372 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2373 PyObject* comment; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2374 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2375 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2376 if (self->handle_comment) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2377 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
|
2378 if (comment) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2379 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
|
2380 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2381 Py_DECREF(comment); |
|
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 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2384 } |
|
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 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2387 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
|
2388 const XML_Char* data_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2389 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2390 PyObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2391 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2392 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2393 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2394 if (self->handle_pi) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2395 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
|
2396 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
|
2397 if (target && data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2398 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
|
2399 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2400 Py_DECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2401 Py_DECREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2402 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2403 Py_XDECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2404 Py_XDECREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2405 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2406 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2407 } |
|
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 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2410 static int |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2411 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
|
2412 XML_Encoding *info) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2413 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2414 PyObject* u; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2415 Py_UNICODE* p; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2416 unsigned char s[256]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2417 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2418 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2419 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
|
2420 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2421 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
|
2422 s[i] = i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2423 |
| 36117 | 2424 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
|
2425 if (!u) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2426 return XML_STATUS_ERROR; |
|
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 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
|
2429 Py_DECREF(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2430 return XML_STATUS_ERROR; |
|
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 p = PyUnicode_AS_UNICODE(u); |
|
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 for (i = 0; i < 256; i++) { |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2436 if (p[i] != Py_UNICODE_REPLACEMENT_CHARACTER) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2437 info->map[i] = p[i]; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2438 else |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2439 info->map[i] = -1; |
|
36050
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 Py_DECREF(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2443 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2444 return XML_STATUS_OK; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2445 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2446 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2447 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2448 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2449 /* constructor and destructor */ |
|
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 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
|
2452 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
|
2453 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2454 XMLParserObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2455 /* 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
|
2456 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
|
2457 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2458 PyObject* target = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2459 char* encoding = NULL; |
| 36684 | 2460 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
|
2461 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
|
2462 &target, &encoding)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2463 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2464 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2465 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2466 if (!expat_capi) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2467 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2468 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
|
2469 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2470 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2471 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2472 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2473 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2474 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
|
2475 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2476 return NULL; |
|
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 self->entity = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2479 if (!self->entity) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2480 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2481 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2482 } |
|
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 self->names = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2485 if (!self->names) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2486 PyObject_Del(self->entity); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2487 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2488 return NULL; |
|
36050
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2491 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
|
2492 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
|
2493 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
|
2494 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2495 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
|
2496 if (!self->parser) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2497 PyObject_Del(self->names); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2498 PyObject_Del(self->entity); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2499 PyObject_Del(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2500 PyErr_NoMemory(); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2501 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2502 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2503 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2504 /* setup target handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2505 if (!target) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2506 target = treebuilder_new(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2507 if (!target) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2508 EXPAT(ParserFree)(self->parser); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2509 PyObject_Del(self->names); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2510 PyObject_Del(self->entity); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2511 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2512 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2513 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2514 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2515 Py_INCREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2516 self->target = target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2517 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2518 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
|
2519 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
|
2520 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
|
2521 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
|
2522 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
|
2523 self->handle_pi = PyObject_GetAttrString(target, "pi"); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2524 self->handle_close = PyObject_GetAttrString(target, "close"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2525 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2526 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2527 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2528 /* configure parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2529 EXPAT(SetUserData)(self->parser, self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2530 EXPAT(SetElementHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2531 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2532 (XML_StartElementHandler) expat_start_handler, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2533 (XML_EndElementHandler) expat_end_handler |
|
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 EXPAT(SetDefaultHandlerExpand)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2536 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2537 (XML_DefaultHandler) expat_default_handler |
|
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 EXPAT(SetCharacterDataHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2540 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2541 (XML_CharacterDataHandler) expat_data_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2542 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2543 if (self->handle_comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2544 EXPAT(SetCommentHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2545 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2546 (XML_CommentHandler) expat_comment_handler |
|
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 if (self->handle_pi) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2549 EXPAT(SetProcessingInstructionHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2550 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2551 (XML_ProcessingInstructionHandler) expat_pi_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2552 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2553 #if defined(Py_USING_UNICODE) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2554 EXPAT(SetUnknownEncodingHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2555 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2556 (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
|
2557 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2558 #endif |
|
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 ALLOC(sizeof(XMLParserObject), "create expatparser"); |
|
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 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2563 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2564 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2565 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2566 xmlparser_dealloc(XMLParserObject* self) |
|
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 EXPAT(ParserFree)(self->parser); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2569 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2570 Py_XDECREF(self->handle_close); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2571 Py_XDECREF(self->handle_pi); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2572 Py_XDECREF(self->handle_comment); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2573 Py_XDECREF(self->handle_end); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2574 Py_XDECREF(self->handle_data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2575 Py_XDECREF(self->handle_start); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2576 Py_XDECREF(self->handle_xml); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2577 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2578 Py_DECREF(self->target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2579 Py_DECREF(self->entity); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2580 Py_DECREF(self->names); |
|
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 RELEASE(sizeof(XMLParserObject), "destroy expatparser"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2583 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2584 PyObject_Del(self); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2587 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2588 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2589 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2590 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2591 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
|
2592 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2593 int ok; |
|
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 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
|
2596 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2597 if (PyErr_Occurred()) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2598 return NULL; |
|
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 if (!ok) { |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2601 expat_set_error( |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2602 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
|
2603 EXPAT(GetErrorLineNumber)(self->parser), |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2604 EXPAT(GetErrorColumnNumber)(self->parser) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2605 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2606 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2607 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2608 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2609 Py_RETURN_NONE; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2612 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2613 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
|
2614 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2615 /* end feeding data to parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2616 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2617 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2618 if (!PyArg_ParseTuple(args, ":close")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2619 return NULL; |
|
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 res = expat_parse(self, "", 0, 1); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2622 if (!res) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2623 return NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2624 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2625 if (TreeBuilder_CheckExact(self->target)) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2626 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2627 return treebuilder_done((TreeBuilderObject*) self->target); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2628 } if (self->handle_close) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2629 Py_DECREF(res); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2630 return PyObject_CallFunction(self->handle_close, ""); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2631 } else |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2632 return res; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2633 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2634 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2635 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2636 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
|
2637 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2638 /* feed data to parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2639 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2640 char* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2641 int data_len; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2642 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
|
2643 return NULL; |
|
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 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
|
2646 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2647 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2648 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2649 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
|
2650 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2651 /* (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
|
2652 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2653 PyObject* reader; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2654 PyObject* buffer; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2655 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2656 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2657 PyObject* fileobj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2658 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
|
2659 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2660 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2661 reader = PyObject_GetAttrString(fileobj, "read"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2662 if (!reader) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2663 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2664 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2665 /* read from open file object */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2666 for (;;) { |
|
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 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
|
2669 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2670 if (!buffer) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2671 /* 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
|
2672 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2673 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2674 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2675 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2676 if (!PyString_CheckExact(buffer) || PyString_GET_SIZE(buffer) == 0) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2677 Py_DECREF(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2678 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2679 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2680 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2681 res = expat_parse( |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2682 self, PyString_AS_STRING(buffer), PyString_GET_SIZE(buffer), 0 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2683 ); |
|
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 Py_DECREF(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2686 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2687 if (!res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2688 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2689 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2690 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2691 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2692 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2693 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2694 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2695 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2696 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2697 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
|
2698 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2699 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
|
2700 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2701 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
|
2702 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2703 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2704 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2705 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2706 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2707 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2708 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
|
2709 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2710 /* activate element event reporting */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2711 |
|
38759
1a11a4a49fb8
Fix some Py_ssize_t issues
Neal Norwitz <nnorwitz@gmail.com>
parents:
38560
diff
changeset
|
2712 Py_ssize_t i; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2713 TreeBuilderObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2714 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2715 PyObject* events; /* event collector */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2716 PyObject* event_set = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2717 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
|
2718 &event_set)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2719 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2720 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2721 if (!TreeBuilder_CheckExact(self->target)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2722 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2723 PyExc_TypeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2724 "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
|
2725 "targets" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2726 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2727 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2728 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2729 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2730 target = (TreeBuilderObject*) self->target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2731 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2732 Py_INCREF(events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2733 Py_XDECREF(target->events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2734 target->events = events; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2735 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2736 /* clear out existing events */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2737 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
|
2738 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
|
2739 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
|
2740 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
|
2741 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2742 if (event_set == Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2743 /* default is "end" only */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2744 target->end_event_obj = PyString_FromString("end"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2745 Py_RETURN_NONE; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2748 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
|
2749 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2750 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2751 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
|
2752 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
|
2753 char* event; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2754 if (!PyString_Check(item)) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2755 goto error; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2756 event = PyString_AS_STRING(item); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2757 if (strcmp(event, "start") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2758 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2759 target->start_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2760 } 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
|
2761 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2762 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
|
2763 target->end_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2764 } 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
|
2765 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2766 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
|
2767 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
|
2768 EXPAT(SetNamespaceDeclHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2769 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2770 (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
|
2771 (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
|
2772 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2773 } 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
|
2774 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2775 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
|
2776 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
|
2777 EXPAT(SetNamespaceDeclHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2778 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2779 (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
|
2780 (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
|
2781 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2782 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2783 PyErr_Format( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2784 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2785 "unknown event '%s'", event |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2786 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2787 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2788 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2789 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2790 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2791 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2792 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2793 error: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2794 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2795 PyExc_TypeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2796 "invalid event tuple" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2797 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2798 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2799 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2800 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2801 static PyMethodDef xmlparser_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2802 {"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
|
2803 {"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
|
2804 {"_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
|
2805 {"_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
|
2806 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2807 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2808 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2809 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2810 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
|
2811 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2812 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2813 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2814 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
|
2815 if (res) |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2816 return res; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2817 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2818 PyErr_Clear(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2819 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2820 if (strcmp(name, "entity") == 0) |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2821 res = self->entity; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2822 else if (strcmp(name, "target") == 0) |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2823 res = self->target; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2824 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
|
2825 char buffer[100]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2826 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
|
2827 XML_MINOR_VERSION, XML_MICRO_VERSION); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2828 return PyString_FromString(buffer); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2829 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2830 PyErr_SetString(PyExc_AttributeError, name); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2831 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2832 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2833 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2834 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2835 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2836 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2837 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2838 statichere PyTypeObject XMLParser_Type = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2839 PyObject_HEAD_INIT(NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2840 0, "XMLParser", sizeof(XMLParserObject), 0, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2841 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2842 (destructor)xmlparser_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2843 0, /* tp_print */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2844 (getattrfunc)xmlparser_getattr, /* tp_getattr */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2845 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2846 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2847 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2848 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2849 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2850 /* python module interface */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2851 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2852 static PyMethodDef _functions[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2853 {"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
|
2854 {"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
|
2855 {"TreeBuilder", (PyCFunction) treebuilder, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2856 #if defined(USE_EXPAT) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2857 {"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
|
2858 {"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
|
2859 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2860 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2861 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2862 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2863 DL_EXPORT(void) |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2864 init_elementtree(void) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2865 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2866 PyObject* m; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2867 PyObject* g; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2868 char* bootstrap; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2869 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2870 /* Patch object type */ |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
2871 Py_TYPE(&Element_Type) = Py_TYPE(&TreeBuilder_Type) = &PyType_Type; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2872 #if defined(USE_EXPAT) |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
2873 Py_TYPE(&XMLParser_Type) = &PyType_Type; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2874 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2875 |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2876 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
|
2877 if (!m) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2878 return; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2879 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2880 /* python glue code */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2881 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2882 g = PyDict_New(); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2883 if (!g) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2884 return; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2885 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2886 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
|
2887 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2888 bootstrap = ( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2889 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2890 "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
|
2891 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2892 "try:\n" |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2893 " 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
|
2894 "except ImportError:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2895 " import ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2896 "ET = ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2897 "del ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2898 |
|
36051
9b897fb7ac6a
updating to cElementTree 1.0.5 (step 3 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
36050
diff
changeset
|
2899 "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
|
2900 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2901 "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
|
2902 " copy(cElementTree.Element('x'))\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2903 "except:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2904 " def copyelement(elem):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2905 " return elem\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2906 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2907 "class CommentProxy:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2908 " def __call__(self, text=None):\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2909 " 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
|
2910 " element.text = text\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2911 " return element\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2912 " def __cmp__(self, other):\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2913 " return cmp(ET.Comment, other)\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2914 "cElementTree.Comment = CommentProxy()\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2915 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2916 "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
|
2917 " def parse(self, source, parser=None):\n" |
|
73189
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2918 " close_source = False\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2919 " 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
|
2920 " source = open(source, 'rb')\n" |
|
73189
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2921 " close_source = False\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2922 " try:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2923 " if parser is not None:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2924 " while 1:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2925 " data = source.read(65536)\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2926 " if not data:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2927 " break\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2928 " parser.feed(data)\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2929 " self._root = parser.close()\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2930 " else:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2931 " parser = cElementTree.XMLParser()\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2932 " self._root = parser._parse(source)\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2933 " return self._root\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2934 " finally:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2935 " if close_source:\n" |
|
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2936 " source.close()\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2937 "cElementTree.ElementTree = ElementTree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2938 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2939 "def iter(node, tag=None):\n" /* helper */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2940 " if tag == '*':\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2941 " tag = None\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2942 " 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
|
2943 " yield node\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2944 " for node in node:\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2945 " for node in iter(node, tag):\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2946 " yield node\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2947 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2948 "def itertext(node):\n" /* helper */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2949 " if node.text:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2950 " yield node.text\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2951 " for e in node:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2952 " for s in e.itertext():\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2953 " yield s\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2954 " if e.tail:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2955 " yield e.tail\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2956 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2957 "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
|
2958 " tree = ElementTree()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2959 " tree.parse(source, parser)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2960 " return tree\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2961 "cElementTree.parse = parse\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2962 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2963 "class iterparse(object):\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2964 " root = None\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2965 " def __init__(self, file, events=None):\n" |
|
73189
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2966 " self._close_file = False\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2967 " 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
|
2968 " file = open(file, 'rb')\n" |
|
73189
eceaa31252b3
Closes #7334: close source files on ElementTree.parse and iterparse (partial backport of issue #10093 from 3.2).
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59998
diff
changeset
|
2969 " self._close_file = True\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2970 " self._file = file\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2971 " self._events = []\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2972 " self._index = 0\n" |
|
73293
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2973 " self._error = None\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2974 " self.root = self._root = None\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2975 " b = cElementTree.TreeBuilder()\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2976 " self._parser = cElementTree.XMLParser(b)\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2977 " self._parser._setevents(self._events, events)\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2978 " def next(self):\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2979 " while 1:\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2980 " try:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2981 " item = self._events[self._index]\n" |
|
73293
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2982 " self._index += 1\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2983 " return item\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
2984 " except IndexError:\n" |
|
73293
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2985 " pass\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2986 " if self._error:\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2987 " e = self._error\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2988 " self._error = None\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2989 " raise e\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2990 " if self._parser is None:\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2991 " self.root = self._root\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2992 " if self._close_file:\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2993 " self._file.close()\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2994 " raise StopIteration\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2995 " # load event buffer\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2996 " del self._events[:]\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2997 " self._index = 0\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2998 " data = self._file.read(16384)\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
2999 " if data:\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
3000 " try:\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3001 " self._parser.feed(data)\n" |
|
73293
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
3002 " except SyntaxError as exc:\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
3003 " self._error = exc\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3004 " else:\n" |
|
73293
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
3005 " self._root = self._parser.close()\n" |
|
e1dde980a92c
Issue #2892: preserve iterparse events in case of SyntaxError
Florent Xicluna <florent.xicluna@gmail.com>
parents:
73189
diff
changeset
|
3006 " self._parser = None\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3007 " def __iter__(self):\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3008 " return self\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3009 "cElementTree.iterparse = iterparse\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3010 |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3011 "class PIProxy:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3012 " def __call__(self, target, text=None):\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3013 " element = cElementTree.Element(ET.PI)\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3014 " element.text = target\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3015 " if text:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3016 " 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
|
3017 " return element\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3018 " def __cmp__(self, other):\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3019 " return cmp(ET.PI, other)\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3020 "cElementTree.PI = cElementTree.ProcessingInstruction = PIProxy()\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3021 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3022 "def XML(text):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3023 " parser = cElementTree.XMLParser()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3024 " parser.feed(text)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3025 " return parser.close()\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3026 "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
|
3027 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3028 "def XMLID(text):\n" /* public */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3029 " tree = XML(text)\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3030 " ids = {}\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3031 " for elem in tree.iter():\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3032 " id = elem.get('id')\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3033 " if id:\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3034 " ids[id] = elem\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3035 " return tree, ids\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3036 "cElementTree.XMLID = XMLID\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3037 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3038 "try:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3039 " register_namespace = ET.register_namespace\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3040 "except AttributeError:\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3041 " def register_namespace(prefix, uri):\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3042 " ET._namespace_map[uri] = prefix\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3043 "cElementTree.register_namespace = register_namespace\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3044 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3045 "cElementTree.dump = ET.dump\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3046 "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
|
3047 "cElementTree.iselement = ET.iselement\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3048 "cElementTree.QName = ET.QName\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3049 "cElementTree.tostring = ET.tostring\n" |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3050 "cElementTree.fromstringlist = ET.fromstringlist\n" |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3051 "cElementTree.tostringlist = ET.tostringlist\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3052 "cElementTree.VERSION = '" VERSION "'\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3053 "cElementTree.__version__ = '" VERSION "'\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3054 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3055 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3056 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3057 if (!PyRun_String(bootstrap, Py_file_input, g, NULL)) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3058 return; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3059 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3060 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
|
3061 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3062 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
|
3063 if (elementtree_copyelement_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3064 /* 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
|
3065 PyMethodDef* mp; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3066 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
|
3067 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
|
3068 mp->ml_name = "__reduce__"; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3069 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3070 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3071 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3072 PyErr_Clear(); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3073 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3074 elementtree_deepcopy_obj = PyDict_GetItemString(g, "deepcopy"); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3075 elementtree_iter_obj = PyDict_GetItemString(g, "iter"); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3076 elementtree_itertext_obj = PyDict_GetItemString(g, "itertext"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3077 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3078 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3079 /* link against pyexpat, if possible */ |
|
59998
d11fbc796499
Backported PyCapsule from 3.1, and converted most uses of
Larry Hastings <larry@hastings.org>
parents:
59512
diff
changeset
|
3080 expat_capi = PyCapsule_Import(PyExpat_CAPSULE_NAME, 0); |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3081 if (expat_capi) { |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3082 /* check that it's usable */ |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3083 if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 || |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3084 expat_capi->size < sizeof(struct PyExpat_CAPI) || |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3085 expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION || |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3086 expat_capi->MINOR_VERSION != XML_MINOR_VERSION || |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3087 expat_capi->MICRO_VERSION != XML_MICRO_VERSION) |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3088 expat_capi = NULL; |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3089 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3090 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3091 |
|
59511
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3092 elementtree_parseerror_obj = PyErr_NewException( |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3093 "cElementTree.ParseError", PyExc_SyntaxError, NULL |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3094 ); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3095 Py_INCREF(elementtree_parseerror_obj); |
|
831e30c0fd73
Issue #6472: The xml.etree package is updated to ElementTree 1.3. The cElementTree module is updated too.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
47527
diff
changeset
|
3096 PyModule_AddObject(m, "ParseError", elementtree_parseerror_obj); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3097 } |
