16e164f
To: vim_dev@googlegroups.com
16e164f
Subject: Patch 7.4.905
16e164f
Fcc: outbox
16e164f
From: Bram Moolenaar <Bram@moolenaar.net>
16e164f
Mime-Version: 1.0
16e164f
Content-Type: text/plain; charset=UTF-8
16e164f
Content-Transfer-Encoding: 8bit
16e164f
------------
16e164f
16e164f
Patch 7.4.905
16e164f
Problem:    Python interface can produce error "vim.message' object has no
16e164f
            attribute 'isatty'".
16e164f
Solution:   Add dummy isatty(), readable(), etc. (closes #464)
16e164f
Files:      src/if_py_both.h, src/testdir/test86.in, src/testdir/test86.ok,
16e164f
            src/testdir/test87.in, src/testdir/test87.ok
16e164f
16e164f
16e164f
*** ../vim-7.4.904/src/if_py_both.h	2015-02-10 18:41:53.006111926 +0100
16e164f
--- src/if_py_both.h	2015-11-02 13:21:24.911033469 +0100
16e164f
***************
16e164f
*** 465,484 ****
16e164f
  }
16e164f
  
16e164f
      static PyObject *
16e164f
! OutputFlush(PyObject *self UNUSED)
16e164f
  {
16e164f
      /* do nothing */
16e164f
      Py_INCREF(Py_None);
16e164f
      return Py_None;
16e164f
  }
16e164f
  
16e164f
  /***************/
16e164f
  
16e164f
  static struct PyMethodDef OutputMethods[] = {
16e164f
      /* name,	    function,				calling,	doc */
16e164f
      {"write",	    (PyCFunction)OutputWrite,		METH_O,		""},
16e164f
      {"writelines",  (PyCFunction)OutputWritelines,	METH_O,		""},
16e164f
!     {"flush",	    (PyCFunction)OutputFlush,		METH_NOARGS,	""},
16e164f
      {"__dir__",	    (PyCFunction)OutputDir,		METH_NOARGS,	""},
16e164f
      { NULL,	    NULL,				0,		NULL}
16e164f
  };
16e164f
--- 465,505 ----
16e164f
  }
16e164f
  
16e164f
      static PyObject *
16e164f
! AlwaysNone(PyObject *self UNUSED)
16e164f
  {
16e164f
      /* do nothing */
16e164f
      Py_INCREF(Py_None);
16e164f
      return Py_None;
16e164f
  }
16e164f
  
16e164f
+     static PyObject *
16e164f
+ AlwaysFalse(PyObject *self UNUSED)
16e164f
+ {
16e164f
+     /* do nothing */
16e164f
+     Py_INCREF(Py_False);
16e164f
+     return Py_False;
16e164f
+ }
16e164f
+ 
16e164f
+     static PyObject *
16e164f
+ AlwaysTrue(PyObject *self UNUSED)
16e164f
+ {
16e164f
+     /* do nothing */
16e164f
+     Py_INCREF(Py_True);
16e164f
+     return Py_True;
16e164f
+ }
16e164f
+ 
16e164f
  /***************/
16e164f
  
16e164f
  static struct PyMethodDef OutputMethods[] = {
16e164f
      /* name,	    function,				calling,	doc */
16e164f
      {"write",	    (PyCFunction)OutputWrite,		METH_O,		""},
16e164f
      {"writelines",  (PyCFunction)OutputWritelines,	METH_O,		""},
16e164f
!     {"flush",	    (PyCFunction)AlwaysNone,		METH_NOARGS,	""},
16e164f
!     {"close",	    (PyCFunction)AlwaysNone,		METH_NOARGS,	""},
16e164f
!     {"isatty",	    (PyCFunction)AlwaysFalse,		METH_NOARGS,	""},
16e164f
!     {"readable",    (PyCFunction)AlwaysFalse,		METH_NOARGS,	""},
16e164f
!     {"seekable",    (PyCFunction)AlwaysFalse,		METH_NOARGS,	""},
16e164f
!     {"writable",    (PyCFunction)AlwaysTrue,		METH_NOARGS,	""},
16e164f
      {"__dir__",	    (PyCFunction)OutputDir,		METH_NOARGS,	""},
16e164f
      { NULL,	    NULL,				0,		NULL}
16e164f
  };
