[Python-checkins] CVS: python/dist/src/Mac/Modules hfsplusmodule.c,1.2,1.3

Jack Jansen jackjansen@users.sourceforge.net
Tue, 06 Nov 2001 07:58:02 -0800


Update of /cvsroot/python/python/dist/src/Mac/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv25156/python/Mac/Modules

Modified Files:
	hfsplusmodule.c 
Log Message:
Changed names, added bridge functions to macfs.fsref objects and
generally did things to get it working.

Index: hfsplusmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/hfsplusmodule.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** hfsplusmodule.c	2001/11/06 12:06:39	1.2
--- hfsplusmodule.c	2001/11/06 15:57:59	1.3
***************
*** 1,20 ****
  /*
!   $Log$
!   Revision 1.2  2001/11/06 12:06:39  jackjansen
!   First couple of fixes to make it compile with Universal 3.3.2.
! 
!   Revision 1.8  2001/10/03 17:29:01  ganatra
!   add parent method to FSRef class
! 
!   Revision 1.7  2001/04/13 20:54:19  ganatra
!   More standard format for MacOSError exceptions
! 
!   Revision 1.6  2001/04/11 04:07:40  ganatra
!   Add permissions constants and log header..
! 
  */
  
  
  #include "Python.h"
  #ifdef WITHOUT_FRAMEWORKS
  #include <Files.h>
--- 1,10 ----
  /*
! ** Interface to hfs+ API.
! ** Contributed by Nitin Ganatra.
  */
  
  
  #include "Python.h"
+ #include "pymactoolbox.h"
  #ifdef WITHOUT_FRAMEWORKS
  #include <Files.h>
***************
*** 674,677 ****
--- 664,680 ----
  
  //__________________________________________________________________________________________________
+ static char fsRefObject_as_fsref__doc__[] =
+ "as_fsref() -> macfs.fsref\n\n\
+ Return a macfs.fsref-style object from an hfsplus.fsref style object";
+ 
+ static
+ PyObject *fsRefObject_as_fsref(fsRefObject *self, PyObject *args)
+ {
+ 	if (!PyArg_ParseTuple(args, ""))
+ 		return NULL;
+ 	return PyMac_BuildFSRef(&self->ref);
+ }
+ 
+ //__________________________________________________________________________________________________
  static char fsRefObject_openfork__doc__[] =
  "openfork([resourcefork [,perms]]) -> forkRef\n\n\
***************
*** 976,979 ****
--- 979,983 ----
  	{"openfork", 	(PyCFunction)fsRefObject_openfork,	METH_VARARGS,	fsRefObject_openfork__doc__},
  
+ 	{"as_fsref",	(PyCFunction)fsRefObject_as_fsref,	METH_VARARGS,	fsRefObject_as_fsref__doc__},
  	{NULL,		NULL}
  };
***************
*** 1042,1046 ****
  //____________________________________ MODULE FUNCTIONS ____________________________________________
  //__________________________________________________________________________________________________
! static char fmgrmodule_getcatinfo__doc__[] =
  "getcatinfo(path[,bitmap]) -> Dict\n\n\
  Returns a dictionary of attributes for the given item\n\
--- 1046,1050 ----
  //____________________________________ MODULE FUNCTIONS ____________________________________________
  //__________________________________________________________________________________________________
! static char hfsplusmodule_getcatinfo__doc__[] =
  "getcatinfo(path[,bitmap]) -> Dict\n\n\
  Returns a dictionary of attributes for the given item\n\
***************
*** 1050,1056 ****
  
  static
