[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.236,2.237

Tim Peters tim_one@users.sourceforge.net
Wed, 12 Sep 2001 22:38:58 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv20497/python/Python

Modified Files:
	bltinmodule.c 
Log Message:
SF bug [#460467] file objects should be subclassable.
Preliminary support.  What's here works, but needs fine-tuning.


Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.236
retrieving revision 2.237
diff -C2 -d -r2.236 -r2.237
*** bltinmodule.c	2001/09/06 21:55:46	2.236
--- bltinmodule.c	2001/09/13 05:38:56	2.237
***************
*** 1193,1221 ****
  builtin_open(PyObject *self, PyObject *args)
  {
! 	char *name = NULL;
! 	char *mode = "r";
! 	int bufsize = -1;
! 	PyObject *f;
! 
! 	if (!PyArg_ParseTuple(args, "et|si:open", Py_FileSystemDefaultEncoding, 
! 	                      &name, &mode, &bufsize))
! 		return NULL;
! 	f = PyFile_FromString(name, mode);
! 	PyMem_Free(name); /* free the encoded string */
! 	if (f != NULL)
! 		PyFile_SetBufSize(f, bufsize);
! 	return f;
  }
  
  static char open_doc[] =
! "open(filename[, mode[, buffering]]) -> file object\n\
! \n\
! Open a file.  The mode can be 'r', 'w' or 'a' for reading (default),\n\
! writing or appending.  The file will be created if it doesn't exist\n\
! when opened for writing or appending; it will be truncated when\n\
! opened for writing.  Add a 'b' to the mode for binary files.\n\
! Add a '+' to the mode to allow simultaneous reading and writing.\n\
! If the buffering argument is given, 0 means unbuffered, 1 means line\n\
! buffered, and larger numbers specify the buffer size.";
  
  
--- 1193,1210 ----
  builtin_open(PyObject *self, PyObject *args)
  {
! 	return PyFile_Type.tp_new(&PyFile_Type, args, NULL);
  }
  
+ /* XXX Keep this in synch with file_doc in fileobject.c. */
  static char open_doc[] =
! "open(name[, mode[, buffering]]) -> file object\n"
! "\n"
! "Open a file.  The mode can be 'r', 'w' or 'a' for reading (default),\n"
! "writing or appending.  The file will be created if it doesn't exist\n"
! "when opened for writing or appending; it will be truncated when\n"
! "opened for writing.  Add a 'b' to the mode for binary files.\n"
! "Add a '+' to the mode to allow simultaneous reading and writing.\n"
! "If the buffering argument is given, 0 means unbuffered, 1 means line\n"
! "buffered, and larger numbers specify the buffer size.";
  
  
***************
*** 1894,1897 ****
--- 1883,1888 ----
  		return NULL;
  	if (PyDict_SetItemString(dict, "type", (PyObject *) &PyType_Type) < 0)
+ 		return NULL;
+ 	if (PyDict_SetItemString(dict, "file", (PyObject *) &PyFile_Type) < 0)
  		return NULL;
  #ifdef Py_USING_UNICODE