16e164f
*** ../vim-7.4.904/src/testdir/test86.in	2014-09-29 18:08:54.587952270 +0200
16e164f
--- src/testdir/test86.in	2015-11-02 13:19:04.276680955 +0100
16e164f
***************
16e164f
*** 1094,1101 ****
16e164f
--- 1094,1113 ----
16e164f
  ee('del sys.stdout.softspace')
16e164f
  number_test('sys.stdout.softspace = %s', unsigned=True)
16e164f
  number_test('sys.stderr.softspace = %s', unsigned=True)
16e164f
+ ee('assert sys.stdout.isatty()==False')
16e164f
+ ee('assert sys.stdout.seekable()==False')
16e164f
+ ee('sys.stdout.close()')
16e164f
+ ee('sys.stdout.flush()')
16e164f
+ ee('assert sys.stderr.isatty()==False')
16e164f
+ ee('assert sys.stderr.seekable()==False')
16e164f
+ ee('sys.stderr.close()')
16e164f
+ ee('sys.stderr.flush()')
16e164f
  ee('sys.stdout.attr = None')
16e164f
  cb.append(">> OutputWrite")
16e164f
+ ee('assert sys.stdout.writable()==True')
16e164f
+ ee('assert sys.stdout.readable()==False')
16e164f
+ ee('assert sys.stderr.writable()==True')
16e164f
+ ee('assert sys.stderr.readable()==False')
16e164f
  ee('sys.stdout.write(None)')
16e164f
  cb.append(">> OutputWriteLines")
16e164f
  ee('sys.stdout.writelines(None)')
16e164f
*** ../vim-7.4.904/src/testdir/test86.ok	2014-03-12 15:26:36.428714415 +0100
16e164f
--- src/testdir/test86.ok	2015-11-02 13:19:04.280680909 +0100
16e164f
***************
16e164f
*** 447,453 ****
16e164f
  dictionary:__dir__,__members__,get,has_key,items,keys,locked,pop,popitem,scope,update,values
16e164f
  list:__dir__,__members__,extend,locked
16e164f
  function:__dir__,__members__,softspace
16e164f
! output:__dir__,__members__,flush,softspace,write,writelines
16e164f
  {}
16e164f
  {'a': 1}
16e164f
  {'a': 1}
16e164f
--- 447,453 ----
16e164f
  dictionary:__dir__,__members__,get,has_key,items,keys,locked,pop,popitem,scope,update,values
16e164f
  list:__dir__,__members__,extend,locked
16e164f
  function:__dir__,__members__,softspace
16e164f
! output:__dir__,__members__,close,flush,isatty,readable,seekable,softspace,writable,write,writelines
16e164f
  {}
16e164f
  {'a': 1}
16e164f
  {'a': 1}
16e164f
***************
16e164f
*** 488,495 ****
16e164f
--- 488,507 ----
16e164f
  sys.stderr.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',)
16e164f
  sys.stderr.softspace = -1:ValueError:('number must be greater or equal to zero',)
16e164f
  <<< Finished
16e164f
+ assert sys.stdout.isatty()==False:NOT FAILED
16e164f
+ assert sys.stdout.seekable()==False:NOT FAILED
16e164f
+ sys.stdout.close():NOT FAILED
16e164f
+ sys.stdout.flush():NOT FAILED
16e164f
+ assert sys.stderr.isatty()==False:NOT FAILED
16e164f
+ assert sys.stderr.seekable()==False:NOT FAILED
16e164f
+ sys.stderr.close():NOT FAILED
16e164f
+ sys.stderr.flush():NOT FAILED
16e164f
  sys.stdout.attr = None:AttributeError:('invalid attribute: attr',)
16e164f
  >> OutputWrite
16e164f
+ assert sys.stdout.writable()==True:NOT FAILED
16e164f
+ assert sys.stdout.readable()==False:NOT FAILED
16e164f
+ assert sys.stderr.writable()==True:NOT FAILED
16e164f
+ assert sys.stderr.readable()==False:NOT FAILED
16e164f
  sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',)
16e164f
  >> OutputWriteLines
16e164f
  sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",)
16e164f
*** ../vim-7.4.904/src/testdir/test87.in	2014-09-29 18:08:54.591952271 +0200
16e164f
--- src/testdir/test87.in	2015-11-02 13:19:04.280680909 +0100
16e164f
***************
16e164f
*** 1071,1078 ****
16e164f
--- 1071,1090 ----
16e164f
  ee('del sys.stdout.softspace')
16e164f
  number_test('sys.stdout.softspace = %s', unsigned=True)
16e164f
  number_test('sys.stderr.softspace = %s', unsigned=True)
