Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: Modules/pyexpat.c

Issue 20152: Derby: Convert the _imp module to use Argument Clinic
Patch Set: Created 6 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Python.h" 1 #include "Python.h"
2 #include <ctype.h> 2 #include <ctype.h>
3 3
4 #include "frameobject.h" 4 #include "frameobject.h"
5 #include "expat.h" 5 #include "expat.h"
6 6
7 #include "pyexpat.h" 7 #include "pyexpat.h"
8
9 /*[clinic input]
10 module pyexpat
11 [clinic start generated code]*/
12 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b168d503a4490c15]*/
8 13
9 #define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_ MICRO_VERSION) 14 #define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_ MICRO_VERSION)
10 15
11 #define FIX_TRACE 16 #define FIX_TRACE
12 17
13 static XML_Memory_Handling_Suite ExpatMemoryHandler = { 18 static XML_Memory_Handling_Suite ExpatMemoryHandler = {
14 PyObject_Malloc, PyObject_Realloc, PyObject_Free}; 19 PyObject_Malloc, PyObject_Realloc, PyObject_Free};
15 20
16 enum HandlerTypes { 21 enum HandlerTypes {
17 StartElement, 22 StartElement,
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 (void *userData, const XML_Char *doctypeName, 776 (void *userData, const XML_Char *doctypeName,
772 const XML_Char *sysid, const XML_Char *pubid, 777 const XML_Char *sysid, const XML_Char *pubid,
773 int has_internal_subset), 778 int has_internal_subset),
774 ("(NNNi)", string_intern(self, doctypeName), 779 ("(NNNi)", string_intern(self, doctypeName),
775 string_intern(self, sysid), string_intern(self, pubid), 780 string_intern(self, sysid), string_intern(self, pubid),
776 has_internal_subset)) 781 has_internal_subset))
777 782
778 VOID_HANDLER(EndDoctypeDecl, (void *userData), ("()")) 783 VOID_HANDLER(EndDoctypeDecl, (void *userData), ("()"))
779 784
780 /* ---------------------------------------------------------------- */ 785 /* ---------------------------------------------------------------- */
786 /*[clinic input]
787 class pyexpat.xmlparser "xmlparseobject *" "&Xmlparsetype"
788 [clinic start generated code]*/
789 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=2393162385232e1c]*/
790
781 791
782 static PyObject * 792 static PyObject *
783 get_parse_result(xmlparseobject *self, int rv) 793 get_parse_result(xmlparseobject *self, int rv)
784 { 794 {
785 if (PyErr_Occurred()) { 795 if (PyErr_Occurred()) {
786 return NULL; 796 return NULL;
787 } 797 }
788 if (rv == 0) { 798 if (rv == 0) {
789 return set_error(self, XML_GetErrorCode(self->itself)); 799 return set_error(self, XML_GetErrorCode(self->itself));
790 } 800 }
791 if (flush_character_buffer(self) < 0) { 801 if (flush_character_buffer(self) < 0) {
792 return NULL; 802 return NULL;
793 } 803 }
794 return PyLong_FromLong(rv); 804 return PyLong_FromLong(rv);
795 } 805 }
796 806
797 PyDoc_STRVAR(xmlparse_Parse__doc__,
798 "Parse(data[, isfinal])\n\
799 Parse XML data. `isfinal' should be true at end of input.");
800
801 #define MAX_CHUNK_SIZE (1 << 20) 807 #define MAX_CHUNK_SIZE (1 << 20)
802 808
809 /*[clinic input]
810 pyexpat.xmlparser.Parse
811
812 data: object
813 isFinal: int = 0
loewis 2014/07/27 18:05:30 isFinal->isfinal
814 /
815
816 Parse XML data.
817
818 `isfinal' should be true at end of input.
819 [clinic start generated code]*/
820
821 PyDoc_STRVAR(pyexpat_xmlparser_Parse__doc__,
822 "sig=($self, data, isFinal=0)\n"
823 "Parse XML data.\n"
824 "\n"
825 "`isfinal\' should be true at end of input.");
826
827 #define PYEXPAT_XMLPARSER_PARSE_METHODDEF \
828 {"Parse", (PyCFunction)pyexpat_xmlparser_Parse, METH_VARARGS, pyexpat_xmlpar ser_Parse__doc__},
829
803 static PyObject * 830 static PyObject *
804 xmlparse_Parse(xmlparseobject *self, PyObject *args) 831 pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyObject *data, int isFinal);
832
833 static PyObject *
834 pyexpat_xmlparser_Parse(xmlparseobject *self, PyObject *args)
805 { 835 {
836 PyObject *return_value = NULL;
806 PyObject *data; 837 PyObject *data;
807 int isFinal = 0; 838 int isFinal = 0;
839
840 if (!PyArg_ParseTuple(args,
841 "O|i:Parse",
842 &data, &isFinal))
843 goto exit;
844 return_value = pyexpat_xmlparser_Parse_impl(self, data, isFinal);
845
846 exit:
847 return return_value;
848 }
849
850 static PyObject *
851 pyexpat_xmlparser_Parse_impl(xmlparseobject *self, PyObject *data, int isFinal)
852 /*[clinic end generated code: output=b269e895560080aa input=e37b81b8948ca7e0]*/
853 {
808 const char *s; 854 const char *s;
809 Py_ssize_t slen; 855 Py_ssize_t slen;
810 Py_buffer view; 856 Py_buffer view;
811 int rc; 857 int rc;
812 858
813 if (!PyArg_ParseTuple(args, "O|i:Parse", &data, &isFinal))
814 return NULL;
815
816 if (PyUnicode_Check(data)) { 859 if (PyUnicode_Check(data)) {
817 view.buf = NULL; 860 view.buf = NULL;
818 s = PyUnicode_AsUTF8AndSize(data, &slen); 861 s = PyUnicode_AsUTF8AndSize(data, &slen);
819 if (s == NULL) 862 if (s == NULL)
820 return NULL; 863 return NULL;
821 /* Explicitly set UTF-8 encoding. Return code ignored. */ 864 /* Explicitly set UTF-8 encoding. Return code ignored. */
822 (void)XML_SetEncoding(self->itself, "utf-8"); 865 (void)XML_SetEncoding(self->itself, "utf-8");
823 } 866 }
824 else { 867 else {
825 if (PyObject_GetBuffer(data, &view, PyBUF_SIMPLE) < 0) 868 if (PyObject_GetBuffer(data, &view, PyBUF_SIMPLE) < 0)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 memcpy(buf, ptr, len); 923 memcpy(buf, ptr, len);
881 Py_DECREF(str); 924 Py_DECREF(str);
882 /* len <= buf_size <= INT_MAX */ 925 /* len <= buf_size <= INT_MAX */
883 return (int)len; 926 return (int)len;
884 927
885 error: 928 error:
886 Py_XDECREF(str); 929 Py_XDECREF(str);
887 return -1; 930 return -1;
888 } 931 }
889 932
890 PyDoc_STRVAR(xmlparse_ParseFile__doc__, 933 /*[clinic input]
891 "ParseFile(file)\n\ 934 pyexpat.xmlparser.ParseFile
892 Parse XML data from file-like object."); 935
936 file: object
937 /
938
939 Parse XML data from file-like object.
940 [clinic start generated code]*/
941
942 PyDoc_STRVAR(pyexpat_xmlparser_ParseFile__doc__,
943 "sig=($self, file)\n"
944 "Parse XML data from file-like object.");
945
946 #define PYEXPAT_XMLPARSER_PARSEFILE_METHODDEF \
947 {"ParseFile", (PyCFunction)pyexpat_xmlparser_ParseFile, METH_O, pyexpat_xmlp arser_ParseFile__doc__},
893 948
894 static PyObject * 949 static PyObject *
895 xmlparse_ParseFile(xmlparseobject *self, PyObject *f) 950 pyexpat_xmlparser_ParseFile(xmlparseobject *self, PyObject *file)
951 /*[clinic end generated code: output=0123fbf1397ee84f input=fbb5a12b6038d735]*/
896 { 952 {
897 int rv = 1; 953 int rv = 1;
898 PyObject *readmethod = NULL; 954 PyObject *readmethod = NULL;
899 _Py_IDENTIFIER(read); 955 _Py_IDENTIFIER(read);
900 956
901 readmethod = _PyObject_GetAttrId(f, &PyId_read); 957 readmethod = _PyObject_GetAttrId(file, &PyId_read);
902 if (readmethod == NULL) { 958 if (readmethod == NULL) {
903 PyErr_SetString(PyExc_TypeError, 959 PyErr_SetString(PyExc_TypeError,
904 "argument must have 'read' attribute"); 960 "argument must have 'read' attribute");
905 return NULL; 961 return NULL;
906 } 962 }
907 for (;;) { 963 for (;;) {
908 int bytes_read; 964 int bytes_read;
909 void *buf = XML_GetBuffer(self->itself, BUF_SIZE); 965 void *buf = XML_GetBuffer(self->itself, BUF_SIZE);
910 if (buf == NULL) { 966 if (buf == NULL) {
911 Py_XDECREF(readmethod); 967 Py_XDECREF(readmethod);
(...skipping 11 matching lines...) Expand all
923 return NULL; 979 return NULL;
924 } 980 }
925 981
926 if (!rv || bytes_read == 0) 982 if (!rv || bytes_read == 0)
927 break; 983 break;
928 } 984 }
929 Py_XDECREF(readmethod); 985 Py_XDECREF(readmethod);
930 return get_parse_result(self, rv); 986 return get_parse_result(self, rv);
931 } 987 }
932 988
933 PyDoc_STRVAR(xmlparse_SetBase__doc__, 989 /*[clinic input]
934 "SetBase(base_url)\n\ 990 pyexpat.xmlparser.SetBase
935 Set the base URL for the parser."); 991
992 base: str
993 /
994
995 Set the base URL for the parser.
996 [clinic start generated code]*/
997
998 PyDoc_STRVAR(pyexpat_xmlparser_SetBase__doc__,
999 "sig=($self, base)\n"
1000 "Set the base URL for the parser.");
1001
1002 #define PYEXPAT_XMLPARSER_SETBASE_METHODDEF \
1003 {"SetBase", (PyCFunction)pyexpat_xmlparser_SetBase, METH_VARARGS, pyexpat_xm lparser_SetBase__doc__},
936 1004
937 static PyObject * 1005 static PyObject *
938 xmlparse_SetBase(xmlparseobject *self, PyObject *args) 1006 pyexpat_xmlparser_SetBase_impl(xmlparseobject *self, const char *base);
1007
1008 static PyObject *
1009 pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *args)
939 { 1010 {
940 char *base; 1011 PyObject *return_value = NULL;
1012 const char *base;
941 1013
942 if (!PyArg_ParseTuple(args, "s:SetBase", &base)) 1014 if (!PyArg_ParseTuple(args,
943 return NULL; 1015 "s:SetBase",
1016 &base))
1017 goto exit;
1018 return_value = pyexpat_xmlparser_SetBase_impl(self, base);
1019
1020 exit:
1021 return return_value;
1022 }
1023
1024 static PyObject *
1025 pyexpat_xmlparser_SetBase_impl(xmlparseobject *self, const char *base)
1026 /*[clinic end generated code: output=a900d3a595345852 input=c684e5de895ee1a8]*/
1027 {
944 if (!XML_SetBase(self->itself, base)) { 1028 if (!XML_SetBase(self->itself, base)) {
945 return PyErr_NoMemory(); 1029 return PyErr_NoMemory();
946 } 1030 }
947 Py_INCREF(Py_None); 1031 Py_RETURN_NONE;
948 return Py_None;
949 } 1032 }
950 1033
951 PyDoc_STRVAR(xmlparse_GetBase__doc__, 1034 /*[clinic input]
952 "GetBase() -> url\n\ 1035 pyexpat.xmlparser.GetBase
953 Return base URL string for the parser."); 1036
1037 Return base URL string for the parser.
1038 [clinic start generated code]*/
1039
1040 PyDoc_STRVAR(pyexpat_xmlparser_GetBase__doc__,
1041 "sig=($self)\n"
1042 "Return base URL string for the parser.");
1043
1044 #define PYEXPAT_XMLPARSER_GETBASE_METHODDEF \
1045 {"GetBase", (PyCFunction)pyexpat_xmlparser_GetBase, METH_NOARGS, pyexpat_xml parser_GetBase__doc__},
954 1046
955 static PyObject * 1047 static PyObject *
956 xmlparse_GetBase(xmlparseobject *self, PyObject *unused) 1048 pyexpat_xmlparser_GetBase_impl(xmlparseobject *self);
1049
1050 static PyObject *
1051 pyexpat_xmlparser_GetBase(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
1052 {
1053 return pyexpat_xmlparser_GetBase_impl(self);
1054 }
1055
1056 static PyObject *
1057 pyexpat_xmlparser_GetBase_impl(xmlparseobject *self)
1058 /*[clinic end generated code: output=ea0d083ffcb44c78 input=918d71c38009620e]*/
957 { 1059 {
958 return Py_BuildValue("z", XML_GetBase(self->itself)); 1060 return Py_BuildValue("z", XML_GetBase(self->itself));
959 } 1061 }
960 1062
961 PyDoc_STRVAR(xmlparse_GetInputContext__doc__, 1063 /*[clinic input]
962 "GetInputContext() -> string\n\ 1064 pyexpat.xmlparser.GetInputContext
963 Return the untranslated text of the input that caused the current event.\n\ 1065
964 If the event was generated by a large amount of text (such as a start tag\n\ 1066 Return the untranslated text of the input that caused the current event.
965 for an element with many attributes), not all of the text may be available."); 1067
1068 If the event was generated by a large amount of text (such as a start tag
1069 for an element with many attributes), not all of the text may be available.
1070 [clinic start generated code]*/
1071
1072 PyDoc_STRVAR(pyexpat_xmlparser_GetInputContext__doc__,
1073 "sig=($self)\n"
1074 "Return the untranslated text of the input that caused the current event.\n"
1075 "\n"
1076 "If the event was generated by a large amount of text (such as a start tag\n"
1077 "for an element with many attributes), not all of the text may be available.");
1078
1079 #define PYEXPAT_XMLPARSER_GETINPUTCONTEXT_METHODDEF \
1080 {"GetInputContext", (PyCFunction)pyexpat_xmlparser_GetInputContext, METH_NOA RGS, pyexpat_xmlparser_GetInputContext__doc__},
966 1081
967 static PyObject * 1082 static PyObject *
968 xmlparse_GetInputContext(xmlparseobject *self, PyObject *unused) 1083 pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self);
1084
1085 static PyObject *
1086 pyexpat_xmlparser_GetInputContext(xmlparseobject *self, PyObject *Py_UNUSED(igno red))
1087 {
1088 return pyexpat_xmlparser_GetInputContext_impl(self);
1089 }
1090
1091 static PyObject *
1092 pyexpat_xmlparser_GetInputContext_impl(xmlparseobject *self)
1093 /*[clinic end generated code: output=f667340bbafc327a input=034df8712db68379]*/
969 { 1094 {
970 if (self->in_callback) { 1095 if (self->in_callback) {
971 int offset, size; 1096 int offset, size;
972 const char *buffer 1097 const char *buffer
973 = XML_GetInputContext(self->itself, &offset, &size); 1098 = XML_GetInputContext(self->itself, &offset, &size);
974 1099
975 if (buffer != NULL) 1100 if (buffer != NULL)
976 return PyBytes_FromStringAndSize(buffer + offset, 1101 return PyBytes_FromStringAndSize(buffer + offset,
977 size - offset); 1102 size - offset);
978 else 1103 else
979 Py_RETURN_NONE; 1104 Py_RETURN_NONE;
980 } 1105 }
981 else 1106 else
982 Py_RETURN_NONE; 1107 Py_RETURN_NONE;
983 } 1108 }
984 1109
985 PyDoc_STRVAR(xmlparse_ExternalEntityParserCreate__doc__, 1110 /*[clinic input]
986 "ExternalEntityParserCreate(context[, encoding])\n\ 1111 pyexpat.xmlparser.ExternalEntityParserCreate
987 Create a parser for parsing an external entity based on the\n\ 1112
988 information passed to the ExternalEntityRefHandler."); 1113 context: str(nullable=True)
1114 encoding: str = NULL
1115 /
1116
1117 Create a parser for parsing an external entity based on the information passed t o the ExternalEntityRefHandler.
1118 [clinic start generated code]*/
1119
1120 PyDoc_STRVAR(pyexpat_xmlparser_ExternalEntityParserCreate__doc__,
1121 "sig=($self, context, encoding=None)\n"
1122 "Create a parser for parsing an external entity based on the information passed to the ExternalEntityRefHandler.");
1123
1124 #define PYEXPAT_XMLPARSER_EXTERNALENTITYPARSERCREATE_METHODDEF \
1125 {"ExternalEntityParserCreate", (PyCFunction)pyexpat_xmlparser_ExternalEntity ParserCreate, METH_VARARGS, pyexpat_xmlparser_ExternalEntityParserCreate__doc__} ,
989 1126
990 static PyObject * 1127 static PyObject *
991 xmlparse_ExternalEntityParserCreate(xmlparseobject *self, PyObject *args) 1128 pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self, const ch ar *context, const char *encoding);
1129
1130 static PyObject *
1131 pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyObject *arg s)
992 { 1132 {
993 char *context; 1133 PyObject *return_value = NULL;
994 char *encoding = NULL; 1134 const char *context;
1135 const char *encoding = NULL;
1136
1137 if (!PyArg_ParseTuple(args,
1138 "z|s:ExternalEntityParserCreate",
1139 &context, &encoding))
1140 goto exit;
1141 return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl(self, conte xt, encoding);
1142
1143 exit:
1144 return return_value;
1145 }
1146
1147 static PyObject *
1148 pyexpat_xmlparser_ExternalEntityParserCreate_impl(xmlparseobject *self, const ch ar *context, const char *encoding)
1149 /*[clinic end generated code: output=82c66e8a282ec25b input=283206575d960272]*/
1150 {
995 xmlparseobject *new_parser; 1151 xmlparseobject *new_parser;
996 int i; 1152 int i;
997
998 if (!PyArg_ParseTuple(args, "z|s:ExternalEntityParserCreate",
999 &context, &encoding)) {
1000 return NULL;
1001 }
1002 1153
1003 new_parser = PyObject_GC_New(xmlparseobject, &Xmlparsetype); 1154 new_parser = PyObject_GC_New(xmlparseobject, &Xmlparsetype);
1004 if (new_parser == NULL) 1155 if (new_parser == NULL)
1005 return NULL; 1156 return NULL;
1006 new_parser->buffer_size = self->buffer_size; 1157 new_parser->buffer_size = self->buffer_size;
1007 new_parser->buffer_used = 0; 1158 new_parser->buffer_used = 0;
1008 new_parser->buffer = NULL; 1159 new_parser->buffer = NULL;
1009 new_parser->ordered_attributes = self->ordered_attributes; 1160 new_parser->ordered_attributes = self->ordered_attributes;
1010 new_parser->specified_attributes = self->specified_attributes; 1161 new_parser->specified_attributes = self->specified_attributes;
1011 new_parser->in_callback = 0; 1162 new_parser->in_callback = 0;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 if (handler != NULL) { 1199 if (handler != NULL) {
1049 Py_INCREF(handler); 1200 Py_INCREF(handler);
1050 new_parser->handlers[i] = handler; 1201 new_parser->handlers[i] = handler;
1051 handler_info[i].setter(new_parser->itself, 1202 handler_info[i].setter(new_parser->itself,
1052 handler_info[i].handler); 1203 handler_info[i].handler);
1053 } 1204 }
1054 } 1205 }
1055 return (PyObject *)new_parser; 1206 return (PyObject *)new_parser;
1056 } 1207 }
1057 1208
1058 PyDoc_STRVAR(xmlparse_SetParamEntityParsing__doc__, 1209 /*[clinic input]
1059 "SetParamEntityParsing(flag) -> success\n\ 1210 pyexpat.xmlparser.SetParamEntityParsing
1060 Controls parsing of parameter entities (including the external DTD\n\
1061 subset). Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n\
1062 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n\
1063 XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n\
1064 was successful.");
1065 1211
1066 static PyObject* 1212 flag: int
1067 xmlparse_SetParamEntityParsing(xmlparseobject *p, PyObject* args) 1213 /
1214
1215 Controls parsing of parameter entities (including the external DTD subset).
1216
1217 Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,
1218 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and
1219 XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag
1220 was successful.
1221 [clinic start generated code]*/
1222
1223 PyDoc_STRVAR(pyexpat_xmlparser_SetParamEntityParsing__doc__,
1224 "sig=($self, flag)\n"
1225 "Controls parsing of parameter entities (including the external DTD subset).\n"
1226 "\n"
1227 "Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER,\n"
1228 "XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and\n"
1229 "XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag\n"
1230 "was successful.");
1231
1232 #define PYEXPAT_XMLPARSER_SETPARAMENTITYPARSING_METHODDEF \
1233 {"SetParamEntityParsing", (PyCFunction)pyexpat_xmlparser_SetParamEntityParsi ng, METH_VARARGS, pyexpat_xmlparser_SetParamEntityParsing__doc__},
1234
1235 static PyObject *
1236 pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag);
1237
1238 static PyObject *
1239 pyexpat_xmlparser_SetParamEntityParsing(xmlparseobject *self, PyObject *args)
1068 { 1240 {
1241 PyObject *return_value = NULL;
1069 int flag; 1242 int flag;
1070 if (!PyArg_ParseTuple(args, "i", &flag)) 1243
1071 return NULL; 1244 if (!PyArg_ParseTuple(args,
1072 flag = XML_SetParamEntityParsing(p->itself, flag); 1245 "i:SetParamEntityParsing",
1246 &flag))
1247 goto exit;
1248 return_value = pyexpat_xmlparser_SetParamEntityParsing_impl(self, flag);
1249
1250 exit:
1251 return return_value;
1252 }
1253
1254 static PyObject *
1255 pyexpat_xmlparser_SetParamEntityParsing_impl(xmlparseobject *self, int flag)
1256 /*[clinic end generated code: output=ad61408f937a4429 input=8aea19b4b15e9af1]*/
1257 {
1258 flag = XML_SetParamEntityParsing(self->itself, flag);
1073 return PyLong_FromLong(flag); 1259 return PyLong_FromLong(flag);
1074 } 1260 }
1075 1261
1076 1262
1077 #if XML_COMBINED_VERSION >= 19505 1263 #if XML_COMBINED_VERSION >= 19505
1078 PyDoc_STRVAR(xmlparse_UseForeignDTD__doc__, 1264
1079 "UseForeignDTD([flag])\n\ 1265 /*[clinic input]
1080 Allows the application to provide an artificial external subset if one is\n\ 1266 pyexpat.xmlparser.UseForeignDTD
1081 not specified as part of the document instance. This readily allows the\n\ 1267
1082 use of a 'default' document type controlled by the application, while still\n\ 1268 flag: bool = True
1083 getting the advantage of providing document type information to the parser.\n\ 1269 /
1084 'flag' defaults to True if not provided."); 1270
1271 Allows the application to provide an artificial external subset if one is not sp ecified as part of the document instance.
1272
1273 This readily allows the use of a 'default' document type controlled by the
1274 application, while still getting the advantage of providing document type
1275 information to the parser. 'flag' defaults to True if not provided.
1276 [clinic start generated code]*/
1277
1278 PyDoc_STRVAR(pyexpat_xmlparser_UseForeignDTD__doc__,
1279 "sig=($self, flag=True)\n"
1280 "Allows the application to provide an artificial external subset if one is not s pecified as part of the document instance.\n"
1281 "\n"
1282 "This readily allows the use of a \'default\' document type controlled by the\n"
1283 "application, while still getting the advantage of providing document type\n"
1284 "information to the parser. \'flag\' defaults to True if not provided.");
1285
1286 #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF \
1287 {"UseForeignDTD", (PyCFunction)pyexpat_xmlparser_UseForeignDTD, METH_VARARGS , pyexpat_xmlparser_UseForeignDTD__doc__},
1085 1288
1086 static PyObject * 1289 static PyObject *
1087 xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) 1290 pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, int flag);
1291
1292 static PyObject *
1293 pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyObject *args)
1088 { 1294 {
1295 PyObject *return_value = NULL;
1089 int flag = 1; 1296 int flag = 1;
1297
1298 if (!PyArg_ParseTuple(args,
1299 "|p:UseForeignDTD",
1300 &flag))
1301 goto exit;
1302 return_value = pyexpat_xmlparser_UseForeignDTD_impl(self, flag);
1303
1304 exit:
1305 return return_value;
1306 }
1307
1308 static PyObject *
1309 pyexpat_xmlparser_UseForeignDTD_impl(xmlparseobject *self, int flag)
1310 /*[clinic end generated code: output=2db438da0b740ee0 input=78144c519d116a6e]*/
1311 {
1090 enum XML_Error rc; 1312 enum XML_Error rc;
1091 if (!PyArg_ParseTuple(args, "|p:UseForeignDTD", &flag)) 1313
1092 return NULL;
1093 rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); 1314 rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE);
1094 if (rc != XML_ERROR_NONE) { 1315 if (rc != XML_ERROR_NONE) {
1095 return set_error(self, rc); 1316 return set_error(self, rc);
1096 } 1317 }
1097 Py_INCREF(Py_None); 1318 Py_INCREF(Py_None);
1098 return Py_None; 1319 return Py_None;
1099 } 1320 }
1100 #endif 1321 #endif
1101 1322
1102 static PyObject *xmlparse_dir(PyObject *self, PyObject* noargs); 1323 /*[clinic input]
1324 pyexpat.xmlparser.__dir__
1325 [clinic start generated code]*/
1326
1327 PyDoc_STRVAR(pyexpat_xmlparser___dir____doc__,
1328 "sig=($self)");
1329
1330 #define PYEXPAT_XMLPARSER___DIR___METHODDEF \
1331 {"__dir__", (PyCFunction)pyexpat_xmlparser___dir__, METH_NOARGS, pyexpat_xml parser___dir____doc__},
1332
1333 static PyObject *
1334 pyexpat_xmlparser___dir___impl(xmlparseobject *self);
1335
1336 static PyObject *
1337 pyexpat_xmlparser___dir__(xmlparseobject *self, PyObject *Py_UNUSED(ignored))
1338 {
1339 return pyexpat_xmlparser___dir___impl(self);
1340 }
1341
1342 static PyObject *
1343 pyexpat_xmlparser___dir___impl(xmlparseobject *self)
1344 /*[clinic end generated code: output=ca05eb23aaf1003b input=76aa455f2a661384]*/
1345 {
1346 #define APPEND(list, str) \
1347 do { \
1348 PyObject *o = PyUnicode_FromString(str); \
1349 if (o != NULL) \
1350 PyList_Append(list, o); \
1351 Py_XDECREF(o); \
1352 } while (0)
1353
1354 int i;
1355 PyObject *rc = PyList_New(0);
1356 if (!rc)
1357 return NULL;
1358 for (i = 0; handler_info[i].name != NULL; i++) {
1359 PyObject *o = get_handler_name(&handler_info[i]);
1360 if (o != NULL)
1361 PyList_Append(rc, o);
1362 Py_XDECREF(o);
1363 }
1364 APPEND(rc, "ErrorCode");
1365 APPEND(rc, "ErrorLineNumber");
1366 APPEND(rc, "ErrorColumnNumber");
1367 APPEND(rc, "ErrorByteIndex");
1368 APPEND(rc, "CurrentLineNumber");
1369 APPEND(rc, "CurrentColumnNumber");
1370 APPEND(rc, "CurrentByteIndex");
1371 APPEND(rc, "buffer_size");
1372 APPEND(rc, "buffer_text");
1373 APPEND(rc, "buffer_used");
1374 APPEND(rc, "namespace_prefixes");
1375 APPEND(rc, "ordered_attributes");
1376 APPEND(rc, "specified_attributes");
1377 APPEND(rc, "intern");
1378
1379 #undef APPEND
1380
1381 if (PyErr_Occurred()) {
1382 Py_DECREF(rc);
1383 rc = NULL;
1384 }
1385
1386 return rc;
1387 }
1103 1388
1104 static struct PyMethodDef xmlparse_methods[] = { 1389 static struct PyMethodDef xmlparse_methods[] = {
1105 {"Parse", (PyCFunction)xmlparse_Parse, 1390 PYEXPAT_XMLPARSER_PARSE_METHODDEF
1106 METH_VARARGS, xmlparse_Parse__doc__}, 1391 PYEXPAT_XMLPARSER_PARSEFILE_METHODDEF
1107 {"ParseFile", (PyCFunction)xmlparse_ParseFile, 1392 PYEXPAT_XMLPARSER_SETBASE_METHODDEF
1108 METH_O, xmlparse_ParseFile__doc__}, 1393 PYEXPAT_XMLPARSER_GETBASE_METHODDEF
1109 {"SetBase", (PyCFunction)xmlparse_SetBase, 1394 PYEXPAT_XMLPARSER_GETINPUTCONTEXT_METHODDEF
1110 METH_VARARGS, xmlparse_SetBase__doc__}, 1395 PYEXPAT_XMLPARSER_EXTERNALENTITYPARSERCREATE_METHODDEF
1111 {"GetBase", (PyCFunction)xmlparse_GetBase, 1396 PYEXPAT_XMLPARSER_SETPARAMENTITYPARSING_METHODDEF
1112 METH_NOARGS, xmlparse_GetBase__doc__},
1113 {"ExternalEntityParserCreate", (PyCFunction)xmlparse_ExternalEntityParserCre ate,
1114 METH_VARARGS, xmlparse_ExternalEntityParserCreate__doc__},
1115 {"SetParamEntityParsing", (PyCFunction)xmlparse_SetParamEntityParsing,
1116 METH_VARARGS, xmlparse_SetParamEntityParsing__doc__},
1117 {"GetInputContext", (PyCFunction)xmlparse_GetInputContext,
1118 METH_NOARGS, xmlparse_GetInputContext__doc__},
1119 #if XML_COMBINED_VERSION >= 19505 1397 #if XML_COMBINED_VERSION >= 19505
1120 {"UseForeignDTD", (PyCFunction)xmlparse_UseForeignDTD, 1398 PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
1121 METH_VARARGS, xmlparse_UseForeignDTD__doc__},
1122 #endif 1399 #endif
1123 {"__dir__", xmlparse_dir, METH_NOARGS}, 1400 PYEXPAT_XMLPARSER___DIR___METHODDEF
1124 {NULL, NULL} /* sentinel */ 1401 {NULL, NULL} /* sentinel */
1125 }; 1402 };
1126 1403
1127 /* ---------- */ 1404 /* ---------- */
1128 1405
1129 1406
1130 1407
1131 /* pyexpat international encoding support. 1408 /* pyexpat international encoding support.
1132 Make it as simple as possible. 1409 Make it as simple as possible.
1133 */ 1410 */
1134 1411
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 Py_INCREF(Py_None); 1630 Py_INCREF(Py_None);
1354 return Py_None; 1631 return Py_None;
1355 } 1632 }
1356 else { 1633 else {
1357 Py_INCREF(self->intern); 1634 Py_INCREF(self->intern);
1358 return self->intern; 1635 return self->intern;
1359 } 1636 }
1360 } 1637 }
1361 generic: 1638 generic:
1362 return PyObject_GenericGetAttr((PyObject*)self, nameobj); 1639 return PyObject_GenericGetAttr((PyObject*)self, nameobj);
1363 }
1364
1365 static PyObject *
1366 xmlparse_dir(PyObject *self, PyObject* noargs)
1367 {
1368 #define APPEND(list, str) \
1369 do { \
1370 PyObject *o = PyUnicode_FromString(str); \
1371 if (o != NULL) \
1372 PyList_Append(list, o); \
1373 Py_XDECREF(o); \
1374 } while (0)
1375
1376 int i;
1377 PyObject *rc = PyList_New(0);
1378 if (!rc)
1379 return NULL;
1380 for (i = 0; handler_info[i].name != NULL; i++) {
1381 PyObject *o = get_handler_name(&handler_info[i]);
1382 if (o != NULL)
1383 PyList_Append(rc, o);
1384 Py_XDECREF(o);
1385 }
1386 APPEND(rc, "ErrorCode");
1387 APPEND(rc, "ErrorLineNumber");
1388 APPEND(rc, "ErrorColumnNumber");
1389 APPEND(rc, "ErrorByteIndex");
1390 APPEND(rc, "CurrentLineNumber");
1391 APPEND(rc, "CurrentColumnNumber");
1392 APPEND(rc, "CurrentByteIndex");
1393 APPEND(rc, "buffer_size");
1394 APPEND(rc, "buffer_text");
1395 APPEND(rc, "buffer_used");
1396 APPEND(rc, "namespace_prefixes");
1397 APPEND(rc, "ordered_attributes");
1398 APPEND(rc, "specified_attributes");
1399 APPEND(rc, "intern");
1400
1401 #undef APPEND
1402
1403 if (PyErr_Occurred()) {
1404 Py_DECREF(rc);
1405 rc = NULL;
1406 }
1407
1408 return rc;
1409 } 1640 }
1410 1641
1411 static int 1642 static int
1412 sethandler(xmlparseobject *self, PyObject *name, PyObject* v) 1643 sethandler(xmlparseobject *self, PyObject *name, PyObject* v)
1413 { 1644 {
1414 int handlernum = handlername2int(name); 1645 int handlernum = handlername2int(name);
1415 if (handlernum >= 0) { 1646 if (handlernum >= 0) {
1416 xmlhandler c_handler = NULL; 1647 xmlhandler c_handler = NULL;
1417 PyObject *temp = self->handlers[handlernum]; 1648 PyObject *temp = self->handlers[handlernum];
1418 1649
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 0, /* tp_richcompare */ 1837 0, /* tp_richcompare */
1607 0, /* tp_weaklistoffset */ 1838 0, /* tp_weaklistoffset */
1608 0, /* tp_iter */ 1839 0, /* tp_iter */
1609 0, /* tp_iternext */ 1840 0, /* tp_iternext */
1610 xmlparse_methods, /* tp_methods */ 1841 xmlparse_methods, /* tp_methods */
1611 }; 1842 };
1612 1843
1613 /* End of code for xmlparser objects */ 1844 /* End of code for xmlparser objects */
1614 /* -------------------------------------------------------- */ 1845 /* -------------------------------------------------------- */
1615 1846
1847 /*[clinic input]
1848 pyexpat.ParserCreate
1849
1850 encoding: str(nullable=True) = NULL
1851 namespace_separator: str(nullable=True) = NULL
1852 intern: object = NULL
1853
1854 Return a new XML parser object.
1855 [clinic start generated code]*/
1856
1616 PyDoc_STRVAR(pyexpat_ParserCreate__doc__, 1857 PyDoc_STRVAR(pyexpat_ParserCreate__doc__,
1617 "ParserCreate([encoding[, namespace_separator]]) -> parser\n\ 1858 "sig=($module, encoding=None, namespace_separator=None, intern=None)\n"
1618 Return a new XML parser object."); 1859 "Return a new XML parser object.");
1860
1861 #define PYEXPAT_PARSERCREATE_METHODDEF \
1862 {"ParserCreate", (PyCFunction)pyexpat_ParserCreate, METH_VARARGS|METH_KEYWOR DS, pyexpat_ParserCreate__doc__},
1619 1863
1620 static PyObject * 1864 static PyObject *
1621 pyexpat_ParserCreate(PyObject *notused, PyObject *args, PyObject *kw) 1865 pyexpat_ParserCreate_impl(PyModuleDef *module, const char *encoding, const char *namespace_separator, PyObject *intern);
1866
1867 static PyObject *
1868 pyexpat_ParserCreate(PyModuleDef *module, PyObject *args, PyObject *kwargs)
1622 { 1869 {
1623 char *encoding = NULL; 1870 PyObject *return_value = NULL;
1624 char *namespace_separator = NULL; 1871 static char *_keywords[] = {"encoding", "namespace_separator", "intern", NUL L};
1872 const char *encoding = NULL;
1873 const char *namespace_separator = NULL;
1625 PyObject *intern = NULL; 1874 PyObject *intern = NULL;
1875
1876 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
1877 "|zzO:ParserCreate", _keywords,
1878 &encoding, &namespace_separator, &intern))
1879 goto exit;
1880 return_value = pyexpat_ParserCreate_impl(module, encoding, namespace_separat or, intern);
1881
1882 exit:
1883 return return_value;
1884 }
1885
1886 static PyObject *
1887 pyexpat_ParserCreate_impl(PyModuleDef *module, const char *encoding, const char *namespace_separator, PyObject *intern)
1888 /*[clinic end generated code: output=31aef56ef8e7a4c3 input=71b9f471aa6f8f86]*/
1889 {
1626 PyObject *result; 1890 PyObject *result;
1627 int intern_decref = 0; 1891 int intern_decref = 0;
1628 static char *kwlist[] = {"encoding", "namespace_separator",
1629 "intern", NULL};
1630 1892
1631 if (!PyArg_ParseTupleAndKeywords(args, kw, "|zzO:ParserCreate", kwlist,
1632 &encoding, &namespace_separator, &intern))
1633 return NULL;
1634 if (namespace_separator != NULL 1893 if (namespace_separator != NULL
1635 && strlen(namespace_separator) > 1) { 1894 && strlen(namespace_separator) > 1) {
1636 PyErr_SetString(PyExc_ValueError, 1895 PyErr_SetString(PyExc_ValueError,
1637 "namespace_separator must be at most one" 1896 "namespace_separator must be at most one"
1638 " character, omitted, or None"); 1897 " character, omitted, or None");
1639 return NULL; 1898 return NULL;
1640 } 1899 }
1641 /* Explicitly passing None means no interning is desired. 1900 /* Explicitly passing None means no interning is desired.
1642 Not passing anything means that a new dictionary is used. */ 1901 Not passing anything means that a new dictionary is used. */
1643 if (intern == Py_None) 1902 if (intern == Py_None)
1644 intern = NULL; 1903 intern = NULL;
1645 else if (intern == NULL) { 1904 else if (intern == NULL) {
1646 intern = PyDict_New(); 1905 intern = PyDict_New();
1647 if (!intern) 1906 if (!intern)
1648 return NULL; 1907 return NULL;
1649 intern_decref = 1; 1908 intern_decref = 1;
1650 } 1909 }
1651 else if (!PyDict_Check(intern)) { 1910 else if (!PyDict_Check(intern)) {
1652 PyErr_SetString(PyExc_TypeError, "intern must be a dictionary"); 1911 PyErr_SetString(PyExc_TypeError, "intern must be a dictionary");
1653 return NULL; 1912 return NULL;
1654 } 1913 }
1655 1914
1656 result = newxmlparseobject(encoding, namespace_separator, intern); 1915 result = newxmlparseobject((char *)encoding, (char *)namespace_separator,
1916 intern);
1657 if (intern_decref) { 1917 if (intern_decref) {
1658 Py_DECREF(intern); 1918 Py_DECREF(intern);
1659 } 1919 }
1660 return result; 1920 return result;
1661 } 1921 }
1662 1922
1923 /*[clinic input]
1924 pyexpat.ErrorString
1925
1926 code: long
1927 /
1928
1929 Returns string error for given number.
1930 [clinic start generated code]*/
1931
1663 PyDoc_STRVAR(pyexpat_ErrorString__doc__, 1932 PyDoc_STRVAR(pyexpat_ErrorString__doc__,
1664 "ErrorString(errno) -> string\n\ 1933 "sig=($module, code)\n"
1665 Returns string error for given number."); 1934 "Returns string error for given number.");
1935
1936 #define PYEXPAT_ERRORSTRING_METHODDEF \
1937 {"ErrorString", (PyCFunction)pyexpat_ErrorString, METH_VARARGS, pyexpat_Erro rString__doc__},
1666 1938
1667 static PyObject * 1939 static PyObject *
1668 pyexpat_ErrorString(PyObject *self, PyObject *args) 1940 pyexpat_ErrorString_impl(PyModuleDef *module, long code);
1941
1942 static PyObject *
1943 pyexpat_ErrorString(PyModuleDef *module, PyObject *args)
1669 { 1944 {
1670 long code = 0; 1945 PyObject *return_value = NULL;
1946 long code;
1671 1947
1672 if (!PyArg_ParseTuple(args, "l:ErrorString", &code)) 1948 if (!PyArg_ParseTuple(args,
1673 return NULL; 1949 "l:ErrorString",
1950 &code))
1951 goto exit;
1952 return_value = pyexpat_ErrorString_impl(module, code);
1953
1954 exit:
1955 return return_value;
1956 }
1957
1958 static PyObject *
1959 pyexpat_ErrorString_impl(PyModuleDef *module, long code)
1960 /*[clinic end generated code: output=3dff3c098378df72 input=cc67de010d9e62b3]*/
1961 {
1674 return Py_BuildValue("z", XML_ErrorString((int)code)); 1962 return Py_BuildValue("z", XML_ErrorString((int)code));
1675 } 1963 }
1676 1964
1677 /* List of methods defined in the module */ 1965 /* List of methods defined in the module */
1678 1966
1679 static struct PyMethodDef pyexpat_methods[] = { 1967 static struct PyMethodDef pyexpat_methods[] = {
1680 {"ParserCreate", (PyCFunction)pyexpat_ParserCreate, 1968 PYEXPAT_PARSERCREATE_METHODDEF
1681 METH_VARARGS|METH_KEYWORDS, pyexpat_ParserCreate__doc__}, 1969 PYEXPAT_ERRORSTRING_METHODDEF
1682 {"ErrorString", (PyCFunction)pyexpat_ErrorString, 1970 {NULL, NULL} /* sentinel */
1683 METH_VARARGS, pyexpat_ErrorString__doc__},
1684
1685 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
1686 }; 1971 };
1687 1972
1688 /* Module docstring */ 1973 /* Module docstring */
1689 1974
1690 PyDoc_STRVAR(pyexpat_module_documentation, 1975 PyDoc_STRVAR(pyexpat_module_documentation,
1691 "Python wrapper for Expat parser."); 1976 "Python wrapper for Expat parser.");
1692 1977
1693 /* Initialization function for the module */ 1978 /* Initialization function for the module */
1694 1979
1695 #ifndef MODULE_NAME 1980 #ifndef MODULE_NAME
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 (xmlhandlersetter)XML_SetAttlistDeclHandler, 2336 (xmlhandlersetter)XML_SetAttlistDeclHandler,
2052 (xmlhandler)my_AttlistDeclHandler}, 2337 (xmlhandler)my_AttlistDeclHandler},
2053 #if XML_COMBINED_VERSION >= 19504 2338 #if XML_COMBINED_VERSION >= 19504
2054 {"SkippedEntityHandler", 2339 {"SkippedEntityHandler",
2055 (xmlhandlersetter)XML_SetSkippedEntityHandler, 2340 (xmlhandlersetter)XML_SetSkippedEntityHandler,
2056 (xmlhandler)my_SkippedEntityHandler}, 2341 (xmlhandler)my_SkippedEntityHandler},
2057 #endif 2342 #endif
2058 2343
2059 {NULL, NULL, NULL} /* sentinel */ 2344 {NULL, NULL, NULL} /* sentinel */
2060 }; 2345 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+