Mercurial > cpython-lru_cache-weakref
annotate Modules/_elementtree.c @ 77142:70ec1f671c19
Added test for namespace package dynamic path updates.
| author | Eric V. Smith <eric@trueblade.com> |
|---|---|
| date | Fri, 25 May 2012 11:25:27 -0400 |
| parents | 41a9d24d075e |
| children | 7d252dbfbee3 |
| 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 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
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 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
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 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
32 * 2007-08-25 fl call custom builder's close method from XMLParser |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
33 * 2007-08-31 fl added iter, extend from ET 1.3 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
34 * 2007-09-01 fl fixed ParseError exception, setslice source type, etc |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
35 * 2007-09-03 fl fixed handling of negative insert indexes |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
36 * 2007-09-04 fl added itertext from ET 1.3 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
37 * 2007-09-06 fl added position attribute to ParseError exception |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
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 * |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
40 * Copyright (c) 1999-2009 by Secret Labs AB. All rights reserved. |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
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. */ |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
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" |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
51 #include "structmember.h" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
52 |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
53 #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
|
54 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 /* configuration */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
58 /* 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
|
59 #define USE_EXPAT |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
60 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
61 /* 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
|
62 /* #define USE_PYEXPAT_CAPI */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
63 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
64 /* 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
|
65 allocations. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
66 #define STATIC_CHILDREN 4 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
67 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
68 /* 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
|
69 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
|
70 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
|
71 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
|
72 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
73 /* Also note that pymalloc always allocates blocks in multiples of |
|
74903
65fc79fb4eb2
Issue #13988: cElementTree is deprecated and the _elementtree accelerator is automatically used whenever available.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
74870
diff
changeset
|
74 eight bytes. For the current C version of ElementTree, this means |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
75 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
|
76 32-bit platforms. */ |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
80 #if 0 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
81 static int memory = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
82 #define ALLOC(size, comment)\ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
83 do { memory += size; printf("%8d - %s\n", memory, comment); } while (0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
84 #define RELEASE(size, comment)\ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
85 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
|
86 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
87 #define ALLOC(size, comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
88 #define RELEASE(size, comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
89 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
90 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
91 /* compiler tweaks */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
92 #if defined(_MSC_VER) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
93 #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
|
94 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
95 #define LOCAL(type) static type |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
96 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
97 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
98 /* 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
|
99 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
|
100 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
|
101 info. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
102 #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
|
103 #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
|
104 #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
|
105 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
106 /* glue functions (see the init function for details) */ |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
107 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
|
108 static PyObject* elementtree_deepcopy_obj; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
109 static PyObject* elementtree_iter_obj; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
110 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
|
111 static PyObject* elementpath_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
112 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
113 /* helpers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
114 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
115 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
116 deepcopy(PyObject* object, PyObject* memo) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
117 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
118 /* 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
|
119 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
120 PyObject* args; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
121 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
122 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
123 if (!elementtree_deepcopy_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
124 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
125 PyExc_RuntimeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
126 "deepcopy helper not found" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
127 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
128 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
129 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
130 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
131 args = PyTuple_New(2); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
132 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
133 return NULL; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
134 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
135 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
|
136 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
|
137 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
138 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
|
139 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
140 Py_DECREF(args); |
|
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 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
143 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
144 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
145 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
146 list_join(PyObject* list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
147 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
148 /* 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
|
149 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
150 PyObject* joiner; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
151 PyObject* function; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
152 PyObject* args; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
153 PyObject* result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
154 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
155 switch (PyList_GET_SIZE(list)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
156 case 0: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
157 Py_DECREF(list); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
158 return PyBytes_FromString(""); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
159 case 1: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
160 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
|
161 Py_INCREF(result); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
162 Py_DECREF(list); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
163 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
164 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
165 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
166 /* 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
|
167 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
|
168 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
169 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
|
170 if (!joiner) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
171 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
172 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
173 function = PyObject_GetAttrString(joiner, "join"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
174 if (!function) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
175 Py_DECREF(joiner); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
176 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
177 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
178 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
179 args = PyTuple_New(1); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
180 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
181 return NULL; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
182 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
183 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
|
184 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
185 result = PyObject_CallObject(function, args); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
186 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
187 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
|
188 Py_DECREF(function); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
189 Py_DECREF(joiner); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
190 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
191 return result; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
192 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
193 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
194 /* -------------------------------------------------------------------- */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
195 /* the Element type */ |
|
36050
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 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
198 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
199 /* 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
|
200 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
201 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
202 /* child elements */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
203 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
|
204 int allocated; /* allocated items */ |
|
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 /* 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
|
207 PyObject* *children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
208 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
209 PyObject* _children[STATIC_CHILDREN]; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
210 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
211 } ElementObjectExtra; |
|
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 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
214 PyObject_HEAD |
|
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 /* element tag (a string). */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
217 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
218 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
219 /* 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 should be left intact. */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
225 PyObject* text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
226 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
227 /* 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
|
228 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
|
229 PyObject* tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
230 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
231 ElementObjectExtra* extra; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
232 |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
233 PyObject *weakreflist; /* For tp_weaklistoffset */ |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
234 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
235 } ElementObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
236 |
|
37144
91dd4d44d3bc
Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
237 static PyTypeObject Element_Type; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
238 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
239 #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
|
240 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
241 /* -------------------------------------------------------------------- */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
242 /* Element constructors and destructor */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
243 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
244 LOCAL(int) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
245 create_extra(ElementObject* self, PyObject* attrib) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
246 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
247 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
|
248 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
249 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
250 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
251 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
252 attrib = Py_None; |
|
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 Py_INCREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
255 self->extra->attrib = attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
256 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
257 self->extra->length = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
258 self->extra->allocated = STATIC_CHILDREN; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
259 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
|
260 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
261 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
262 } |
|
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 LOCAL(void) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
265 dealloc_extra(ElementObject* self) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
266 { |
|
76101
118729090dc5
Fix Windows compilation errors
Eli Bendersky <eliben@gmail.com>
parents:
76098
diff
changeset
|
267 ElementObjectExtra *myextra; |
|
118729090dc5
Fix Windows compilation errors
Eli Bendersky <eliben@gmail.com>
parents:
76098
diff
changeset
|
268 int i; |
|
118729090dc5
Fix Windows compilation errors
Eli Bendersky <eliben@gmail.com>
parents:
76098
diff
changeset
|
269 |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
270 if (!self->extra) |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
271 return; |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
272 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
273 /* Avoid DECREFs calling into this code again (cycles, etc.) |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
274 */ |
|
76101
118729090dc5
Fix Windows compilation errors
Eli Bendersky <eliben@gmail.com>
parents:
76098
diff
changeset
|
275 myextra = self->extra; |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
276 self->extra = NULL; |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
277 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
278 Py_DECREF(myextra->attrib); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
279 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
280 for (i = 0; i < myextra->length; i++) |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
281 Py_DECREF(myextra->children[i]); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
282 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
283 if (myextra->children != myextra->_children) |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
284 PyObject_Free(myextra->children); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
285 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
286 PyObject_Free(myextra); |
|
36050
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 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
289 /* Convenience internal function to create new Element objects with the given |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
290 * tag and attributes. |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
291 */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
292 LOCAL(PyObject*) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
293 create_new_element(PyObject* tag, PyObject* attrib) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
294 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
295 ElementObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
296 |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
297 self = PyObject_GC_New(ElementObject, &Element_Type); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
298 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
299 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
300 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
301 /* use None for empty dictionaries */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
302 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
|
303 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
304 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
305 self->extra = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
306 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
307 if (attrib != Py_None) { |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
308 if (create_extra(self, attrib) < 0) { |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37144
diff
changeset
|
309 PyObject_Del(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
310 return NULL; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
311 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
312 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
313 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
314 Py_INCREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
315 self->tag = tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
316 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
317 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
318 self->text = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
319 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
320 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
321 self->tail = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
322 |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
323 self->weakreflist = NULL; |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
324 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
325 ALLOC(sizeof(ElementObject), "create element"); |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
326 PyObject_GC_Track(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
327 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
328 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
329 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
330 static PyObject * |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
331 element_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
332 { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
333 ElementObject *e = (ElementObject *)type->tp_alloc(type, 0); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
334 if (e != NULL) { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
335 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
336 e->tag = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
337 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
338 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
339 e->text = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
340 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
341 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
342 e->tail = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
343 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
344 e->extra = NULL; |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
345 e->weakreflist = NULL; |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
346 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
347 return (PyObject *)e; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
348 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
349 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
350 static int |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
351 element_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
352 { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
353 PyObject *tag; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
354 PyObject *tmp; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
355 PyObject *attrib = NULL; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
356 ElementObject *self_elem; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
357 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
358 if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, &PyDict_Type, &attrib)) |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
359 return -1; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
360 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
361 if (attrib || kwds) { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
362 attrib = (attrib) ? PyDict_Copy(attrib) : PyDict_New(); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
363 if (!attrib) |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
364 return -1; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
365 if (kwds) |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
366 PyDict_Update(attrib, kwds); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
367 } else { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
368 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
369 attrib = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
370 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
371 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
372 self_elem = (ElementObject *)self; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
373 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
374 /* Use None for empty dictionaries */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
375 if (PyDict_CheckExact(attrib) && PyDict_Size(attrib) == 0) { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
376 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
377 attrib = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
378 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
379 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
380 if (attrib != Py_None) { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
381 if (create_extra(self_elem, attrib) < 0) { |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
382 PyObject_Del(self_elem); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
383 return -1; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
384 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
385 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
386 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
387 /* If create_extra needed attrib, it took a reference to it, so we can |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
388 * release ours anyway. |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
389 */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
390 Py_DECREF(attrib); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
391 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
392 /* Replace the objects already pointed to by tag, text and tail. */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
393 tmp = self_elem->tag; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
394 self_elem->tag = tag; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
395 Py_INCREF(tag); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
396 Py_DECREF(tmp); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
397 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
398 tmp = self_elem->text; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
399 self_elem->text = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
400 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
401 Py_DECREF(JOIN_OBJ(tmp)); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
402 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
403 tmp = self_elem->tail; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
404 self_elem->tail = Py_None; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
405 Py_INCREF(Py_None); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
406 Py_DECREF(JOIN_OBJ(tmp)); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
407 |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
408 return 0; |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
409 } |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
410 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
411 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
412 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
|
413 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
414 int size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
415 PyObject* *children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
416 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
417 /* 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
|
418 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
|
419 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
420 if (!self->extra) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
421 create_extra(self, NULL); |
|
36050
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 size = self->extra->length + extra; |
|
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 if (size > self->extra->allocated) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
426 /* 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
|
427 size = (size >> 3) + (size < 9 ? 3 : 6) + size; |
|
44742
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
428 /* Coverity CID #182 size_error: Allocating 1 bytes to pointer "children" |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
429 * which needs at least 4 bytes. |
|
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
430 * Although it's a false alarm always assume at least one child to |
|
44742
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
431 * be safe. |
|
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
432 */ |
|
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
433 size = size ? size : 1; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
434 if (self->extra->children != self->extra->_children) { |
|
44742
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
435 /* Coverity CID #182 size_error: Allocating 1 bytes to pointer |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
436 * "children", which needs at least 4 bytes. Although it's a |
|
44742
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
437 * false alarm always assume at least one child to be safe. |
|
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
438 */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
439 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
|
440 size * sizeof(PyObject*)); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
441 if (!children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
442 goto nomemory; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
443 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
444 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
|
445 if (!children) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
446 goto nomemory; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
447 /* 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
|
448 memcpy(children, self->extra->children, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
449 self->extra->length * sizeof(PyObject*)); |
|
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 self->extra->children = children; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
452 self->extra->allocated = size; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
453 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
454 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
455 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
456 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
457 nomemory: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
458 PyErr_NoMemory(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
459 return -1; |
|
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 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
463 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
|
464 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
465 /* 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
|
466 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
467 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
|
468 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
469 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
470 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
471 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
|
472 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
473 self->extra->length++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
474 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
475 return 0; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
478 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
479 element_get_attrib(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
480 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
481 /* 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
|
482 /* 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
|
483 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
484 PyObject* res = self->extra->attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
485 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
486 if (res == Py_None) { |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
487 Py_DECREF(res); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
488 /* create missing dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
489 res = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
490 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
491 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
492 self->extra->attrib = res; |
|
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 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
496 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
497 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
498 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
499 element_get_text(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
500 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
501 /* 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
|
502 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
503 PyObject* res = self->text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
504 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
505 if (JOIN_GET(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
506 res = JOIN_OBJ(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
507 if (PyList_CheckExact(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
508 res = list_join(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
509 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
510 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
511 self->text = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
512 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
513 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
514 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
515 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
516 } |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
519 element_get_tail(ElementObject* self) |
|
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 /* 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
|
522 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
523 PyObject* res = self->tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
524 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
525 if (JOIN_GET(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
526 res = JOIN_OBJ(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
527 if (PyList_CheckExact(res)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
528 res = list_join(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
529 if (!res) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
530 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
531 self->tail = res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
532 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
533 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
534 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
535 return res; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
538 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
539 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
|
540 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
541 PyObject* elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
542 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
543 ElementObject* parent; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
544 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
545 PyObject* attrib = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
546 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
|
547 &Element_Type, &parent, &tag, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
548 &PyDict_Type, &attrib)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
549 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
550 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
551 if (attrib || kw) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
552 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
|
553 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
554 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
555 if (kw) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
556 PyDict_Update(attrib, kw); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
557 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
558 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
559 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
560 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
561 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
562 elem = create_new_element(tag, attrib); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
563 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
564 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
565 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
566 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
|
567 Py_DECREF(elem); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
568 return NULL; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
569 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
570 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
571 return elem; |
|
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 |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
574 static int |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
575 element_gc_traverse(ElementObject *self, visitproc visit, void *arg) |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
576 { |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
577 Py_VISIT(self->tag); |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
578 Py_VISIT(JOIN_OBJ(self->text)); |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
579 Py_VISIT(JOIN_OBJ(self->tail)); |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
580 |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
581 if (self->extra) { |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
582 int i; |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
583 Py_VISIT(self->extra->attrib); |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
584 |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
585 for (i = 0; i < self->extra->length; ++i) |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
586 Py_VISIT(self->extra->children[i]); |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
587 } |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
588 return 0; |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
589 } |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
590 |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
591 static int |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
592 element_gc_clear(ElementObject *self) |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
593 { |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
594 Py_CLEAR(self->tag); |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
595 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
596 /* The following is like Py_CLEAR for self->text and self->tail, but |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
597 * written explicitily because the real pointers hide behind access |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
598 * macros. |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
599 */ |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
600 if (self->text) { |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
601 PyObject *tmp = JOIN_OBJ(self->text); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
602 self->text = NULL; |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
603 Py_DECREF(tmp); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
604 } |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
605 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
606 if (self->tail) { |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
607 PyObject *tmp = JOIN_OBJ(self->tail); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
608 self->tail = NULL; |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
609 Py_DECREF(tmp); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
610 } |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
611 |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
612 /* After dropping all references from extra, it's no longer valid anyway, |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
613 * so fully deallocate it. |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
614 */ |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
615 dealloc_extra(self); |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
616 return 0; |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
617 } |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
618 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
619 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
620 element_dealloc(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
621 { |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
622 PyObject_GC_UnTrack(self); |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
623 |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
624 if (self->weakreflist != NULL) |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
625 PyObject_ClearWeakRefs((PyObject *) self); |
|
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
626 |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
627 /* element_gc_clear clears all references and deallocates extra |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
628 */ |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
629 element_gc_clear(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
630 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
631 RELEASE(sizeof(ElementObject), "destroy element"); |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
632 Py_TYPE(self)->tp_free((PyObject *)self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
633 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
634 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
635 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
636 /* methods (in alphabetical order) */ |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
639 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
|
640 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
641 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
642 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
|
643 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
644 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
645 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
|
646 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
647 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
648 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
649 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
650 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
651 static PyObject* |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
652 element_clearmethod(ElementObject* self, PyObject* args) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
653 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
654 if (!PyArg_ParseTuple(args, ":clear")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
655 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
656 |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
657 dealloc_extra(self); |
|
36050
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_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
660 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
|
661 self->text = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
662 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
663 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
664 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
|
665 self->tail = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
666 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
667 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
668 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
669 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
670 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
671 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
|
672 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
673 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
674 ElementObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
675 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
676 if (!PyArg_ParseTuple(args, ":__copy__")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
677 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
678 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
679 element = (ElementObject*) create_new_element( |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
680 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
|
681 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
682 if (!element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
683 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
684 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
685 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
|
686 element->text = self->text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
687 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
|
688 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
689 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
|
690 element->tail = self->tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
691 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
|
692 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
693 if (self->extra) { |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
694 |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
695 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
|
696 Py_DECREF(element); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
697 return NULL; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
698 } |
|
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 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
|
701 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
|
702 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
|
703 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
704 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
705 element->extra->length = self->extra->length; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
706 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
707 } |
|
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 return (PyObject*) element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
710 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
711 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
712 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
713 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
|
714 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
715 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
716 ElementObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
717 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
718 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
719 PyObject* text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
720 PyObject* tail; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
721 PyObject* id; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
722 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
723 PyObject* memo; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
724 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
|
725 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
726 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
727 tag = deepcopy(self->tag, memo); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
728 if (!tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
729 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
730 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
731 if (self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
732 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
|
733 if (!attrib) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
734 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
735 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
736 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
737 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
738 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
739 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
740 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
741 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
742 element = (ElementObject*) create_new_element(tag, attrib); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
743 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
744 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
745 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
746 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
747 if (!element) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
748 return NULL; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
749 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
750 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
|
751 if (!text) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
752 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
753 Py_DECREF(element->text); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
754 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
|
755 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
756 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
|
757 if (!tail) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
758 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
759 Py_DECREF(element->tail); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
760 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
|
761 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
762 if (self->extra) { |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
763 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
764 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
|
765 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
766 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
767 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
|
768 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
|
769 if (!child) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
770 element->extra->length = i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
771 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
772 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
773 element->extra->children[i] = child; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
774 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
775 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
776 element->extra->length = self->extra->length; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
777 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
778 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
779 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
780 /* add object to memo dictionary (so deepcopy won't visit it again) */ |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
42491
diff
changeset
|
781 id = PyLong_FromLong((Py_uintptr_t) self); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
782 if (!id) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
783 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
784 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
785 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
|
786 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
787 Py_DECREF(id); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
788 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
789 if (i < 0) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
790 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
791 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
792 return (PyObject*) element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
793 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
794 error: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
795 Py_DECREF(element); |
|
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 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
798 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
799 LOCAL(int) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
800 checkpath(PyObject* tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
801 { |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
802 Py_ssize_t i; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
803 int check = 1; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
804 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
805 /* 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
|
806 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
807 #define PATHCHAR(ch) \ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
808 (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
|
809 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
810 if (PyUnicode_Check(tag)) { |
| 72475 | 811 const Py_ssize_t len = PyUnicode_GET_LENGTH(tag); |
| 812 void *data = PyUnicode_DATA(tag); | |
| 813 unsigned int kind = PyUnicode_KIND(tag); | |
| 814 for (i = 0; i < len; i++) { | |
| 815 Py_UCS4 ch = PyUnicode_READ(kind, data, i); | |
| 816 if (ch == '{') | |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
817 check = 0; |
| 72475 | 818 else if (ch == '}') |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
819 check = 1; |
| 72475 | 820 else if (check && PATHCHAR(ch)) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
821 return 1; |
|
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 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
824 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
825 if (PyBytes_Check(tag)) { |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
826 char *p = PyBytes_AS_STRING(tag); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
827 for (i = 0; i < PyBytes_GET_SIZE(tag); i++) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
828 if (p[i] == '{') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
829 check = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
830 else if (p[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
831 check = 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
832 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
|
833 return 1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
834 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
835 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
836 } |
|
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 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
|
839 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
840 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
841 static PyObject* |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
842 element_extend(ElementObject* self, PyObject* args) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
843 { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
844 PyObject* seq; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
845 Py_ssize_t i, seqlen = 0; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
846 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
847 PyObject* seq_in; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
848 if (!PyArg_ParseTuple(args, "O:extend", &seq_in)) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
849 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
850 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
851 seq = PySequence_Fast(seq_in, ""); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
852 if (!seq) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
853 PyErr_Format( |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
854 PyExc_TypeError, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
855 "expected sequence, not \"%.200s\"", Py_TYPE(seq_in)->tp_name |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
856 ); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
857 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
858 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
859 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
860 seqlen = PySequence_Size(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
861 for (i = 0; i < seqlen; i++) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
862 PyObject* element = PySequence_Fast_GET_ITEM(seq, i); |
|
75894
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
863 if (!PyObject_IsInstance(element, (PyObject *)&Element_Type)) { |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
864 Py_DECREF(seq); |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
865 PyErr_Format( |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
866 PyExc_TypeError, |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
867 "expected an Element, not \"%.200s\"", |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
868 Py_TYPE(element)->tp_name); |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
869 return NULL; |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
870 } |
|
75268a773455
Issue #13782: streamline argument type-checking in ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75722
diff
changeset
|
871 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
872 if (element_add_subelement(self, element) < 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
873 Py_DECREF(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
874 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
875 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
876 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
877 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
878 Py_DECREF(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
879 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
880 Py_RETURN_NONE; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
881 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
882 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
883 static PyObject* |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
884 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
|
885 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
886 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
887 PyObject* tag; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
888 PyObject* namespaces = Py_None; |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
889 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
890 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
|
891 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
892 |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
893 if (checkpath(tag) || namespaces != Py_None) { |
|
72925
7109f31300fb
Rename _Py_identifier to _Py_IDENTIFIER.
Martin v. Löwis <martin@v.loewis.de>
parents:
72835
diff
changeset
|
894 _Py_IDENTIFIER(find); |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
895 return _PyObject_CallMethodId( |
|
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
896 elementpath_obj, &PyId_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
|
897 ); |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
898 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
899 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
900 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
901 Py_RETURN_NONE; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
902 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
903 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
|
904 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
|
905 if (Element_CheckExact(item) && |
|
51244
e9675d72e3e3
Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
906 PyObject_RichCompareBool(((ElementObject*)item)->tag, tag, Py_EQ) == 1) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
907 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
908 return item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
909 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
910 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
911 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
912 Py_RETURN_NONE; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
915 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
916 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
|
917 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
918 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
919 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
920 PyObject* default_value = Py_None; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
921 PyObject* namespaces = Py_None; |
|
72925
7109f31300fb
Rename _Py_identifier to _Py_IDENTIFIER.
Martin v. Löwis <martin@v.loewis.de>
parents:
72835
diff
changeset
|
922 _Py_IDENTIFIER(findtext); |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
923 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
924 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
|
925 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
926 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
927 if (checkpath(tag) || namespaces != Py_None) |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
928 return _PyObject_CallMethodId( |
|
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
929 elementpath_obj, &PyId_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
|
930 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
931 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
932 if (!self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
933 Py_INCREF(default_value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
934 return default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
935 } |
|
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 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
|
938 ElementObject* item = (ElementObject*) self->extra->children[i]; |
|
51244
e9675d72e3e3
Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
939 if (Element_CheckExact(item) && (PyObject_RichCompareBool(item->tag, tag, Py_EQ) == 1)) { |
|
e9675d72e3e3
Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
940 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
941 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
|
942 if (text == Py_None) |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
943 return PyBytes_FromString(""); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
944 Py_XINCREF(text); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
945 return text; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
946 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
947 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
948 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
949 Py_INCREF(default_value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
950 return default_value; |
|
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* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
954 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
|
955 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
956 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
957 PyObject* out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
958 PyObject* tag; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
959 PyObject* namespaces = Py_None; |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
960 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
961 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
|
962 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
963 |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
964 if (checkpath(tag) || namespaces != Py_None) { |
|
72925
7109f31300fb
Rename _Py_identifier to _Py_IDENTIFIER.
Martin v. Löwis <martin@v.loewis.de>
parents:
72835
diff
changeset
|
965 _Py_IDENTIFIER(findall); |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
966 return _PyObject_CallMethodId( |
|
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
967 elementpath_obj, &PyId_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
|
968 ); |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
969 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
970 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
971 out = PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
972 if (!out) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
973 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
974 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
975 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
976 return out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
977 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
978 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
|
979 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
|
980 if (Element_CheckExact(item) && |
|
51244
e9675d72e3e3
Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
981 PyObject_RichCompareBool(((ElementObject*)item)->tag, tag, Py_EQ) == 1) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
982 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
|
983 Py_DECREF(out); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
984 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
985 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
986 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
987 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
988 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
989 return out; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
990 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
991 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
992 static PyObject* |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
993 element_iterfind(ElementObject* self, PyObject* args) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
994 { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
995 PyObject* tag; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
996 PyObject* namespaces = Py_None; |
|
72925
7109f31300fb
Rename _Py_identifier to _Py_IDENTIFIER.
Martin v. Löwis <martin@v.loewis.de>
parents:
72835
diff
changeset
|
997 _Py_IDENTIFIER(iterfind); |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
998 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
999 if (!PyArg_ParseTuple(args, "O|O:iterfind", &tag, &namespaces)) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1000 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1001 |
|
72835
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1002 return _PyObject_CallMethodId( |
|
5e33219492bc
Add API for static strings, primarily good for identifiers.
Martin v. Löwis <martin@v.loewis.de>
parents:
72475
diff
changeset
|
1003 elementpath_obj, &PyId_iterfind, "OOO", self, tag, namespaces |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1004 ); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1005 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1006 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1007 static PyObject* |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1008 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
|
1009 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1010 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1011 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1012 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1013 PyObject* default_value = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1014 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
|
1015 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1016 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1017 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
|
1018 value = default_value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1019 else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1020 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
|
1021 if (!value) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1022 value = default_value; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1025 Py_INCREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1026 return value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1027 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1028 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1029 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1030 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
|
1031 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1032 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1033 PyObject* list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1034 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1035 /* FIXME: report as deprecated? */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1036 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1037 if (!PyArg_ParseTuple(args, ":getchildren")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1038 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1039 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1040 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1041 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1042 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1043 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
|
1044 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1045 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1046 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1047 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
|
1048 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
|
1049 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1050 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
|
1051 } |
|
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 return list; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1054 } |
|
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 static PyObject* |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1057 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
|
1058 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1059 PyObject* result; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
1060 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1061 PyObject* tag = Py_None; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1062 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
|
1063 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1064 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1065 if (!elementtree_iter_obj) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1066 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1067 PyExc_RuntimeError, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1068 "iter helper not found" |
|
36050
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 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1071 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1072 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1073 args = PyTuple_New(2); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1074 if (!args) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1075 return NULL; |
|
36450
c193283e63bc
Check return results for errors
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1076 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1077 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
|
1078 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
|
1079 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1080 result = PyObject_CallObject(elementtree_iter_obj, args); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1081 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1082 Py_DECREF(args); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1083 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1084 return result; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1085 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1086 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1087 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1088 static PyObject* |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1089 element_itertext(ElementObject* self, PyObject* args) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1090 { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1091 PyObject* result; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
1092 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1093 if (!PyArg_ParseTuple(args, ":itertext")) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1094 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1095 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1096 if (!elementtree_itertext_obj) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1097 PyErr_SetString( |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1098 PyExc_RuntimeError, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1099 "itertext helper not found" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1100 ); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1101 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1102 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1103 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1104 args = PyTuple_New(1); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1105 if (!args) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1106 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1107 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1108 Py_INCREF(self); PyTuple_SET_ITEM(args, 0, (PyObject*) self); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1109 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1110 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
|
1111 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1112 Py_DECREF(args); |
|
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 return result; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1117 static PyObject* |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1118 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
|
1119 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1120 ElementObject* self = (ElementObject*) self_; |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1121 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1122 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
|
1123 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1124 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1125 "child index out of range" |
|
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 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1128 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1129 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1130 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
|
1131 return self->extra->children[index]; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1134 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1135 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
|
1136 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1137 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1138 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1139 int index; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1140 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1141 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
|
1142 &Element_Type, &element)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1143 return NULL; |
|
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 if (!self->extra) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1146 create_extra(self, NULL); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1147 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1148 if (index < 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1149 index += self->extra->length; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1150 if (index < 0) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1151 index = 0; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1152 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1153 if (index > self->extra->length) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1154 index = self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1155 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1156 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
|
1157 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1158 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1159 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
|
1160 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
|
1161 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1162 Py_INCREF(element); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1163 self->extra->children[index] = element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1164 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1165 self->extra->length++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1166 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1167 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1168 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1171 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
|
1172 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1173 if (!PyArg_ParseTuple(args, ":items")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1174 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1175 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1176 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
|
1177 return PyList_New(0); |
|
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 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
|
1180 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1183 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
|
1184 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1185 if (!PyArg_ParseTuple(args, ":keys")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1186 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1187 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1188 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
|
1189 return PyList_New(0); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1190 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1191 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
|
1192 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1193 |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1194 static Py_ssize_t |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1195 element_length(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1196 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1197 if (!self->extra) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1198 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1199 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1200 return self->extra->length; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1201 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1202 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1203 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1204 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
|
1205 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1206 PyObject* elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1207 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1208 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1209 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1210 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
|
1211 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1212 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1213 attrib = PyDict_Copy(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1214 if (!attrib) |
|
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 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1217 elem = create_new_element(tag, attrib); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1218 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1219 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1220 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1221 return elem; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1222 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1223 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1224 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1225 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
|
1226 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1227 int i; |
|
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 PyObject* element; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1230 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
|
1231 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1232 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1233 if (!self->extra) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1234 /* 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
|
1235 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1236 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1237 "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
|
1238 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1239 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1240 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1241 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1242 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
|
1243 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
|
1244 break; |
|
51244
e9675d72e3e3
Merged revisions 69181 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48660
diff
changeset
|
1245 if (PyObject_RichCompareBool(self->extra->children[i], element, Py_EQ) == 1) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1246 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1247 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1248 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1249 if (i == self->extra->length) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1250 /* 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
|
1251 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1252 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1253 "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
|
1254 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1255 return NULL; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1258 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
|
1259 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1260 self->extra->length--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1261 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1262 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
|
1263 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
|
1264 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1265 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1266 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1267 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1268 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1269 element_repr(ElementObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1270 { |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1271 if (self->tag) |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1272 return PyUnicode_FromFormat("<Element %R at %p>", self->tag, self); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1273 else |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1274 return PyUnicode_FromFormat("<Element at %p>", self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1275 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1276 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1277 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1278 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
|
1279 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1280 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1281 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1282 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1283 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1284 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
|
1285 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1286 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1287 if (!self->extra) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1288 create_extra(self, NULL); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1289 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1290 attrib = element_get_attrib(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1291 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1292 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1293 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1294 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
|
1295 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1296 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1297 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1298 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1299 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1300 static int |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1301 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
|
1302 { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1303 ElementObject* self = (ElementObject*) self_; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1304 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1305 PyObject* old; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1306 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1307 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
|
1308 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1309 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1310 "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
|
1311 return -1; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1312 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1313 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1314 old = self->extra->children[index]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1315 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1316 if (item) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1317 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1318 self->extra->children[index] = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1319 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1320 self->extra->length--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1321 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
|
1322 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
|
1323 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1324 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1325 Py_DECREF(old); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1326 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1327 return 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1328 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1329 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1330 static PyObject* |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1331 element_subscr(PyObject* self_, PyObject* item) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1332 { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1333 ElementObject* self = (ElementObject*) self_; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1334 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1335 if (PyIndex_Check(item)) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1336 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1337 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1338 if (i == -1 && PyErr_Occurred()) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1339 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1340 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1341 if (i < 0 && self->extra) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1342 i += self->extra->length; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1343 return element_getitem(self_, i); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1344 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1345 else if (PySlice_Check(item)) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1346 Py_ssize_t start, stop, step, slicelen, cur, i; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1347 PyObject* list; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1348 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1349 if (!self->extra) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1350 return PyList_New(0); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1351 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65707
diff
changeset
|
1352 if (PySlice_GetIndicesEx(item, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1353 self->extra->length, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1354 &start, &stop, &step, &slicelen) < 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1355 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1356 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1357 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1358 if (slicelen <= 0) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1359 return PyList_New(0); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1360 else { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1361 list = PyList_New(slicelen); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1362 if (!list) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1363 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1364 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1365 for (cur = start, i = 0; i < slicelen; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1366 cur += step, i++) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1367 PyObject* item = self->extra->children[cur]; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1368 Py_INCREF(item); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1369 PyList_SET_ITEM(list, i, item); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1370 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1371 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1372 return list; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1373 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1374 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1375 else { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1376 PyErr_SetString(PyExc_TypeError, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1377 "element indices must be integers"); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1378 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1379 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1380 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1381 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1382 static int |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1383 element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1384 { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1385 ElementObject* self = (ElementObject*) self_; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1386 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1387 if (PyIndex_Check(item)) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1388 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1389 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1390 if (i == -1 && PyErr_Occurred()) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1391 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1392 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1393 if (i < 0 && self->extra) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1394 i += self->extra->length; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1395 return element_setitem(self_, i, value); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1396 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1397 else if (PySlice_Check(item)) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1398 Py_ssize_t start, stop, step, slicelen, newlen, cur, i; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1399 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1400 PyObject* recycle = NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1401 PyObject* seq = NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1402 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1403 if (!self->extra) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1404 create_extra(self, NULL); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1405 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
65707
diff
changeset
|
1406 if (PySlice_GetIndicesEx(item, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1407 self->extra->length, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1408 &start, &stop, &step, &slicelen) < 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1409 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1410 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1411 |
|
75505
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1412 if (value == NULL) { |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1413 /* Delete slice */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1414 size_t cur; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1415 Py_ssize_t i; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1416 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1417 if (slicelen <= 0) |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1418 return 0; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1419 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1420 /* Since we're deleting, the direction of the range doesn't matter, |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1421 * so for simplicity make it always ascending. |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1422 */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1423 if (step < 0) { |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1424 stop = start + 1; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1425 start = stop + step * (slicelen - 1) - 1; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1426 step = -step; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1427 } |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1428 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1429 assert((size_t)slicelen <= PY_SIZE_MAX / sizeof(PyObject *)); |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1430 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1431 /* recycle is a list that will contain all the children |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1432 * scheduled for removal. |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1433 */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1434 if (!(recycle = PyList_New(slicelen))) { |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1435 PyErr_NoMemory(); |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1436 return -1; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1437 } |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1438 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1439 /* This loop walks over all the children that have to be deleted, |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1440 * with cur pointing at them. num_moved is the amount of children |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1441 * until the next deleted child that have to be "shifted down" to |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1442 * occupy the deleted's places. |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1443 * Note that in the ith iteration, shifting is done i+i places down |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1444 * because i children were already removed. |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1445 */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1446 for (cur = start, i = 0; cur < (size_t)stop; cur += step, ++i) { |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1447 /* Compute how many children have to be moved, clipping at the |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1448 * list end. |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1449 */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1450 Py_ssize_t num_moved = step - 1; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1451 if (cur + step >= (size_t)self->extra->length) { |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1452 num_moved = self->extra->length - cur - 1; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1453 } |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1454 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1455 PyList_SET_ITEM(recycle, i, self->extra->children[cur]); |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1456 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1457 memmove( |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1458 self->extra->children + cur - i, |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1459 self->extra->children + cur + 1, |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1460 num_moved * sizeof(PyObject *)); |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1461 } |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1462 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1463 /* Leftover "tail" after the last removed child */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1464 cur = start + (size_t)slicelen * step; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1465 if (cur < (size_t)self->extra->length) { |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1466 memmove( |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1467 self->extra->children + cur - slicelen, |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1468 self->extra->children + cur, |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1469 (self->extra->length - cur) * sizeof(PyObject *)); |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1470 } |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1471 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1472 self->extra->length -= slicelen; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1473 |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1474 /* Discard the recycle list with all the deleted sub-elements */ |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1475 Py_XDECREF(recycle); |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1476 return 0; |
|
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1477 } |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1478 else { |
|
75505
1a721b9a4039
Issue #14178: Problem deleting slices with steps != +1 in the _elementtree module.
Eli Bendersky <eliben@gmail.com>
parents:
75410
diff
changeset
|
1479 /* A new slice is actually being assigned */ |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1480 seq = PySequence_Fast(value, ""); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1481 if (!seq) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1482 PyErr_Format( |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1483 PyExc_TypeError, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1484 "expected sequence, not \"%.200s\"", Py_TYPE(value)->tp_name |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1485 ); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1486 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1487 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1488 newlen = PySequence_Size(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1489 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1490 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1491 if (step != 1 && newlen != slicelen) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1492 { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1493 PyErr_Format(PyExc_ValueError, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1494 "attempt to assign sequence of size %zd " |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1495 "to extended slice of size %zd", |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1496 newlen, slicelen |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1497 ); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1498 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1499 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1500 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1501 /* Resize before creating the recycle bin, to prevent refleaks. */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1502 if (newlen > slicelen) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1503 if (element_resize(self, newlen - slicelen) < 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1504 if (seq) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1505 Py_DECREF(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1506 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1507 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1508 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1509 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1510 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1511 if (slicelen > 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1512 /* to avoid recursive calls to this method (via decref), move |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1513 old items to the recycle bin here, and get rid of them when |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1514 we're done modifying the element */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1515 recycle = PyList_New(slicelen); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1516 if (!recycle) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1517 if (seq) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1518 Py_DECREF(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1519 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1520 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1521 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1522 for (cur = start, i = 0; i < slicelen; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1523 cur += step, i++) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1524 PyList_SET_ITEM(recycle, i, self->extra->children[cur]); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1525 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1526 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1527 if (newlen < slicelen) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1528 /* delete slice */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1529 for (i = stop; i < self->extra->length; i++) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1530 self->extra->children[i + newlen - slicelen] = self->extra->children[i]; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1531 } else if (newlen > slicelen) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1532 /* insert slice */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1533 for (i = self->extra->length-1; i >= stop; i--) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1534 self->extra->children[i + newlen - slicelen] = self->extra->children[i]; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1535 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1536 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1537 /* replace the slice */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1538 for (cur = start, i = 0; i < newlen; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1539 cur += step, i++) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1540 PyObject* element = PySequence_Fast_GET_ITEM(seq, i); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1541 Py_INCREF(element); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1542 self->extra->children[cur] = element; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1543 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1544 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1545 self->extra->length += newlen - slicelen; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1546 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1547 if (seq) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1548 Py_DECREF(seq); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1549 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1550 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1551 /* discard the recycle bin, and everything in it */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1552 Py_XDECREF(recycle); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1553 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1554 return 0; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1555 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1556 else { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1557 PyErr_SetString(PyExc_TypeError, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1558 "element indices must be integers"); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1559 return -1; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1560 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1561 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1562 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1563 static PyMethodDef element_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1564 |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
1565 {"clear", (PyCFunction) element_clearmethod, METH_VARARGS}, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1566 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1567 {"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
|
1568 {"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
|
1569 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1570 {"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
|
1571 {"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
|
1572 {"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
|
1573 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1574 {"append", (PyCFunction) element_append, METH_VARARGS}, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1575 {"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
|
1576 {"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
|
1577 {"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
|
1578 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1579 {"iter", (PyCFunction) element_iter, METH_VARARGS}, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1580 {"itertext", (PyCFunction) element_itertext, METH_VARARGS}, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1581 {"iterfind", (PyCFunction) element_iterfind, METH_VARARGS}, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1582 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1583 {"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
|
1584 {"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
|
1585 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1586 {"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
|
1587 {"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
|
1588 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1589 {"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
|
1590 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1591 {"__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
|
1592 {"__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
|
1593 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1594 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1595 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1596 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1597 static PyObject* |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1598 element_getattro(ElementObject* self, PyObject* nameobj) |
|
36050
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 PyObject* res; |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1601 char *name = ""; |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1602 |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
1603 if (PyUnicode_Check(nameobj)) |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1604 name = _PyUnicode_AsString(nameobj); |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
1605 |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
1606 if (name == NULL) |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
1607 return NULL; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1608 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1609 /* handle common attributes first */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1610 if (strcmp(name, "tag") == 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1611 res = self->tag; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1612 Py_INCREF(res); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1613 return res; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1614 } else if (strcmp(name, "text") == 0) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1615 res = element_get_text(self); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1616 Py_INCREF(res); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1617 return res; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1618 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1619 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1620 /* methods */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1621 res = PyObject_GenericGetAttr((PyObject*) self, nameobj); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1622 if (res) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1623 return res; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1624 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1625 /* less common attributes */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1626 if (strcmp(name, "tail") == 0) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1627 PyErr_Clear(); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1628 res = element_get_tail(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1629 } else if (strcmp(name, "attrib") == 0) { |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1630 PyErr_Clear(); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1631 if (!self->extra) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1632 create_extra(self, NULL); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1633 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
|
1634 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1635 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1636 if (!res) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1637 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1638 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1639 Py_INCREF(res); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1640 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1641 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1642 |
|
77062
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1643 static PyObject* |
|
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1644 element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1645 { |
|
77062
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1646 char *name = ""; |
|
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1647 if (PyUnicode_Check(nameobj)) |
|
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1648 name = _PyUnicode_AsString(nameobj); |
|
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1649 |
|
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1650 if (name == NULL) |
|
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1651 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1652 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1653 if (strcmp(name, "tag") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1654 Py_DECREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1655 self->tag = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1656 Py_INCREF(self->tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1657 } 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
|
1658 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
|
1659 self->text = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1660 Py_INCREF(self->text); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1661 } 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
|
1662 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
|
1663 self->tail = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1664 Py_INCREF(self->tail); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1665 } 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
|
1666 if (!self->extra) |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1667 create_extra(self, NULL); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1668 Py_DECREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1669 self->extra->attrib = value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1670 Py_INCREF(self->extra->attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1671 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1672 PyErr_SetString(PyExc_AttributeError, name); |
|
77062
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1673 return NULL; |
|
36050
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 |
|
77062
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1676 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1677 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1678 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1679 static PySequenceMethods element_as_sequence = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1680 (lenfunc) element_length, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1681 0, /* sq_concat */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1682 0, /* sq_repeat */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1683 element_getitem, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1684 0, |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36450
diff
changeset
|
1685 element_setitem, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1686 0, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1687 }; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1688 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1689 static PyMappingMethods element_as_mapping = { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1690 (lenfunc) element_length, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1691 (binaryfunc) element_subscr, |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1692 (objobjargproc) element_ass_subscr, |
|
36050
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 |
|
37144
91dd4d44d3bc
Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
1695 static PyTypeObject Element_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
1696 PyVarObject_HEAD_INIT(NULL, 0) |
|
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
1697 "Element", sizeof(ElementObject), 0, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1698 /* methods */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1699 (destructor)element_dealloc, /* tp_dealloc */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1700 0, /* tp_print */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1701 0, /* tp_getattr */ |
|
77062
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1702 0, /* tp_setattr */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1703 0, /* tp_reserved */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1704 (reprfunc)element_repr, /* tp_repr */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1705 0, /* tp_as_number */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1706 &element_as_sequence, /* tp_as_sequence */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1707 &element_as_mapping, /* tp_as_mapping */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1708 0, /* tp_hash */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1709 0, /* tp_call */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1710 0, /* tp_str */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1711 (getattrofunc)element_getattro, /* tp_getattro */ |
|
77062
41a9d24d075e
Issue #14849: setup Element data members to be assignable in subclasses
Eli Bendersky <eliben@gmail.com>
parents:
76110
diff
changeset
|
1712 (setattrofunc)element_setattro, /* tp_setattro */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1713 0, /* tp_as_buffer */ |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
1714 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
1715 /* tp_flags */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1716 0, /* tp_doc */ |
|
75997
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
1717 (traverseproc)element_gc_traverse, /* tp_traverse */ |
|
0ca32013d77e
Issue #14065: Added cyclic GC support to ET.Element
Eli Bendersky <eliben@gmail.com>
parents:
75894
diff
changeset
|
1718 (inquiry)element_gc_clear, /* tp_clear */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1719 0, /* tp_richcompare */ |
|
76098
14abfa27ff19
Fixes and enhancements to _elementtree:
Eli Bendersky <eliben@gmail.com>
parents:
75997
diff
changeset
|
1720 offsetof(ElementObject, weakreflist), /* tp_weaklistoffset */ |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1721 0, /* tp_iter */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1722 0, /* tp_iternext */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1723 element_methods, /* tp_methods */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1724 0, /* tp_members */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1725 0, /* tp_getset */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1726 0, /* tp_base */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1727 0, /* tp_dict */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1728 0, /* tp_descr_get */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1729 0, /* tp_descr_set */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1730 0, /* tp_dictoffset */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1731 (initproc)element_init, /* tp_init */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1732 PyType_GenericAlloc, /* tp_alloc */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1733 element_new, /* tp_new */ |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1734 0, /* tp_free */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1735 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1736 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1737 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1738 /* the tree builder type */ |
|
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 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1741 PyObject_HEAD |
|
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 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
|
1744 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1745 ElementObject* this; /* current node */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1746 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
|
1747 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1748 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
|
1749 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1750 PyObject* stack; /* element stack */ |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1751 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
|
1752 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1753 /* element tracing */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1754 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
|
1755 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
|
1756 PyObject* end_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1757 PyObject* start_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1758 PyObject* end_ns_event_obj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1759 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1760 } TreeBuilderObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1761 |
|
37144
91dd4d44d3bc
Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
1762 static PyTypeObject TreeBuilder_Type; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1763 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
1764 #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
|
1765 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1766 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1767 /* constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1768 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1769 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1770 treebuilder_new(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1771 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1772 TreeBuilderObject* self; |
|
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 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
|
1775 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1776 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1777 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1778 self->root = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1779 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1780 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1781 self->this = (ElementObject*) Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1782 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1783 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1784 self->last = (ElementObject*) Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1785 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1786 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1787 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1788 self->stack = PyList_New(20); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1789 self->index = 0; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1790 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1791 self->events = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1792 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
|
1793 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
|
1794 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1795 ALLOC(sizeof(TreeBuilderObject), "create treebuilder"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1796 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1797 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1798 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1799 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1800 static PyObject* |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1801 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
|
1802 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1803 if (!PyArg_ParseTuple(args, ":TreeBuilder")) |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1806 return treebuilder_new(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1807 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1808 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1809 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1810 treebuilder_dealloc(TreeBuilderObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1811 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1812 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
|
1813 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
|
1814 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
|
1815 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
|
1816 Py_XDECREF(self->events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1817 Py_DECREF(self->stack); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1818 Py_XDECREF(self->data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1819 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1820 Py_DECREF(self->this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1821 Py_XDECREF(self->root); |
|
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 RELEASE(sizeof(TreeBuilderObject), "destroy treebuilder"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1824 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1825 PyObject_Del(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1826 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1827 |
|
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 /* handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1830 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1831 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1832 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
|
1833 PyObject* attrib) |
|
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 PyObject* node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1836 PyObject* this; |
|
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->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1839 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
|
1840 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
|
1841 self->last->text = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1842 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
|
1843 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1844 } else { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1845 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
|
1846 self->last->tail = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1847 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
|
1848 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1849 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1850 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1851 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1852 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
1853 node = create_new_element(tag, attrib); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1854 if (!node) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1855 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1856 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1857 this = (PyObject*) self->this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1858 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1859 if (this != Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1860 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
|
1861 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1862 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1863 if (self->root) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1864 PyErr_SetString( |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
1865 elementtree_parseerror_obj, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1866 "multiple elements on top level" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1867 ); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1868 goto error; |
|
36050
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(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1871 self->root = node; |
|
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 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
|
1875 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
|
1876 goto error; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1877 Py_INCREF(this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1878 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1879 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
|
1880 goto error; |
|
36050
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 self->index++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1883 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1884 Py_DECREF(this); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1885 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1886 self->this = (ElementObject*) node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1887 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1888 Py_DECREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1889 Py_INCREF(node); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1890 self->last = (ElementObject*) node; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1891 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1892 if (self->start_event_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1893 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1894 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
|
1895 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1896 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1897 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
|
1898 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
|
1899 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1900 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1901 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1902 PyErr_Clear(); /* FIXME: propagate error */ |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1905 return node; |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1906 |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1907 error: |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1908 Py_DECREF(node); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1909 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1910 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1911 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1912 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1913 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
|
1914 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1915 if (!self->data) { |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1916 if (self->last == (ElementObject*) Py_None) { |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1917 /* ignore calls to data before the first call to start */ |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1918 Py_RETURN_NONE; |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
1919 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1920 /* 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
|
1921 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
|
1922 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1923 /* more than one item; use a list to collect items */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1924 if (PyBytes_CheckExact(self->data) && Py_REFCNT(self->data) == 1 && |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1925 PyBytes_CheckExact(data) && PyBytes_GET_SIZE(data) == 1) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1926 /* 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
|
1927 the most common case by resizing the existing string... */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1928 Py_ssize_t size = PyBytes_GET_SIZE(self->data); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1929 if (_PyBytes_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
|
1930 return NULL; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1931 PyBytes_AS_STRING(self->data)[size] = PyBytes_AS_STRING(data)[0]; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1932 } 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
|
1933 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
|
1934 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1935 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1936 PyObject* list = PyList_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1937 if (!list) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1938 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1939 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
|
1940 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
|
1941 self->data = list; |
|
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 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1944 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1945 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1946 } |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1949 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
|
1950 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1951 PyObject* item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1952 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1953 if (self->data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1954 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
|
1955 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
|
1956 self->last->text = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1957 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
|
1958 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1959 } else { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
1960 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
|
1961 self->last->tail = JOIN_SET( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1962 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
|
1963 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1964 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1965 self->data = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1966 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1967 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1968 if (self->index == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1969 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1970 PyExc_IndexError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1971 "pop from empty stack" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1972 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1973 return NULL; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1976 self->index--; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1977 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1978 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
|
1979 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1980 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1981 Py_DECREF(self->last); |
|
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 self->last = (ElementObject*) self->this; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1984 self->this = (ElementObject*) item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1985 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1986 if (self->end_event_obj) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1987 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1988 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
|
1989 PyObject* node = (PyObject*) self->last; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1990 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1991 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1992 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
|
1993 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
|
1994 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1995 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1996 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1997 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1998 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1999 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2000 Py_INCREF(self->last); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2001 return (PyObject*) self->last; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2002 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2003 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2004 LOCAL(void) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2005 treebuilder_handle_namespace(TreeBuilderObject* self, int start, |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2006 PyObject *prefix, PyObject *uri) |
|
36050
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 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2009 PyObject* action; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2010 PyObject* parcel; |
|
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 if (!self->events) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2013 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2014 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2015 if (start) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2016 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
|
2017 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2018 action = self->start_ns_event_obj; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2019 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
|
2020 if (!parcel) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2021 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2022 Py_INCREF(action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2023 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2024 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
|
2025 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2026 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
|
2027 Py_INCREF(action); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2028 parcel = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2029 Py_INCREF(parcel); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2030 } |
|
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 res = PyTuple_New(2); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2033 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2034 if (res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2035 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
|
2036 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
|
2037 PyList_Append(self->events, res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2038 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2039 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2040 PyErr_Clear(); /* FIXME: propagate error */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2041 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2042 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2043 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2044 /* methods (in alphabetical order) */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2045 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2046 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2047 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
|
2048 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2049 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2050 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
|
2051 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2052 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2053 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
|
2054 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2055 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2056 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2057 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
|
2058 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2059 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2060 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
|
2061 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2062 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2063 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
|
2064 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2065 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2066 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2067 treebuilder_done(TreeBuilderObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2068 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2069 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2070 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2071 /* FIXME: check stack size? */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2072 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2073 if (self->root) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2074 res = self->root; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2075 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2076 res = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2077 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2078 Py_INCREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2079 return res; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2082 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2083 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
|
2084 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2085 if (!PyArg_ParseTuple(args, ":close")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2086 return NULL; |
|
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 return treebuilder_done(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2089 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2090 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2091 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2092 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
|
2093 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2094 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2095 PyObject* attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2096 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
|
2097 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2098 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2099 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
|
2100 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2101 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2102 static PyMethodDef treebuilder_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2103 {"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
|
2104 {"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
|
2105 {"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
|
2106 {"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
|
2107 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2108 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2109 |
|
37144
91dd4d44d3bc
Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
2110 static PyTypeObject TreeBuilder_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
2111 PyVarObject_HEAD_INIT(NULL, 0) |
|
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
2112 "TreeBuilder", sizeof(TreeBuilderObject), 0, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2113 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2114 (destructor)treebuilder_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2115 0, /* tp_print */ |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2116 0, /* tp_getattr */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2117 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
51244
diff
changeset
|
2118 0, /* tp_reserved */ |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2119 0, /* tp_repr */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2120 0, /* tp_as_number */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2121 0, /* tp_as_sequence */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2122 0, /* tp_as_mapping */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2123 0, /* tp_hash */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2124 0, /* tp_call */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2125 0, /* tp_str */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2126 0, /* tp_getattro */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2127 0, /* tp_setattro */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2128 0, /* tp_as_buffer */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2129 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2130 0, /* tp_doc */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2131 0, /* tp_traverse */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2132 0, /* tp_clear */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2133 0, /* tp_richcompare */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2134 0, /* tp_weaklistoffset */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2135 0, /* tp_iter */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2136 0, /* tp_iternext */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2137 treebuilder_methods, /* tp_methods */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2138 0, /* tp_members */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2139 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2140 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2141 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2142 /* the expat interface */ |
|
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 #if defined(USE_EXPAT) |
|
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 #include "expat.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2147 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2148 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2149 #include "pyexpat.h" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2150 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
|
2151 #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
|
2152 #else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2153 #define EXPAT(func) (XML_##func) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2154 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2155 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2156 typedef struct { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2157 PyObject_HEAD |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2158 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2159 XML_Parser parser; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2160 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2161 PyObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2162 PyObject* entity; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2163 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2164 PyObject* names; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2165 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2166 PyObject* handle_start; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2167 PyObject* handle_data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2168 PyObject* handle_end; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2169 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2170 PyObject* handle_comment; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2171 PyObject* handle_pi; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2172 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2173 PyObject* handle_close; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2174 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2175 } XMLParserObject; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2176 |
|
37144
91dd4d44d3bc
Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
2177 static PyTypeObject XMLParser_Type; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2178 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2179 /* helpers */ |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2182 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
|
2183 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2184 /* 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
|
2185 to a universal name string */ |
|
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 int size = strlen(string); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2188 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2189 PyObject* value; |
|
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 /* look the 'raw' name up in the names dictionary */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
2192 key = PyBytes_FromStringAndSize(string, size); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2193 if (!key) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2194 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2195 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2196 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
|
2197 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2198 if (value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2199 Py_INCREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2200 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2201 /* 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
|
2202 necessary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2203 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2204 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2205 char* p; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2206 int i; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2207 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2208 /* look for namespace separator */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2209 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
|
2210 if (string[i] == '}') |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2211 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2212 if (i != size) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2213 /* convert to universal name */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
2214 tag = PyBytes_FromStringAndSize(NULL, size+1); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
2215 p = PyBytes_AS_STRING(tag); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2216 p[0] = '{'; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2217 memcpy(p+1, string, size); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2218 size++; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2219 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2220 /* 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
|
2221 Py_INCREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2222 tag = key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2223 } |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
2224 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2225 /* decode universal name */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
2226 p = PyBytes_AS_STRING(tag); |
|
42491
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2227 value = PyUnicode_DecodeUTF8(p, size, "strict"); |
|
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2228 Py_DECREF(tag); |
|
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2229 if (!value) { |
|
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2230 Py_DECREF(key); |
|
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2231 return NULL; |
|
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2232 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2233 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2234 /* add to names dictionary */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2235 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
|
2236 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2237 Py_DECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2238 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2239 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2240 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2241 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2242 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2243 return value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2244 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2245 |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2246 /* Set the ParseError exception with the given parameters. |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2247 * If message is not NULL, it's used as the error string. Otherwise, the |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2248 * message string is the default for the given error_code. |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2249 */ |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2250 static void |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2251 expat_set_error(enum XML_Error error_code, int line, int column, char *message) |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2252 { |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2253 PyObject *errmsg, *error, *position, *code; |
|
68805
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2254 |
|
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2255 errmsg = PyUnicode_FromFormat("%s: line %d, column %d", |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2256 message ? message : EXPAT(ErrorString)(error_code), |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2257 line, column); |
|
68805
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2258 if (errmsg == NULL) |
|
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2259 return; |
|
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2260 |
|
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2261 error = PyObject_CallFunction(elementtree_parseerror_obj, "O", errmsg); |
|
74d3dc78f0db
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68804
diff
changeset
|
2262 Py_DECREF(errmsg); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2263 if (!error) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2264 return; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2265 |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2266 /* Add code and position attributes */ |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2267 code = PyLong_FromLong((long)error_code); |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2268 if (!code) { |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2269 Py_DECREF(error); |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2270 return; |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2271 } |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2272 if (PyObject_SetAttrString(error, "code", code) == -1) { |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2273 Py_DECREF(error); |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2274 Py_DECREF(code); |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2275 return; |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2276 } |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2277 Py_DECREF(code); |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2278 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2279 position = Py_BuildValue("(ii)", line, column); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2280 if (!position) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2281 Py_DECREF(error); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2282 return; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2283 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2284 if (PyObject_SetAttrString(error, "position", position) == -1) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2285 Py_DECREF(error); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2286 Py_DECREF(position); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2287 return; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2288 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2289 Py_DECREF(position); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2290 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2291 PyErr_SetObject(elementtree_parseerror_obj, error); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2292 Py_DECREF(error); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2293 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2294 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2295 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2296 /* handlers */ |
|
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 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2299 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
|
2300 int data_len) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2301 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2302 PyObject* key; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2303 PyObject* value; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2304 PyObject* res; |
|
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 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
|
2307 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2308 |
|
42491
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2309 key = PyUnicode_DecodeUTF8(data_in + 1, data_len - 2, "strict"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2310 if (!key) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2311 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2312 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2313 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
|
2314 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2315 if (value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2316 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2317 res = treebuilder_handle_data( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2318 (TreeBuilderObject*) self->target, value |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2319 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2320 else if (self->handle_data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2321 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
|
2322 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2323 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2324 Py_XDECREF(res); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2325 } else if (!PyErr_Occurred()) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2326 /* Report the first error, not the last */ |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2327 char message[128] = "undefined entity "; |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2328 strncat(message, data_in, data_len < 100?data_len:100); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2329 expat_set_error( |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2330 XML_ERROR_UNDEFINED_ENTITY, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2331 EXPAT(GetErrorLineNumber)(self->parser), |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2332 EXPAT(GetErrorColumnNumber)(self->parser), |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2333 message |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2334 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2335 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2336 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2337 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2338 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2339 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2340 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2341 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
|
2342 const XML_Char **attrib_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2343 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2344 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2345 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2346 PyObject* attrib; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2347 int ok; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2348 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2349 /* tag name */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2350 tag = makeuniversal(self, tag_in); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2351 if (!tag) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2352 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
|
2353 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2354 /* attributes */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2355 if (attrib_in[0]) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2356 attrib = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2357 if (!attrib) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2358 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2359 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
|
2360 PyObject* key = makeuniversal(self, attrib_in[0]); |
|
42491
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2361 PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2362 if (!key || !value) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2363 Py_XDECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2364 Py_XDECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2365 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2366 return; |
|
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 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
|
2369 Py_DECREF(value); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2370 Py_DECREF(key); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2371 if (ok < 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2372 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2373 return; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2374 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2375 attrib_in += 2; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2376 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2377 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2378 Py_INCREF(Py_None); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2379 attrib = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2380 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2381 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2382 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2383 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2384 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
|
2385 tag, attrib); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2386 else if (self->handle_start) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2387 if (attrib == Py_None) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2388 Py_DECREF(attrib); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2389 attrib = PyDict_New(); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2390 if (!attrib) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2391 return; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2392 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2393 res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2394 } else |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2395 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2396 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2397 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2398 Py_DECREF(attrib); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2399 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2400 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2401 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2402 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2403 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2404 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
|
2405 int data_len) |
|
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 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2408 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2409 |
|
42491
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2410 data = PyUnicode_DecodeUTF8(data_in, data_len, "strict"); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2411 if (!data) |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2412 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
|
2413 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2414 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2415 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2416 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
|
2417 else if (self->handle_data) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2418 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
|
2419 else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2420 res = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2421 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2422 Py_DECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2423 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2424 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2425 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2426 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2427 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2428 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
|
2429 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2430 PyObject* tag; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2431 PyObject* res = NULL; |
|
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 if (TreeBuilder_CheckExact(self->target)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2434 /* shortcut */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2435 /* 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
|
2436 res = treebuilder_handle_end( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2437 (TreeBuilderObject*) self->target, Py_None |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2438 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2439 else if (self->handle_end) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2440 tag = makeuniversal(self, tag_in); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2441 if (tag) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2442 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
|
2443 Py_DECREF(tag); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2444 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2445 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2446 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2447 Py_XDECREF(res); |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2450 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2451 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
|
2452 const XML_Char *uri) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2453 { |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2454 PyObject* sprefix = NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2455 PyObject* suri = NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2456 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2457 suri = PyUnicode_DecodeUTF8(uri, strlen(uri), "strict"); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2458 if (!suri) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2459 return; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2460 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2461 if (prefix) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2462 sprefix = PyUnicode_DecodeUTF8(prefix, strlen(prefix), "strict"); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2463 else |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2464 sprefix = PyUnicode_FromString(""); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2465 if (!sprefix) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2466 Py_DECREF(suri); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2467 return; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2468 } |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2469 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2470 treebuilder_handle_namespace( |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2471 (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
|
2472 ); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2473 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2474 Py_DECREF(sprefix); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2475 Py_DECREF(suri); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2476 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2477 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2478 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2479 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
|
2480 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2481 treebuilder_handle_namespace( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2482 (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
|
2483 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2484 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2485 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2486 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2487 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
|
2488 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2489 PyObject* comment; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2490 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2491 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2492 if (self->handle_comment) { |
|
42491
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2493 comment = PyUnicode_DecodeUTF8(comment_in, strlen(comment_in), "strict"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2494 if (comment) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2495 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
|
2496 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2497 Py_DECREF(comment); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2498 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2499 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2500 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2501 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2502 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2503 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
|
2504 const XML_Char* data_in) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2505 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2506 PyObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2507 PyObject* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2508 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2509 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2510 if (self->handle_pi) { |
|
42491
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2511 target = PyUnicode_DecodeUTF8(target_in, strlen(target_in), "strict"); |
|
a8f13a43eaa1
SF patch # 1769767, get test_xml_etree_c working. More conversions are probably needed.
Neal Norwitz <nnorwitz@gmail.com>
parents:
42334
diff
changeset
|
2512 data = PyUnicode_DecodeUTF8(data_in, strlen(data_in), "strict"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2513 if (target && data) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2514 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
|
2515 Py_XDECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2516 Py_DECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2517 Py_DECREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2518 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2519 Py_XDECREF(data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2520 Py_XDECREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2521 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2522 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2523 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2524 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2525 static int |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2526 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
|
2527 XML_Encoding *info) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2528 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2529 PyObject* u; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2530 unsigned char s[256]; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2531 int i; |
| 72475 | 2532 void *data; |
| 2533 unsigned int kind; | |
|
36050
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 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
|
2536 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2537 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
|
2538 s[i] = i; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
2539 |
| 36117 | 2540 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
|
2541 if (!u) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2542 return XML_STATUS_ERROR; |
| 72475 | 2543 if (PyUnicode_READY(u)) |
| 2544 return XML_STATUS_ERROR; | |
| 2545 | |
| 2546 if (PyUnicode_GET_LENGTH(u) != 256) { | |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2547 Py_DECREF(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2548 return XML_STATUS_ERROR; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2549 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2550 |
| 72475 | 2551 kind = PyUnicode_KIND(u); |
| 2552 data = PyUnicode_DATA(u); | |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2553 for (i = 0; i < 256; i++) { |
| 72475 | 2554 Py_UCS4 ch = PyUnicode_READ(kind, data, i); |
| 2555 if (ch != Py_UNICODE_REPLACEMENT_CHARACTER) | |
| 2556 info->map[i] = ch; | |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2557 else |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2558 info->map[i] = -1; |
|
36050
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2561 Py_DECREF(u); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2562 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2563 return XML_STATUS_OK; |
|
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2566 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2567 /* constructor and destructor */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2568 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2569 static PyObject* |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
2570 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
|
2571 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2572 XMLParserObject* self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2573 /* 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
|
2574 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
|
2575 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2576 PyObject* target = NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2577 char* encoding = NULL; |
| 36684 | 2578 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
|
2579 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
|
2580 &target, &encoding)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2581 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2582 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2583 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2584 if (!expat_capi) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2585 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2586 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
|
2587 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2588 return NULL; |
|
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 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2591 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2592 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
|
2593 if (self == NULL) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2594 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2595 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2596 self->entity = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2597 if (!self->entity) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2598 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2599 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2600 } |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
2601 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2602 self->names = PyDict_New(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2603 if (!self->names) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2604 PyObject_Del(self->entity); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2605 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2606 return NULL; |
|
36050
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 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
|
2610 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
|
2611 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
|
2612 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2613 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
|
2614 if (!self->parser) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2615 PyObject_Del(self->names); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2616 PyObject_Del(self->entity); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2617 PyObject_Del(self); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2618 PyErr_NoMemory(); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2619 return NULL; |
|
36050
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2622 /* setup target handlers */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2623 if (!target) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2624 target = treebuilder_new(); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2625 if (!target) { |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2626 EXPAT(ParserFree)(self->parser); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2627 PyObject_Del(self->names); |
|
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2628 PyObject_Del(self->entity); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2629 PyObject_Del(self); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
2630 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2631 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2632 } else |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2633 Py_INCREF(target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2634 self->target = target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2635 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2636 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
|
2637 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
|
2638 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
|
2639 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
|
2640 self->handle_pi = PyObject_GetAttrString(target, "pi"); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2641 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
|
2642 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2643 PyErr_Clear(); |
|
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 /* configure parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2646 EXPAT(SetUserData)(self->parser, self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2647 EXPAT(SetElementHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2648 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2649 (XML_StartElementHandler) expat_start_handler, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2650 (XML_EndElementHandler) expat_end_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2651 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2652 EXPAT(SetDefaultHandlerExpand)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2653 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2654 (XML_DefaultHandler) expat_default_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2655 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2656 EXPAT(SetCharacterDataHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2657 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2658 (XML_CharacterDataHandler) expat_data_handler |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2659 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2660 if (self->handle_comment) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2661 EXPAT(SetCommentHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2662 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2663 (XML_CommentHandler) expat_comment_handler |
|
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 if (self->handle_pi) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2666 EXPAT(SetProcessingInstructionHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2667 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2668 (XML_ProcessingInstructionHandler) expat_pi_handler |
|
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 EXPAT(SetUnknownEncodingHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2671 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2672 (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
|
2673 ); |
|
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 ALLOC(sizeof(XMLParserObject), "create expatparser"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2676 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2677 return (PyObject*) self; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2678 } |
|
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 static void |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2681 xmlparser_dealloc(XMLParserObject* self) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2682 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2683 EXPAT(ParserFree)(self->parser); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2684 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2685 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
|
2686 Py_XDECREF(self->handle_pi); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2687 Py_XDECREF(self->handle_comment); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2688 Py_XDECREF(self->handle_end); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2689 Py_XDECREF(self->handle_data); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2690 Py_XDECREF(self->handle_start); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2691 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2692 Py_DECREF(self->target); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2693 Py_DECREF(self->entity); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2694 Py_DECREF(self->names); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2695 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2696 RELEASE(sizeof(XMLParserObject), "destroy expatparser"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2697 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2698 PyObject_Del(self); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2699 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2700 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2701 /* -------------------------------------------------------------------- */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2702 /* methods (in alphabetical order) */ |
|
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 LOCAL(PyObject*) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2705 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
|
2706 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2707 int ok; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2708 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2709 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
|
2710 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2711 if (PyErr_Occurred()) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2712 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2713 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2714 if (!ok) { |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2715 expat_set_error( |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2716 EXPAT(GetErrorCode)(self->parser), |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2717 EXPAT(GetErrorLineNumber)(self->parser), |
|
75722
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2718 EXPAT(GetErrorColumnNumber)(self->parser), |
|
b76fa310e73d
Issue #14207: the ParseError exception raised by _elementtree was made
Eli Bendersky <eliben@gmail.com>
parents:
75721
diff
changeset
|
2719 NULL |
|
36050
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 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2722 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2723 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2724 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2725 } |
|
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 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2728 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
|
2729 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2730 /* end feeding data to parser */ |
|
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 PyObject* res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2733 if (!PyArg_ParseTuple(args, ":close")) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2734 return NULL; |
|
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 res = expat_parse(self, "", 0, 1); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2737 if (!res) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2738 return NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2739 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2740 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
|
2741 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2742 return treebuilder_done((TreeBuilderObject*) self->target); |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2743 } if (self->handle_close) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2744 Py_DECREF(res); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2745 return PyObject_CallFunction(self->handle_close, ""); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2746 } else |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2747 return res; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2748 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2749 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2750 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2751 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
|
2752 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2753 /* feed data to parser */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2754 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2755 char* data; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2756 int data_len; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2757 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
|
2758 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2759 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2760 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
|
2761 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2762 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2763 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2764 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
|
2765 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2766 /* (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
|
2767 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2768 PyObject* reader; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2769 PyObject* buffer; |
|
75721
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2770 PyObject* temp; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2771 PyObject* res; |
|
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 PyObject* fileobj; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2774 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
|
2775 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2776 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2777 reader = PyObject_GetAttrString(fileobj, "read"); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2778 if (!reader) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2779 return NULL; |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
2780 |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2781 /* read from open file object */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2782 for (;;) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2783 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2784 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
|
2785 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2786 if (!buffer) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2787 /* 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
|
2788 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2789 return NULL; |
|
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 |
|
75721
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2792 if (PyUnicode_CheckExact(buffer)) { |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2793 /* A unicode object is encoded into bytes using UTF-8 */ |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2794 if (PyUnicode_GET_SIZE(buffer) == 0) { |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2795 Py_DECREF(buffer); |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2796 break; |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2797 } |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2798 temp = PyUnicode_AsEncodedString(buffer, "utf-8", "surrogatepass"); |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2799 if (!temp) { |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2800 /* Propagate exception from PyUnicode_AsEncodedString */ |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2801 Py_DECREF(buffer); |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2802 Py_DECREF(reader); |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2803 return NULL; |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2804 } |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2805 |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2806 /* Here we no longer need the original buffer since it contains |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2807 * unicode. Make it point to the encoded bytes object. |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2808 */ |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2809 Py_DECREF(buffer); |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2810 buffer = temp; |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2811 } |
|
7bdf5c96fdc0
Closes Issue #14246: _elementtree parser will now handle io.StringIO
Eli Bendersky <eliben@gmail.com>
parents:
75505
diff
changeset
|
2812 else if (!PyBytes_CheckExact(buffer) || PyBytes_GET_SIZE(buffer) == 0) { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2813 Py_DECREF(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2814 break; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2815 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2816 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2817 res = expat_parse( |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
2818 self, PyBytes_AS_STRING(buffer), PyBytes_GET_SIZE(buffer), 0 |
|
36050
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 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2821 Py_DECREF(buffer); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2822 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2823 if (!res) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2824 Py_DECREF(reader); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2825 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2826 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2827 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2828 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2829 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2830 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2831 Py_DECREF(reader); |
|
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 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
|
2834 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2835 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
|
2836 Py_DECREF(res); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2837 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
|
2838 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2839 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2840 return res; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2841 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2842 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2843 static PyObject* |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2844 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
|
2845 { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2846 /* activate element event reporting */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2847 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
2848 Py_ssize_t i; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2849 TreeBuilderObject* target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2850 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2851 PyObject* events; /* event collector */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2852 PyObject* event_set = Py_None; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2853 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
|
2854 &event_set)) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2855 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2856 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2857 if (!TreeBuilder_CheckExact(self->target)) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2858 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2859 PyExc_TypeError, |
|
74903
65fc79fb4eb2
Issue #13988: cElementTree is deprecated and the _elementtree accelerator is automatically used whenever available.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
74870
diff
changeset
|
2860 "event handling only supported for ElementTree.TreeBuilder " |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2861 "targets" |
|
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 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2864 } |
|
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 target = (TreeBuilderObject*) self->target; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2867 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2868 Py_INCREF(events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2869 Py_XDECREF(target->events); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2870 target->events = events; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2871 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2872 /* clear out existing events */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2873 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
|
2874 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
|
2875 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
|
2876 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
|
2877 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2878 if (event_set == Py_None) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2879 /* default is "end" only */ |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2880 target->end_event_obj = PyUnicode_FromString("end"); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2881 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2882 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2883 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2884 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
|
2885 goto error; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2886 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2887 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
|
2888 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
|
2889 char* event; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2890 if (PyUnicode_Check(item)) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2891 event = _PyUnicode_AsString(item); |
|
59893
2d6178480cc7
Fix a crash in _elementtree related to lone unicode surrogates.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59601
diff
changeset
|
2892 if (event == NULL) |
|
2d6178480cc7
Fix a crash in _elementtree related to lone unicode surrogates.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59601
diff
changeset
|
2893 goto error; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2894 } else if (PyBytes_Check(item)) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2895 event = PyBytes_AS_STRING(item); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2896 else { |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2897 goto error; |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
2898 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2899 if (strcmp(event, "start") == 0) { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2900 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2901 target->start_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2902 } 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
|
2903 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2904 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
|
2905 target->end_event_obj = item; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2906 } 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
|
2907 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2908 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
|
2909 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
|
2910 EXPAT(SetNamespaceDeclHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2911 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2912 (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
|
2913 (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
|
2914 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2915 } 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
|
2916 Py_INCREF(item); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2917 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
|
2918 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
|
2919 EXPAT(SetNamespaceDeclHandler)( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2920 self->parser, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2921 (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
|
2922 (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
|
2923 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2924 } else { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2925 PyErr_Format( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2926 PyExc_ValueError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2927 "unknown event '%s'", event |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2928 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2929 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2930 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2931 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2932 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2933 Py_RETURN_NONE; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2934 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2935 error: |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2936 PyErr_SetString( |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2937 PyExc_TypeError, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2938 "invalid event tuple" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2939 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2940 return NULL; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2941 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2942 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2943 static PyMethodDef xmlparser_methods[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2944 {"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
|
2945 {"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
|
2946 {"_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
|
2947 {"_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
|
2948 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2949 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2950 |
|
68804
d0fe7489c4cc
_elementtree.c: remove trailing spaces
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
2951 static PyObject* |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2952 xmlparser_getattro(XMLParserObject* self, PyObject* nameobj) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2953 { |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2954 if (PyUnicode_Check(nameobj)) { |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2955 PyObject* res; |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2956 if (PyUnicode_CompareWithASCIIString(nameobj, "entity") == 0) |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2957 res = self->entity; |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2958 else if (PyUnicode_CompareWithASCIIString(nameobj, "target") == 0) |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2959 res = self->target; |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2960 else if (PyUnicode_CompareWithASCIIString(nameobj, "version") == 0) { |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2961 return PyUnicode_FromFormat( |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2962 "Expat %d.%d.%d", XML_MAJOR_VERSION, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2963 XML_MINOR_VERSION, XML_MICRO_VERSION); |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2964 } |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2965 else |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2966 goto generic; |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2967 |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2968 Py_INCREF(res); |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2969 return res; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2970 } |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2971 generic: |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66664
diff
changeset
|
2972 return PyObject_GenericGetAttr((PyObject*) self, nameobj); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2973 } |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2974 |
|
37144
91dd4d44d3bc
Finish getting rid of statichere/staticforward
Neal Norwitz <nnorwitz@gmail.com>
parents:
36954
diff
changeset
|
2975 static PyTypeObject XMLParser_Type = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
2976 PyVarObject_HEAD_INIT(NULL, 0) |
|
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
41782
diff
changeset
|
2977 "XMLParser", sizeof(XMLParserObject), 0, |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2978 /* methods */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2979 (destructor)xmlparser_dealloc, /* tp_dealloc */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2980 0, /* tp_print */ |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2981 0, /* tp_getattr */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2982 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
51244
diff
changeset
|
2983 0, /* tp_reserved */ |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2984 0, /* tp_repr */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2985 0, /* tp_as_number */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2986 0, /* tp_as_sequence */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2987 0, /* tp_as_mapping */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2988 0, /* tp_hash */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2989 0, /* tp_call */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2990 0, /* tp_str */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2991 (getattrofunc)xmlparser_getattro, /* tp_getattro */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2992 0, /* tp_setattro */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2993 0, /* tp_as_buffer */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2994 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2995 0, /* tp_doc */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2996 0, /* tp_traverse */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2997 0, /* tp_clear */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2998 0, /* tp_richcompare */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
2999 0, /* tp_weaklistoffset */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3000 0, /* tp_iter */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3001 0, /* tp_iternext */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3002 xmlparser_methods, /* tp_methods */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3003 0, /* tp_members */ |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3004 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3005 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3006 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3007 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3008 /* ==================================================================== */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3009 /* python module interface */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3010 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3011 static PyMethodDef _functions[] = { |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3012 {"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
|
3013 {"TreeBuilder", (PyCFunction) treebuilder, METH_VARARGS}, |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3014 #if defined(USE_EXPAT) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3015 {"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
|
3016 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3017 {NULL, NULL} |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3018 }; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3019 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3020 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3021 static struct PyModuleDef _elementtreemodule = { |
|
63924
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3022 PyModuleDef_HEAD_INIT, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3023 "_elementtree", |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3024 NULL, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3025 -1, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3026 _functions, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3027 NULL, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3028 NULL, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3029 NULL, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3030 NULL |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3031 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3032 |
| 40528 | 3033 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3034 PyInit__elementtree(void) |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3035 { |
|
76110
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3036 PyObject *m, *g, *temp; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3037 char* bootstrap; |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3038 |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3039 /* Initialize object types */ |
|
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3040 if (PyType_Ready(&TreeBuilder_Type) < 0) |
|
63924
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3041 return NULL; |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3042 if (PyType_Ready(&Element_Type) < 0) |
|
63924
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3043 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3044 #if defined(USE_EXPAT) |
|
48414
4025f638911f
#3247: Get rid of Py_FindMethod:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
3045 if (PyType_Ready(&XMLParser_Type) < 0) |
|
63924
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3046 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3047 #endif |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3048 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3049 m = PyModule_Create(&_elementtreemodule); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
3050 if (!m) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3051 return NULL; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3052 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3053 /* The code below requires that the module gets already added |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3054 to sys.modules. */ |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3055 PyDict_SetItemString(PyImport_GetModuleDict(), |
|
63924
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3056 _elementtreemodule.m_name, |
|
9108e7dcd7d8
Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59893
diff
changeset
|
3057 m); |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3058 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3059 /* python glue code */ |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3060 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3061 g = PyDict_New(); |
|
36954
db5e720b0cef
merged with cElementTree development trunk (1.0.6 snapshot):
Fredrik Lundh <fredrik@pythonware.com>
parents:
36684
diff
changeset
|
3062 if (!g) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3063 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3064 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3065 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
|
3066 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3067 bootstrap = ( |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3068 "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
|
3069 " if tag == '*':\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3070 " tag = None\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3071 " 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
|
3072 " yield node\n" |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3073 " for node in node:\n" |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3074 " 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
|
3075 " yield node\n" |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3076 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3077 "def itertext(node):\n" /* helper */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3078 " if node.text:\n" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3079 " yield node.text\n" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3080 " for e in node:\n" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3081 " for s in e.itertext():\n" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3082 " yield s\n" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3083 " if e.tail:\n" |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3084 " yield e.tail\n" |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3085 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3086 ); |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3087 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3088 if (!PyRun_String(bootstrap, Py_file_input, g, NULL)) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3089 return NULL; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3090 |
|
76110
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3091 if (!(temp = PyImport_ImportModule("copy"))) |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3092 return NULL; |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3093 elementtree_deepcopy_obj = PyObject_GetAttrString(temp, "deepcopy"); |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3094 Py_XDECREF(temp); |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3095 |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3096 if (!(elementpath_obj = PyImport_ImportModule("xml.etree.ElementPath"))) |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3097 return NULL; |
|
1ddf58262706
Replace bootstrap imports with real C API calls.
Eli Bendersky <eliben@gmail.com>
parents:
76101
diff
changeset
|
3098 |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3099 elementtree_iter_obj = PyDict_GetItemString(g, "iter"); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3100 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
|
3101 |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3102 #if defined(USE_PYEXPAT_CAPI) |
|
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3103 /* link against pyexpat, if possible */ |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3104 expat_capi = PyCapsule_Import(PyExpat_CAPSULE_NAME, 0); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3105 if (expat_capi) { |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3106 /* check that it's usable */ |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3107 if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 || |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3108 expat_capi->size < sizeof(struct PyExpat_CAPI) || |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3109 expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION || |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3110 expat_capi->MINOR_VERSION != XML_MINOR_VERSION || |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3111 expat_capi->MICRO_VERSION != XML_MICRO_VERSION) |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3112 expat_capi = NULL; |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3113 } |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3114 #endif |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3115 |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3116 elementtree_parseerror_obj = PyErr_NewException( |
|
74903
65fc79fb4eb2
Issue #13988: cElementTree is deprecated and the _elementtree accelerator is automatically used whenever available.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
74870
diff
changeset
|
3117 "xml.etree.ElementTree.ParseError", PyExc_SyntaxError, NULL |
|
59601
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3118 ); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3119 Py_INCREF(elementtree_parseerror_obj); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3120 PyModule_AddObject(m, "ParseError", elementtree_parseerror_obj); |
|
7a18c2762886
Merged revisions 78838-78839,78917,78919,78934,78937 via svnmerge from
Florent Xicluna <florent.xicluna@gmail.com>
parents:
53816
diff
changeset
|
3121 |
|
75379
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
3122 Py_INCREF((PyObject *)&Element_Type); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
3123 PyModule_AddObject(m, "Element", (PyObject *)&Element_Type); |
|
ce1c26cbe5fb
Issue #14128: Exposing Element as an actual type from _elementtree, rather than a factory function.
Eli Bendersky <eliben@gmail.com>
parents:
74903
diff
changeset
|
3124 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
3125 return m; |
|
36050
6586cd9920e7
updating to cElementTree 1.0.5 (step 2 of 3)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3126 } |
