commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-144-ge3ef44e


From: Wojciech Polak
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-144-ge3ef44e
Date: Sun, 10 Oct 2010 20:03:12 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=e3ef44efce74604bf62cb630f172226afa91b76c

The branch, master has been updated
       via  e3ef44efce74604bf62cb630f172226afa91b76c (commit)
      from  4f9d95ae16167f61c74af38b564b34c2715bba1d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e3ef44efce74604bf62cb630f172226afa91b76c
Author: Wojciech Polak <address@hidden>
Date:   Sun Oct 10 21:56:48 2010 +0200

    Update Python API and the examples.
    
    * python/libmu_py/folder.c (api_folder_set_stream): Remove.
    * python/libmu_py/message.c (api_message_set_stream): Remove.
    * python/libmu_py/stream.c (api_stream_ref, api_stream_unref): Add.
    (api_stream_sequential_readline, api_stream_sequential_write): Remove.

-----------------------------------------------------------------------

Summary of changes:
 examples/python/iconv.py    |    6 +-
 examples/python/mimetest.py |    4 +-
 examples/python/msg-send.py |    2 +-
 python/libmu_py/body.c      |    2 +-
 python/libmu_py/folder.c    |   25 +---------
 python/libmu_py/message.c   |   25 ----------
 python/libmu_py/stream.c    |  110 ++++++++++++++++---------------------------
 python/mailutils/stream.py  |   33 +++++--------
 8 files changed, 60 insertions(+), 147 deletions(-)

diff --git a/examples/python/iconv.py b/examples/python/iconv.py
index d1d77c9..ab91ca8 100644
--- a/examples/python/iconv.py
+++ b/examples/python/iconv.py
@@ -22,19 +22,19 @@ if len (sys.argv) != 3:
     print "usage: %s from-code to-code" % sys.argv[0]
     sys.exit (0)
 
-sti = stream.StdioStream (sys.stdin)
+sti = stream.StdioStream (stream.MU_STDIN_FD)
 sti.open ()
 
 cvt = filter.FilterIconvStream (sti, sys.argv[1], sys.argv[2])
 cvt.open ()
 
-out = stream.StdioStream (sys.stdout, 0)
+out = stream.StdioStream (stream.MU_STDOUT_FD, 0)
 out.open ()
 
 total = 0
 while True:
     buf = cvt.read (total)
-    out.sequential_write (buf)
+    out.write (buf)
     total += cvt.read_count
     if not cvt.read_count:
         break
diff --git a/examples/python/mimetest.py b/examples/python/mimetest.py
index 7ec6ee2..c63c868 100644
--- a/examples/python/mimetest.py
+++ b/examples/python/mimetest.py
@@ -77,11 +77,9 @@ def message_display_parts (msg, indent):
           print "%*.*sBegin" % (indent, indent, '')
 
          flt = filter.FilterStream (part.body.get_stream (), encoding)
-          offset = 0
 
           while True:
-              buf = flt.readline (offset)
-              offset += flt.read_count
+              buf = flt.readline ()
               if not flt.read_count:
                   break
               print "%*.*s%s" % (indent, indent, '', buf),
diff --git a/examples/python/msg-send.py b/examples/python/msg-send.py
index cbca586..bb13097 100644
--- a/examples/python/msg-send.py
+++ b/examples/python/msg-send.py
@@ -59,7 +59,7 @@ if optfrom:
 if args:
     to = address.Address (args)
 
-sti = stream.StdioStream (sys.stdin, stream.MU_STREAM_SEEKABLE)
+sti = stream.StdioStream (stream.MU_STDIN_FD, stream.MU_STREAM_SEEKABLE)
 sti.open ()
 
 msg = message.Message ()
diff --git a/python/libmu_py/body.c b/python/libmu_py/body.c
index 8ddc517..3ac16f9 100644
--- a/python/libmu_py/body.c
+++ b/python/libmu_py/body.c
@@ -116,7 +116,7 @@ api_body_get_stream (PyObject *self, PyObject *args)
 
   Py_INCREF (py_stm);
 