! PyObject *fmgrmodule_getcatinfo(PyObject *self, PyObject *args)
  {
- 	char *path;
  	PyObject *dict;
  	FSRef ref;
--- 1054,1059 ----
  
  static
! PyObject *hfsplusmodule_getcatinfo(PyObject *self, PyObject *args)
  {
  	PyObject *dict;
  	FSRef ref;
***************
*** 1060,1077 ****
  	FSCatalogInfoBitmap	bitmap = kFSCatInfoGettableInfo;
  
! 	if (!PyArg_ParseTuple(args, "s|l", &path, &bitmap))
  		return NULL;
  
  	Py_BEGIN_ALLOW_THREADS
- 	err = FSPathMakeRef((UInt8 *)path, &ref, NULL);
- 	Py_END_ALLOW_THREADS
- 	if (err != noErr) 
- 		return macos_error_for_call(err, "FSPathMakeRef", path);
- 
- 	Py_BEGIN_ALLOW_THREADS
  	err = FSGetCatalogInfo(&ref, bitmap, &info, &uni, NULL, NULL);
  	Py_END_ALLOW_THREADS
  	if (err != noErr) 
! 		return macos_error_for_call(err, "FSGetCatalogInfo", path);
  
  	dict = dict_from_cataloginfo(bitmap, &info, &uni);
--- 1063,1074 ----
  	FSCatalogInfoBitmap	bitmap = kFSCatInfoGettableInfo;
  
! 	if (!PyArg_ParseTuple(args, "O&|l", PyMac_GetFSRef, &ref, &bitmap))
  		return NULL;
  
  	Py_BEGIN_ALLOW_THREADS
  	err = FSGetCatalogInfo(&ref, bitmap, &info, &uni, NULL, NULL);
  	Py_END_ALLOW_THREADS
  	if (err != noErr) 
! 		return macos_error_for_call(err, "FSGetCatalogInfo", NULL);
  
  	dict = dict_from_cataloginfo(bitmap, &info, &uni);
***************
*** 1084,1111 ****
  
  //__________________________________________________________________________________________________
! static char fmgrmodule_opendir__doc__[] =
  "opendir(path) -> iterator\n\n\
  Return an iterator for listdir.";
  
  static
! PyObject *fmgrmodule_opendir(PyObject *self, PyObject *args)
  {
- 	char *path;
  	iteratorObject *rv;
  	FSRef ref;
  	OSErr err;
  	Boolean	isdir;
  
! 	if (!PyArg_ParseTuple(args, "s", &path))
  		return NULL;
- 
- 	Py_BEGIN_ALLOW_THREADS
- 	err = FSPathMakeRef((UInt8 *)path, &ref, &isdir);
- 	Py_END_ALLOW_THREADS
  
! 	if (err != noErr)
! 		return macos_error_for_call(err, "FSPathMakeRef", path);
! 	else if (isdir == false)
  		return PyErr_Format(PyExc_SyntaxError, "requires a directory");
  
  	rv = newIteratorObject(args, &ref);
--- 1081,1105 ----
  
  //__________________________________________________________________________________________________
! static char hfsplusmodule_opendir__doc__[] =
  "opendir(path) -> iterator\n\n\
  Return an iterator for listdir.";
  
  static
! PyObject *hfsplusmodule_opendir(PyObject *self, PyObject *args)
  {
  	iteratorObject *rv;
  	FSRef ref;
  	OSErr err;
+ #if 0
  	Boolean	isdir;
+ #endif
  
! 	if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &ref))
  		return NULL;
  
! #if 0
! 	if (isdir == false)
  		return PyErr_Format(PyExc_SyntaxError, "requires a directory");
+ #endif
  
  	rv = newIteratorObject(args, &ref);
***************
*** 1116,1142 ****
  
  //__________________________________________________________________________________________________
! static char fmgrmodule_fsref__doc__[] =
  "fsref(path) -> FSRef\n\n\
  Return an FSRef object.";
  
  static
! PyObject *fmgrmodule_fsref(PyObject *self, PyObject *args)
  {
- 	char *path;
  	fsRefObject *obj;
  	FSRef ref;
! 	OSErr err;
! 	Boolean isdir;
  
! 	if (!PyArg_ParseTuple(args, "s", &path))
  		return NULL;
  
- 	Py_BEGIN_ALLOW_THREADS
- 	err = FSPathMakeRef((UInt8 *)path, &ref, &isdir);
- 	Py_END_ALLOW_THREADS
- 
- 	if (err != noErr)
- 		return macos_error_for_call(err, "FSPathMakeRef", path);
- 
  	obj = newFSRefObject(args, &ref, true, isdir);
  	if (obj == NULL)
--- 1110,1127 ----
  
  //__________________________________________________________________________________________________
! static char hfsplusmodule_fsref__doc__[] =
  "fsref(path) -> FSRef\n\n\
  Return an FSRef object.";
  
  static
! PyObject *hfsplusmodule_fsref(PyObject *self, PyObject *args)
  {
  	fsRefObject *obj;
  	FSRef ref;
! 	Boolean isdir = 0;
  
! 	if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &ref))
  		return NULL;
  
  	obj = newFSRefObject(args, &ref, true, isdir);
  	if (obj == NULL)
***************
*** 1146,1150 ****
  
  //__________________________________________________________________________________________________
! static char fmgrmodule_openfork__doc__[] =
  "openfork(path[,resourcefork[,perms]]) -> forkRef\n\n\
  Return a forkRef object for reading/writing/etc. Optionally,\n\
--- 1131,1135 ----
  
  //__________________________________________________________________________________________________
! static char hfsplusmodule_openfork__doc__[] =
  "openfork(path[,resourcefork[,perms]]) -> forkRef\n\n\
  Return a forkRef object for reading/writing/etc. Optionally,\n\
***************
*** 1158,1182 ****
  
  static
! PyObject *fmgrmodule_openfork(PyObject *self, PyObject *args)
  {
- 	char *path;
  	forkRefObject *rv;
  	FSRef ref;
! 	OSErr err;
  	Boolean	isdir;
  	int resfork = 0, perms = fsRdPerm;
  
! 	if (!PyArg_ParseTuple(args, "s|ii", &path, &resfork, &perms))
  		return NULL;
- 
- 	Py_BEGIN_ALLOW_THREADS
- 	err = FSPathMakeRef((UInt8 *)path, &ref, &isdir);
- 	Py_END_ALLOW_THREADS
  
! 	if (err != noErr) {
! 		return macos_error_for_call(err, "FSPathMakeRef", path);
! 	} else if (isdir == true) {
  		return PyErr_Format(PyExc_SyntaxError, "requires a file");
  	}
  
  	rv = newForkRefObject(args, &ref, resfork, perms);
--- 1143,1163 ----
  
  static
! PyObject *hfsplusmodule_openfork(PyObject *self, PyObject *args)
  {
  	forkRefObject *rv;
  	FSRef ref;
! #if 0
  	Boolean	isdir;
+ #endif
  	int resfork = 0, perms = fsRdPerm;
  
! 	if (!PyArg_ParseTuple(args, "s|ii", PyMac_GetFSRef, &ref, &resfork, &perms))
  		return NULL;
  
! #if 0
! 	if (isdir == true) {
  		return PyErr_Format(PyExc_SyntaxError, "requires a file");
  	}
+ #endif
  
  	rv = newForkRefObject(args, &ref, resfork, perms);
***************
*** 1189,1197 ****
  // List of functions defined in the module
  //
! static PyMethodDef fmgrmodule_methods[] = {
! 	{"getcatinfo",	fmgrmodule_getcatinfo,	METH_VARARGS,	fmgrmodule_getcatinfo__doc__},
! 	{"opendir",	fmgrmodule_opendir,	METH_VARARGS,			fmgrmodule_opendir__doc__},
! 	{"openfork", fmgrmodule_openfork,	METH_VARARGS,		fmgrmodule_openfork__doc__},
! 	{"fsref", fmgrmodule_fsref,	METH_VARARGS,				fmgrmodule_fsref__doc__},
  	{NULL,		NULL}
  };
--- 1170,1178 ----
  // List of functions defined in the module
  //
! static PyMethodDef hfsplusmodule_methods[] = {
! 	{"getcatinfo",	hfsplusmodule_getcatinfo,	METH_VARARGS,	hfsplusmodule_getcatinfo__doc__},
! 	{"opendir",	hfsplusmodule_opendir,	METH_VARARGS,			hfsplusmodule_opendir__doc__},
! 	{"openfork", hfsplusmodule_openfork,	METH_VARARGS,		hfsplusmodule_openfork__doc__},
! 	{"fsref", hfsplusmodule_fsref,	METH_VARARGS,				hfsplusmodule_fsref__doc__},
  	{NULL,		NULL}
  };
***************
*** 1212,1216 ****
  
  	/* Create the module and add the functions */
! 	m = Py_InitModule("fmgr", fmgrmodule_methods);
  
  	/* Add some symbolic constants to the module */
--- 1193,1197 ----
  
  	/* Create the module and add the functions */
! 	m = Py_InitModule("hfsplus", hfsplusmodule_methods);
  
  	/* Add some symbolic constants to the module */
***************
*** 1226,1230 ****
  	insert_int(d, "fsFromMark", fsFromMark);
  	insert_int(d, "noCacheMask", noCacheMask);
! 	ErrorObject = PyErr_NewException("fmgr.error", NULL, NULL);
  	PyDict_SetItemString(d, "error", ErrorObject);
  }
--- 1207,1211 ----
  	insert_int(d, "fsFromMark", fsFromMark);
  	insert_int(d, "noCacheMask", noCacheMask);
! 	ErrorObject = PyErr_NewException("hfsplus.error", NULL, NULL);
  	PyDict_SetItemString(d, "error", ErrorObject);
  }