[4suite-checkins] In 4Suite/Ft/Xml/Xslt/src, files RtfWriter.c

Jeremy Kloth jkloth at 4suite.org
Fri Nov 24 15:04:13 MST 2006


Modified Files:
    RtfWriter.c

Log Message:
Added C implementation of RtfWriter
Moved exception handling of XPath expression errors to the Processor

ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/src/RtfWriter.c.diff?r1=1.1&r2=1.2
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/src/RtfWriter.c?rev=1.2&content-type=text/vnd.viewcvs-markup

Index: RtfWriter.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/Xslt/src/RtfWriter.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -U2 -r1.1 -r1.2
--- RtfWriter.c	24 Nov 2006 20:18:47 -0000	1.1
+++ RtfWriter.c	24 Nov 2006 22:04:13 -0000	1.2
@@ -40,66 +40,4 @@
 static PyObject *xmlns_namespace;
 
-static PyObject *convert_domstring(PyObject *v)
-{
-  if (v == NULL) {
-    PyErr_BadInternalCall();
-    return NULL;
-  }
-  if (v == Py_None || PyUnicode_CheckExact(v)) {
-    Py_INCREF(v);
-    return v;
-  }
-  if (PyUnicode_Check(v)) {
-    return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v),
-                                 PyUnicode_GET_SIZE(v));
-  }
-  return PyUnicode_FromEncodedObject(v, "utf-8", NULL);
-}
-
-PyObject *convert_argument(PyObject *arg, char *name, int null_ok)
-{
-  PyObject *result;
-
-  if (null_ok) {
-    result = convert_domstring(arg);
-    if (result == NULL) {
-      if (PyErr_ExceptionMatches(PyExc_TypeError))
-        PyErr_Format(PyExc_TypeError,
-                     "%s must be None, unicode or UTF-8 string, %.80s found.",
-                     name, arg->ob_type->tp_name);
-    } else if (result != Py_None && PyUnicode_GET_SIZE(result) == 0) {
-      if (PyErr_Warn(PyExc_SyntaxWarning,
-                     "The null string should be None, not empty.") == -1) {
-        /* warnings as exceptions is enabled */
-        Py_DECREF(result);
-        result = NULL;
-      }
-      /* From DOM L3, 1.3.3 XML Namespaces, empty strings are converted to
-         the programming language's null.
-      */
-      Py_DECREF(result);
-      Py_INCREF(Py_None);
-      result = Py_None;
-    }
-  }
-  else if (arg != Py_None) {
-    result = convert_domstring(arg);
-    if (result == NULL) {
-      if (PyErr_ExceptionMatches(PyExc_TypeError))
-        PyErr_Format(PyExc_TypeError,
-                     "%s must be unicode or UTF-8 string, %.80s found.",
-                     name, arg->ob_type->tp_name);
-    }
-  }
-  else {
-    /* arg == Py_None and not null_ok */
-    PyErr_Format(PyExc_TypeError,
-                 "%s must be non-null unicode or UTF-8 string.", name);
-    result = NULL;
-  }
-
-  return result;
-}
-
 static PyTypeObject UnescapedText_Type = {
   /* PyObject_HEAD     */ PyObject_HEAD_INIT(NULL)
@@ -234,9 +172,9 @@
   }
 
-  name = convert_argument(name, "name", 0);
+  name = XmlString_ConvertArgument(name, "name", 0);
   if (name == NULL) {
     return NULL;
   }
-  namespace = convert_argument(namespace, "namespace", 1);
+  namespace = XmlString_ConvertArgument(namespace, "namespace", 1);
   if (namespace == NULL) {
     Py_DECREF(name);
@@ -317,9 +255,9 @@
   if (self->buffer_size && complete_text(self) < 0) return NULL;
 
-  name = convert_argument(name, "name", 0);
+  name = XmlString_ConvertArgument(name, "name", 0);
   if (name == NULL) {
     return NULL;
   }
-  namespace = convert_argument(namespace, "namespace", 1);
+  namespace = XmlString_ConvertArgument(namespace, "namespace", 1);
   if (namespace == NULL) {
     Py_DECREF(name);
@@ -391,14 +329,14 @@
     PyAttrObject *attr;
 
-    name = convert_argument(name, "name", 0);
+    name = XmlString_ConvertArgument(name, "name", 0);
     if (name == NULL) {
       return NULL;
     }
-    value = convert_argument(value, "value", 0);
+    value = XmlString_ConvertArgument(value, "value", 0);
     if (value == NULL) {
       Py_DECREF(name);
       return NULL;
     }
-    namespace = convert_argument(namespace, "namespace", 1);
+    namespace = XmlString_ConvertArgument(namespace, "namespace", 1);
     if (namespace == NULL) {
       Py_DECREF(name);
@@ -454,5 +392,5 @@
   }
 
-  data = convert_argument(data, "data", 0);
+  data = XmlString_ConvertArgument(data, "data", 0);
   if (data == NULL) return NULL;
 
@@ -522,7 +460,7 @@
   }
 
-  target = convert_argument(target, "target", 0);
+  target = XmlString_ConvertArgument(target, "target", 0);
   if (target == NULL) return NULL;
-  data = convert_argument(data, "data", 0);
+  data = XmlString_ConvertArgument(data, "data", 0);
   if (data == NULL) {
     Py_DECREF(target);
@@ -565,5 +503,5 @@
   }
 
-  data = convert_argument(data, "data", 0);
+  data = XmlString_ConvertArgument(data, "data", 0);
   if (data == NULL) return NULL;
 


More information about the 4suite-checkins mailing list