-  status = mu_body_get_stream (py_body->body, &py_stm->stm);
+  status = mu_body_get_streamref (py_body->body, &py_stm->stm);
   return status_object (status, (PyObject *)py_stm);
 }
 
diff --git a/python/libmu_py/folder.c b/python/libmu_py/folder.c
index e476efa..41be5ca 100644
--- a/python/libmu_py/folder.c
+++ b/python/libmu_py/folder.c
@@ -140,31 +140,11 @@ api_folder_get_stream (PyObject *self, PyObject *args)
 
   Py_INCREF (py_stm);
 
-  status = mu_folder_get_stream (py_folder->folder, &py_stm->stm);
+  status = mu_folder_get_streamref (py_folder->folder, &py_stm->stm);
   return status_object (status, (PyObject *)py_stm);
 }
 
 static PyObject *
-api_folder_set_stream (PyObject *self, PyObject *args)
-{
-  int status;
-  PyFolder *py_folder;
-  PyStream *py_stm;
-
-  if (!PyArg_ParseTuple (args, "O!O", &PyFolderType, &py_folder, &py_stm))
-    return NULL;
-
-  if (!PyStream_Check ((PyObject *)py_stm))
-    {
-      PyErr_SetString (PyExc_TypeError, "");
-      return NULL;
-    }
-
-  status = mu_folder_set_stream (py_folder->folder, py_stm->stm);
-  return _ro (PyInt_FromLong (status));
-}
-
-static PyObject *
 api_folder_get_authority (PyObject *self, PyObject *args)
 {
   int status;
@@ -276,9 +256,6 @@ static PyMethodDef methods[] = {
   { "get_stream", (PyCFunction) api_folder_get_stream, METH_VARARGS,
     "" },
 
-  { "set_stream", (PyCFunction) api_folder_set_stream, METH_VARARGS,
-    "" },
-
   { "get_authority", (PyCFunction) api_folder_get_authority, METH_VARARGS,
     "" },
 
diff --git a/python/libmu_py/message.c b/python/libmu_py/message.c
index 78600cf..ab05639 100644
--- a/python/libmu_py/message.c
+++ b/python/libmu_py/message.c
@@ -331,28 +331,6 @@ api_message_unencapsulate (PyObject *self, PyObject *args)
   return status_object (status, (PyObject *)py_unen);
 }
 
-static PyObject *
-api_message_set_stream (PyObject *self, PyObject *args)
-{
-  int status;
-  PyMessage *py_msg;
-  PyStream *py_stm;
-
-  if (!PyArg_ParseTuple (args, "O!O", &PyMessageType, &py_msg, &py_stm))
-    return NULL;
-
-  if (!PyStream_Check ((PyObject *)py_stm))
-    {
-      PyErr_SetString (PyExc_TypeError, "");
-      return NULL;
-    }
-
-  status = mu_message_set_stream (py_msg->msg, py_stm->stm, NULL);
-  py_stm->stm = NULL;
-
-  return _ro (PyInt_FromLong (status));
-}
-
 static PyMethodDef methods[] = {
   { "create", (PyCFunction) api_message_create, METH_VARARGS,
     "Create message." },
@@ -402,9 +380,6 @@ static PyMethodDef methods[] = {
   { "unencapsulate", (PyCFunction) api_message_unencapsulate,
     METH_VARARGS, "" },
 
-  { "set_stream", (PyCFunction) api_message_set_stream, METH_VARARGS,
-    "" },
-
   { NULL, NULL, 0, NULL }
 };
 
diff --git a/python/libmu_py/stream.c b/python/libmu_py/stream.c
index 4767376..fdcbcca 100644
--- a/python/libmu_py/stream.c
+++ b/python/libmu_py/stream.c
@@ -115,20 +115,13 @@ api_file_stream_create (PyObject *self, PyObject *args)
 static PyObject *
 api_stdio_stream_create (PyObject *self, PyObject *args)
 {
-  int status, flags;
-  FILE *fp;
+  int status, fd, flags;
   PyStream *py_stm;
-  PyFileObject *py_file;
 
-  if (!PyArg_ParseTuple (args, "O!O!i",
-                        &PyStreamType, &py_stm,
-                        &PyFile_Type, &py_file,
-                        &flags))
+  if (!PyArg_ParseTuple (args, "O!ii", &PyStreamType, &py_stm, &fd, &flags))
     return NULL;
 
-  fp = PyFile_AsFile ((PyObject *)py_file);
-
-  status = mu_stdio_stream_create (&py_stm->stm, fp, flags);
+  status = mu_stdio_stream_create (&py_stm->stm, fd, flags);
   return _ro (PyInt_FromLong (status));
 }
 
@@ -166,6 +159,30 @@ api_filter_prog_stream_create (PyObject *self, PyObject 
*args)
 }
 
 static PyObject *
+api_stream_ref (PyObject *self, PyObject *args)
+{
+  PyStream *py_stm;
+
+  if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
+    return NULL;
+
+  mu_stream_ref (py_stm->stm);
+  return _ro (Py_None);
+}
+
+static PyObject *
+api_stream_unref (PyObject *self, PyObject *args)
+{
+  PyStream *py_stm;
+
+  if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
+    return NULL;
+
+  mu_stream_unref (py_stm->stm);
+  return _ro (Py_None);
+}
+
+static PyObject *
 api_stream_destroy (PyObject *self, PyObject *args)
 {
   PyStream *py_stm;
@@ -173,7 +190,7 @@ api_stream_destroy (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
     return NULL;
 
-  mu_stream_destroy (&py_stm->stm, NULL);
+  mu_stream_destroy (&py_stm->stm);
   return _ro (Py_None);
 }
 
@@ -233,7 +250,6 @@ static PyObject *
 api_stream_read (PyObject *self, PyObject *args)
 {
   int status;
-  size_t offset;
   size_t read_count;
   char rbuf[1024];
   PyObject *py_ret;
@@ -241,11 +257,10 @@ api_stream_read (PyObject *self, PyObject *args)
 
   memset (rbuf, 0, sizeof (rbuf));
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &offset))
+  if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
     return NULL;
 
-  status = mu_stream_read (py_stm->stm, rbuf, sizeof (rbuf), offset,
-                          &read_count);
+  status = mu_stream_read (py_stm->stm, rbuf, sizeof (rbuf), &read_count);
 
   py_ret = PyTuple_New (3);
   PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
@@ -258,17 +273,14 @@ static PyObject *
 api_stream_write (PyObject *self, PyObject *args)
 {
   int status;
-  size_t offset;
-  size_t write_count;
   char *wbuf;
+  size_t size, write_count;
   PyStream *py_stm;
 
-  if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
-                        &wbuf, &offset))
+  if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm, &wbuf, &size))
     return NULL;
 
