make new call back udefined general entity callback py33
authorrobin
Mon, 18 Nov 2013 12:36:02 +0000
branchpy33
changeset 21 0e2e76932beb
parent 20 825aedf5dd22
child 22 d1a26617d06b
make new call back udefined general entity callback
src/pyRXP.c
src/rxp/xmlparser.c
src/rxp/xmlparser.h
test/testRXPbasic.py
--- a/src/pyRXP.c	Mon Nov 18 10:48:33 2013 +0000
+++ b/src/pyRXP.c	Mon Nov 18 12:36:02 2013 +0000
@@ -43,7 +43,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	PyObject		*warnCB, *eoCB, *ucrCB, *srcName, *fourth, *__module__;
+	PyObject		*warnCB, *eoCB, *ugeCB, *srcName, *fourth, *__module__;
 	int				flags[2];
 	} pyRXPParserObject;
 
@@ -218,9 +218,9 @@
             modified URI or a tuple containing a tuple (URI,'text...') to allow\
 			the content itself to be returned. The possibly changed URI\
 			is required.\n\
-        ucrCB    argument should be None or a callable method with\n\
+        ugeCB    argument should be None or a callable method with\n\
             a single argument. This method will be called when undefined\n\
-            character references are seen. The method should return a byte string\n\
+            general entity references are seen. The method should return a byte string\n\
 			containing the definition of the entity\
 \n""\
         fourth  argument should be None (default) or a callable method with\n\
@@ -416,7 +416,7 @@
 		int			warnErr;
 		PyObject*	warnCB;
 		PyObject*	eoCB;
-		PyObject*	ucrCB;
+		PyObject*	ugeCB;
 		PyObject*	fourth;
 		PyObject*	(*Node_New)(ssize_t);
 		int			(*SetItem)(PyObject*, Py_ssize_t, PyObject*);
@@ -823,7 +823,7 @@
 		}
 }
 