16e164f
+ ee('assert sys.stdout.isatty()==False')
16e164f
+ ee('assert sys.stdout.seekable()==False')
16e164f
+ ee('sys.stdout.close()')
16e164f
+ ee('sys.stdout.flush()')
16e164f
+ ee('assert sys.stderr.isatty()==False')
16e164f
+ ee('assert sys.stderr.seekable()==False')
16e164f
+ ee('sys.stderr.close()')
16e164f
+ ee('sys.stderr.flush()')
16e164f
  ee('sys.stdout.attr = None')
16e164f
  cb.append(">> OutputWrite")
16e164f
+ ee('assert sys.stdout.writable()==True')
16e164f
+ ee('assert sys.stdout.readable()==False')
16e164f
+ ee('assert sys.stderr.writable()==True')
16e164f
+ ee('assert sys.stderr.readable()==False')
16e164f
  ee('sys.stdout.write(None)')
16e164f
  cb.append(">> OutputWriteLines")
16e164f
  ee('sys.stdout.writelines(None)')
16e164f
*** ../vim-7.4.904/src/testdir/test87.ok	2014-03-12 15:26:36.432714415 +0100
16e164f
--- src/testdir/test87.ok	2015-11-02 13:19:04.280680909 +0100
16e164f
***************
16e164f
*** 447,453 ****
16e164f
  dictionary:__dir__,get,has_key,items,keys,locked,pop,popitem,scope,update,values
16e164f
  list:__dir__,extend,locked
16e164f
  function:__dir__,softspace
16e164f
! output:__dir__,flush,softspace,write,writelines
16e164f
  {}
16e164f
  {'a': 1}
16e164f
  {'a': 1}
16e164f
--- 447,453 ----
16e164f
  dictionary:__dir__,get,has_key,items,keys,locked,pop,popitem,scope,update,values
16e164f
  list:__dir__,extend,locked
16e164f
  function:__dir__,softspace
16e164f
! output:__dir__,close,flush,isatty,readable,seekable,softspace,writable,write,writelines
16e164f
  {}
16e164f
  {'a': 1}
16e164f
  {'a': 1}
16e164f
***************
16e164f
*** 488,495 ****
16e164f
--- 488,507 ----
16e164f
  sys.stderr.softspace = None:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got NoneType',))
16e164f
  sys.stderr.softspace = -1:(<class 'ValueError'>, ValueError('number must be greater or equal to zero',))
16e164f
  <<< Finished
16e164f
+ assert sys.stdout.isatty()==False:NOT FAILED
16e164f
+ assert sys.stdout.seekable()==False:NOT FAILED
16e164f
+ sys.stdout.close():NOT FAILED
16e164f
+ sys.stdout.flush():NOT FAILED
16e164f
+ assert sys.stderr.isatty()==False:NOT FAILED
16e164f
+ assert sys.stderr.seekable()==False:NOT FAILED
16e164f
+ sys.stderr.close():NOT FAILED
16e164f
+ sys.stderr.flush():NOT FAILED
16e164f
  sys.stdout.attr = None:(<class 'AttributeError'>, AttributeError('invalid attribute: attr',))
16e164f
  >> OutputWrite
16e164f
+ assert sys.stdout.writable()==True:NOT FAILED
16e164f
+ assert sys.stdout.readable()==False:NOT FAILED
16e164f
+ assert sys.stderr.writable()==True:NOT FAILED
16e164f
+ assert sys.stderr.readable()==False:NOT FAILED
16e164f
  sys.stdout.write(None):(<class 'TypeError'>, TypeError("Can't convert 'NoneType' object to str implicitly",))
16e164f
  >> OutputWriteLines
16e164f
  sys.stdout.writelines(None):(<class 'TypeError'>, TypeError("'NoneType' object is not iterable",))
16e164f
*** ../vim-7.4.904/src/version.c	2015-11-02 12:50:49.760534351 +0100
16e164f
--- src/version.c	2015-11-02 13:27:03.923061723 +0100
16e164f
***************
16e164f
*** 743,744 ****
16e164f
--- 743,746 ----
16e164f
  {   /* Add new patch number below this line */
16e164f
+ /**/
16e164f
+     905,
16e164f
  /**/
16e164f
16e164f
-- 
16e164f
hundred-and-one symptoms of being an internet addict:
16e164f
78. You find yourself dialing IP numbers on the phone.
16e164f
16e164f
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
16e164f
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
16e164f
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
16e164f
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///