-  status = mu_stream_write (py_stm->stm, wbuf, strlen (wbuf), offset,
-                           &write_count);
+  status = mu_stream_write (py_stm->stm, wbuf, size, &write_count);
   return status_object (status, PyInt_FromLong (write_count));
 }
 
@@ -276,31 +288,6 @@ static PyObject *
 api_stream_readline (PyObject *self, PyObject *args)
 {
   int status;
-  size_t offset;
-  size_t read_count;
-  char rbuf[1024];
-  PyObject *py_ret;
-  PyStream *py_stm;
-
-  memset (rbuf, 0, sizeof (rbuf));
-
-  if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &offset))
-    return NULL;
-
-  status = mu_stream_readline (py_stm->stm, rbuf, sizeof (rbuf), offset,
-                              &read_count);
-
-  py_ret = PyTuple_New (3);
-  PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
-  PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
-  PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
-  return _ro (py_ret);
-}
-
-static PyObject *
-api_stream_sequential_readline (PyObject *self, PyObject *args)
-{
-  int status;
   size_t read_count;
   char rbuf[1024];
   PyObject *py_ret;
@@ -311,8 +298,7 @@ api_stream_sequential_readline (PyObject *self, PyObject 
*args)
   if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
     return NULL;
 
-  status = mu_stream_sequential_readline (py_stm->stm, rbuf, sizeof (rbuf),
-                                         &read_count);
+  status = mu_stream_readline (py_stm->stm, rbuf, sizeof (rbuf), &read_count);
 
   py_ret = PyTuple_New (3);
   PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
@@ -321,22 +307,6 @@ api_stream_sequential_readline (PyObject *self, PyObject 
*args)
   return _ro (py_ret);
 }
 