-static Char *myUCRCB(Char *name, int namelen, void *info)
+static Char *myUGECB(Char *name, int namelen, void *info)
 {
 	ParserDetails*	pd=(ParserDetails*)info;
 	PyObject	*arglist;
@@ -835,12 +835,12 @@
 	int			err, ir;
 	unsigned char	*s;
 
-	if(pd->ucrCB==Py_None) return r;
+	if(pd->ugeCB==Py_None) return r;
 	uname = PyUnicode_DecodeUTF16((const char *)name, (Py_ssize_t)(sizeof(Char)*namelen), NULL, &g_byteorder);
 	if(!uname) return r;
 	arglist = Py_BuildValue("(O)",uname);
 	Py_DECREF(uname);
-	result = PyEval_CallObject(pd->ucrCB, arglist);
+	result = PyEval_CallObject(pd->ugeCB, arglist);
 	Py_DECREF(arglist);
 	if(result){
 		if(PyBytes_Check(result)){
@@ -912,7 +912,7 @@
 
 	if(!strcmp(name,"warnCB")) return _set_CB(name,&self->warnCB,value);
 	else if(!strcmp(name,"eoCB")) return _set_CB(name,&self->eoCB,value);
-	else if(!strcmp(name,"ucrCB")) return _set_CB(name,&self->ucrCB,value);
+	else if(!strcmp(name,"ugeCB")) return _set_CB(name,&self->ugeCB,value);
 	else if(!strcmp(name,"fourth")){
 		if(value==PPSTATE(self,recordLocation)){
 			return _set_attr(&self->fourth,value);
@@ -978,7 +978,7 @@
 #endif
 	if(self->warnCB) Py_INCREF(self->warnCB);
 	if(self->eoCB) Py_INCREF(self->eoCB);
-	if(self->ucrCB) Py_INCREF(self->ucrCB);
+	if(self->ugeCB) Py_INCREF(self->ugeCB);
 	if(self->fourth) Py_INCREF(self->fourth);
 	if(self->srcName) Py_INCREF(self->srcName);
 
@@ -1012,11 +1012,11 @@
 		CB.warnErr = 0;
 		CB.warnCBF = 0;
 		}
-	if(self->ucrCB && self->ucrCB!=Py_None){
+	if(self->ugeCB && self->ugeCB!=Py_None){
 		CB.eoCB = self->eoCB;
 		}
-	if(self->ucrCB && self->ucrCB!=Py_None){
-		CB.ucrCB = self->ucrCB;
+	if(self->ugeCB && self->ugeCB!=Py_None){
+		CB.ugeCB = self->ugeCB;
 		}
 	CB.fourth = self->fourth;
 
@@ -1026,9 +1026,9 @@
 	if(self->warnCB && self->warnCB!=Py_None){
 		ParserSetWarningCallback(p, myWarnCB);
 		}
-	if(self->ucrCB && self->ucrCB!=Py_None){
-		ParserSetUCRProcArg(p, &CB);
-		ParserSetUCRProc(p, myUCRCB);
+	if(self->ugeCB && self->ugeCB!=Py_None){
+		ParserSetUGEProcArg(p, &CB);
+		ParserSetUGEProc(p, myUGECB);
 		}
 	p->flags[0] = self->flags[0];
 	p->flags[1] = self->flags[1];
@@ -1069,7 +1069,7 @@
 	Py_XDECREF(dsrc);
 	Py_XDECREF(self->warnCB);
 	Py_XDECREF(self->eoCB);
-	Py_XDECREF(self->ucrCB);
+	Py_XDECREF(self->ugeCB);
 	Py_XDECREF(self->fourth);
 	Py_XDECREF(self->srcName);
 	return retVal;
@@ -1157,7 +1157,7 @@
 
 	if(!PyArg_ParseTuple(args, ":Parser")) return NULL;
 	if(!(self = PyObject_NEW(pyRXPParserObject, &pyRXPParserType))) return NULL;
-	self->warnCB = self->eoCB = self->ucrCB = self->fourth = self->srcName = NULL;
+	self->warnCB = self->eoCB = self->ugeCB = self->fourth = self->srcName = NULL;
 #ifdef isPy3
 	self->__module__ = module;
 #else
--- a/src/rxp/xmlparser.c	Mon Nov 18 10:48:33 2013 +0000
+++ b/src/rxp/xmlparser.c	Mon Nov 18 12:36:02 2013 +0000
@@ -644,8 +644,8 @@
     p->dtd_callback_arg = 0;
     p->warning_callback_arg = 0;
     p->entity_opener_arg = 0;
-    p->ucr_proc = 0;
-    p->ucr_proc_arg = 0;
+    p->uge_proc = 0;
+    p->uge_proc_arg = 0;
     p->external_pe_depth = 0;
 
     p->checker = 0;
@@ -758,14 +758,14 @@
     p->entity_opener = opener;
 }
 
-void ParserSetUCRProc(Parser p, CallbackProc cb)
+void ParserSetUGEProc(Parser p, CallbackProc cb)
 {
-    p->ucr_proc = cb;
+    p->uge_proc = cb;
 }
 
-void ParserSetUCRProcArg(Parser p, void *arg)
+void ParserSetUGEProcArg(Parser p, void *arg)
 {
-    p->ucr_proc_arg = arg;
+    p->uge_proc_arg = arg;
 }
 
 #ifndef FOR_LT
@@ -3424,9 +3424,9 @@
 	return transcribe(p, 1 + p->namelen + 1, 1 + p->namelen + 1);
 
     e = FindEntityN(p->dtd, p->name, p->namelen, pe);
-	if(!e && p->ucr_proc){
+	if(!e && p->uge_proc){
 		/*we have a callback let's try it*/
-		Char *ndef=p->ucr_proc(p->name,p->namelen,p->ucr_proc_arg);
+		Char *ndef=p->uge_proc(p->name,p->namelen,p->uge_proc_arg);
 		if(ndef){
 			if(!(e = NewInternalEntityN(p->name, p->namelen, ndef, 0, 0, 0, 0)))
 	    		return error(p, "System error");
--- a/src/rxp/xmlparser.h	Mon Nov 18 10:48:33 2013 +0000
+++ b/src/rxp/xmlparser.h	Mon Nov 18 12:36:02 2013 +0000
@@ -37,7 +37,7 @@
 typedef struct attribute *Attribute;
 typedef struct xbit *XBit;
 typedef void CallbackProc(XBit bit, void *arg);
-typedef Char *UCRProc(Char *name, int namelen, void *arg);
+typedef Char *UGEProc(Char *name, int namelen, void *arg);
 typedef InputSource EntityOpenerProc(Entity e, void *arg);
 
 /* Bits */
@@ -206,8 +206,8 @@
     NF16Checker checker;
     NF16Checker namechecker;    /* entity name and replacement text
                                    checking overlap */
-    UCRProc *ucr_proc;	/*undefined character ref callback*/
-    void *ucr_proc_arg;
+    UGEProc *uge_proc;	/*undefined character ref callback*/
+    void *uge_proc_arg;
 };
 
 XML_API int init_parser(void);
@@ -235,8 +235,8 @@
 XML_API void ParserSetDtdCallbackArg(Parser p, void *arg);
 XML_API void ParserSetWarningCallbackArg(Parser p, void *arg);
 XML_API void ParserSetEntityOpenerArg(Parser p, void *arg);
-XML_API void ParserSetUCRProc(Parser p, UCRProc cb);
-XML_API void ParserSetUCRProcArg(Parser p, void *arg);
+XML_API void ParserSetUGEProc(Parser p, UGEProc cb);
+XML_API void ParserSetUGEProcArg(Parser p, void *arg);
 
 XML_API int ParserPush(Parser p, InputSource source);
 XML_API void ParserPop(Parser p);
--- a/test/testRXPbasic.py	Mon Nov 18 10:48:33 2013 +0000
+++ b/test/testRXPbasic.py	Mon Nov 18 12:36:02 2013 +0000
@@ -15,8 +15,8 @@
 	'aacute': b'\xc3\xa1',
 	'Acirc': b'\xc3\x82',
 	}
-def ucrCB(name):
-	#plogn('ucrCB called with name=%r' % name)
+def ugeCB(name):
+	#plogn('ugeCB called with name=%r' % name)
 	try:
 		return greeks[name]
 	except:
@@ -109,7 +109,7 @@
 	goodTest('''<foo:A xmlns:foo="http://www.foo.org/"><foo:B><foo:C xmlns:foo="http://www.bar.org/"><foo:D>abcd</foo:D></foo:C></foo:B><foo:B/><A>bare A<C>bare C</C><B>bare B</B></A><A xmlns="http://default.reportlab.com/" xmlns:bongo="http://bongo.reportlab.com/">default ns A<bongo:A>bongo A</bongo:A><B>default NS B</B></A></foo:A>''',('{http://www.foo.org/}A', {'xmlns:foo': 'http://www.foo.org/'}, [('{http://www.foo.org/}B', None, [('{http://www.bar.org/}C', {'xmlns:foo': 'http://www.bar.org/'}, [('{http://www.bar.org/}D', None, ['abcd'], None)], None)], None), ('{http://www.foo.org/}B', None, None, None), ('A', None, ['bare A', ('C', None, ['bare C'], None), ('B', None, ['bare B'], None)], None), ('{http://default.reportlab.com/}A', {'xmlns': 'http://default.reportlab.com/', 'xmlns:bongo': 'http://bongo.reportlab.com/'}, ['default ns A', ('{http://bongo.reportlab.com/}A', None, ['bongo A'], None), ('{http://default.reportlab.com/}B', None, ['default NS B'], None)], None)], None),XMLNamespaces=1,ReturnNamespaceAttributes=1)
 	failTest(bigDepth(257),"""error Internal error, stack limit reached!\n""", inOnly=1)
 	failTest('<a>&Aacute;&aacute;</a>','error Error: Undefined entity Aacute\n in unnamed entity at line 1 char 12 of [unknown]\nUndefined entity Aacute\nParse Failed!\n')
-	goodTest('<a>&Aacute;</a>',('a', None, ['\xc1'], None), ucrCB=ucrCB)
+	goodTest('<a>&Aacute;</a>',('a', None, ['\xc1'], None), ugeCB=ugeCB)
 
 def run():
 	#import pyRXP