-static PyObject *
-api_stream_sequential_write (PyObject *self, PyObject *args)
-{
-  int status;
-  char *wbuf;
-  size_t size;
-  PyStream *py_stm;
-
-  if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm, &wbuf,
-                        &size))
-    return NULL;
-
-  status = mu_stream_sequential_write (py_stm->stm, wbuf, size);
-  return _ro (PyInt_FromLong (status));
-}
-
 static PyMethodDef methods[] = {
   { "tcp_stream_create", (PyCFunction) api_tcp_stream_create, METH_VARARGS,
     "" },
@@ -354,6 +324,12 @@ static PyMethodDef methods[] = {
     (PyCFunction) api_filter_prog_stream_create, METH_VARARGS,
     "" },
 
+  { "ref", (PyCFunction) api_stream_ref, METH_VARARGS,
+    "" },
+
+  { "unref", (PyCFunction) api_stream_unref, METH_VARARGS,
+    "" },
+
   { "destroy", (PyCFunction) api_stream_destroy, METH_VARARGS,
     "" },
 
@@ -378,12 +354,6 @@ static PyMethodDef methods[] = {
   { "readline", (PyCFunction) api_stream_readline, METH_VARARGS,
     "" },
 
-  { "sequential_readline", (PyCFunction) api_stream_sequential_readline,
-    METH_VARARGS, "" },
-
-  { "sequential_write", (PyCFunction) api_stream_sequential_write,
-    METH_VARARGS, "" },
-
   { NULL, NULL, 0, NULL }
 };
 
diff --git a/python/mailutils/stream.py b/python/mailutils/stream.py
index dc909cb..a0edfc9 100644
--- a/python/mailutils/stream.py
+++ b/python/mailutils/stream.py
@@ -36,6 +36,10 @@ MU_STREAM_IROTH =       0x00004000
 MU_STREAM_IWOTH =       0x00008000
 MU_STREAM_IMASK =       0x0000F000
 
+MU_STDIN_FD  = 0
+MU_STDOUT_FD = 1
+MU_STDERR_FD = 2
+
 class Stream:
     __refcount = 0
 
@@ -80,36 +84,25 @@ class Stream:
         if status:
             raise StreamError (status)
 
-    def read (self, offset = 0):
-        status, rbuf, self.read_count = stream.read (self.stm, offset)
+    def read (self):
+        status, rbuf, self.read_count = stream.read (self.stm)
         if status:
             raise StreamError (status)
         return rbuf
 
-    def write (self, wbuf, offset = 0):
-        status, self.write_count = stream.write (self.stm, wbuf, offset)
-        if status:
-            raise StreamError (status)
-
-    def readline (self, offset = 0):
-        status, rbuf, self.read_count = stream.readline (self.stm, offset)
+    def write (self, wbuf, size=None):
+        if size == None:
+            size = len (wbuf)
+        status, self.write_count = stream.write (self.stm, wbuf, size)
         if status:
             raise StreamError (status)
-        return rbuf
 
-    def sequential_readline (self):
+    def readline (self):
         status, rbuf, self.read_count = stream.readline (self.stm)
         if status:
             raise StreamError (status)
         return rbuf
 
-    def sequential_write (self, wbuf, size = None):
-        if size == None:
-            size = len (wbuf)
-        status = stream.sequential_write (self.stm, wbuf, size)
-        if status:
-            raise StreamError (status)
-
 class TcpStream (Stream):
     def __init__ (self, host, port, flags = MU_STREAM_READ):
         Stream.__init__ (self)
@@ -125,9 +118,9 @@ class FileStream (Stream):
             raise StreamError (status)
 
 class StdioStream (Stream):
-    def __init__ (self, file, flags = MU_STREAM_READ):
+    def __init__ (self, fd=MU_STDIN_FD, flags=MU_STREAM_READ):
         Stream.__init__ (self)
-        status = stream.stdio_stream_create (self.stm, file, flags)
+        status = stream.stdio_stream_create (self.stm, fd, flags)
         if status:
             raise StreamError (status)
 


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]