[Python-checkins] python/dist/src/Mac/Modules/file _Filemodule.c,1.2,1.3 filescan.py,1.2,1.3 filesupport.py,1.2,1.3

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
2002年12月15日 11:55:10 -0800


Update of /cvsroot/python/python/dist/src/Mac/Modules/file
In directory sc8-pr-cvs1:/tmp/cvs-serv18957/file
Modified Files:
	_Filemodule.c filescan.py filesupport.py 
Log Message:
Combined alias and file into a single module. This is the only reasonable
way to get various alias creation routines as methods of FSSpec or FSRef
objects (which is the logical thing, from a Python POV). Also started on
the code that will contain all the macfs functionality, so macfs can
becode a Python module, to be used mainly for backward compatibility.
Index: _Filemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/_Filemodule.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** _Filemodule.c	13 Dec 2002 23:16:00 -0000	1.2
--- _Filemodule.c	15 Dec 2002 19:55:07 -0000	1.3
***************
*** 27,30 ****
--- 27,40 ----
 #endif
 
+ /* Forward declarations */
+ extern PyObject *FSRef_New(FSRef *itself);
+ extern PyObject *FSSpec_New(FSSpec *itself);
+ extern PyObject *Alias_New(AliasHandle itself);
+ extern int FSRef_Convert(PyObject *v, FSRef *p_itself);
+ extern int FSSpec_Convert(PyObject *v, FSSpec *p_itself);
+ extern int Alias_Convert(PyObject *v, AliasHandle *p_itself);
[...2070 lines suppressed...]
+ 	Alias_Type.ob_type = &PyType_Type;
+ 	Py_INCREF(&Alias_Type);
+ 	PyModule_AddObject(m, "Alias", (PyObject *)&Alias_Type);
+ 	/* Backward-compatible name */
+ 	Py_INCREF(&Alias_Type);
+ 	PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
+ 	FSSpec_Type.ob_type = &PyType_Type;
+ 	Py_INCREF(&FSSpec_Type);
+ 	PyModule_AddObject(m, "FSSpec", (PyObject *)&FSSpec_Type);
+ 	/* Backward-compatible name */
+ 	Py_INCREF(&FSSpec_Type);
+ 	PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
+ 	FSRef_Type.ob_type = &PyType_Type;
+ 	Py_INCREF(&FSRef_Type);
+ 	PyModule_AddObject(m, "FSRef", (PyObject *)&FSRef_Type);
+ 	/* Backward-compatible name */
+ 	Py_INCREF(&FSRef_Type);
+ 	PyModule_AddObject(m, "FSRefType", (PyObject *)&FSRef_Type);
 }
 
Index: filescan.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/filescan.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** filescan.py	13 Dec 2002 23:16:00 -0000	1.2
--- filescan.py	15 Dec 2002 19:55:07 -0000	1.3
***************
*** 9,16 ****
 LONG = "Files"
 SHORT = "file"
- OBJECT = "NOTUSED"
 
 def main():
! 	input = LONG + ".h"
 	output = SHORT + "gen.py"
 	defsoutput = TOOLBOXDIR + LONG + ".py"
--- 9,15 ----
 LONG = "Files"
 SHORT = "file"
 
 def main():
! 	input = ["Files.h", "Aliases.h"]
 	output = SHORT + "gen.py"
 	defsoutput = TOOLBOXDIR + LONG + ".py"
***************
*** 31,39 ****
 		listname = "functions"
 		if arglist:
 			t, n, m = arglist[0]
! 			# This is non-functional today
! 			if t == OBJECT and m == "InMode":
 				classname = "Method"
! 				listname = "methods"
 		return classname, listname
 
--- 30,51 ----
 		listname = "functions"
 		if arglist:
+ 			# Funny special case
+ 			if len(arglist) > 2:
+ 				t, n, m = arglist[1]
+ 				if t == "AliasHandle" and m == "InMode":
+ 					classname = "Arg2MethodGenerator"
+ 					listname = "alias_methods"
+ 					return classname, listname
+ 			# Normal cases
 			t, n, m = arglist[0]
! 			if t == "AliasHandle" and m == "InMode":
 				classname = "Method"
! 				listname = "alias_methods"
! 			if t == "FSSpec_ptr" and m == "InMode":
! 				classname = "Method"
! 				listname = "fsspec_methods"
! 			if t == "FSRef_ptr" and m == "InMode":
! 				classname = "Method"
! 				listname = "fsref_methods"
 		return classname, listname
 
***************
*** 46,49 ****
--- 58,64 ----
 			
 			"FSRefMakePath", # Do this manually
+ #			"ResolveAlias", # Do this manually
+ #			"ResolveAliasWithMountFlags", # Do this manually
+ #			"FollowFinderAlias", # Do this manually
 			
 			"FSRead", # Couldn't be bothered
***************
*** 129,133 ****
 			"IOCompletionProcPtr", # proc pointer
 			"IOCompletionUPP", # Proc pointer
! 			
 			
 			]
--- 144,149 ----
 			"IOCompletionProcPtr", # proc pointer
 			"IOCompletionUPP", # Proc pointer
! 			"AliasFilterProcPtr",
! 			"AliasFilterUPP",
 			
 			]
***************
*** 145,148 ****
--- 161,176 ----
 			 [('UnicodeReverseInBuffer', '*', 'InMode')]
 			),
+ 			# Wrong guess
+ 			([('Str63', 'theString', 'InMode')],
+ 			 [('Str63', 'theString', 'OutMode')]),
+ 			 
+ 			# Yet another way to give a pathname:-)
+ 			([('short', 'fullPathLength', 'InMode'),
+ 			 ('void_ptr', 'fullPath', 'InMode')],
+ 			 [('FullPathName', 'fullPath', 'InMode')]),
+ 	
+ 			# Various ResolveAliasFileXXXX functions
+ 			([('FSSpec', 'theSpec', 'OutMode')],
+ 			 [('FSSpec_ptr', 'theSpec', 'InOutMode')]),
 		]
 		
Index: filesupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/file/filesupport.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** filesupport.py	13 Dec 2002 23:16:00 -0000	1.2
--- filesupport.py	15 Dec 2002 19:55:07 -0000	1.3
***************
*** 7,11 ****
 
 # Declarations that change for each manager
! MACHEADERFILE = 'Files.h'		# The Apple header file
 MODNAME = '_File'				# The name of the module
 
--- 7,11 ----
 
 # Declarations that change for each manager
! #MACHEADERFILE = 'Files.h'		# The Apple header file
 MODNAME = '_File'				# The name of the module
 
***************
*** 17,51 ****
 from macsupport import *
 
! # Create the type objects
! #ConstStrFileNameParam = ConstStr255Param
! #StrFileName = Str255
! #FolderClass = OSTypeType("FolderClass")
! # FolderDesc
! #FolderDescFlags = Type("FolderDescFlags", "l")
! #FolderLocation = OSTypeType("FolderLocation")
! # FolderRouting
! #FolderType = OSTypeType("FolderType")
! #RoutingFlags = Type("RoutingFlags", "l")
 
! class UniCharCountBuffer(InputOnlyType):
 	pass
! 
! #CatPositionRec
 ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
 FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
 FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
! FNMessage = Type("FNMessage", "l")
! FSAllocationFlags = Type("FSAllocationFlags", "H")
 #FSCatalogInfo
- FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l")
 #FSForkInfo
 #FSIterator
- FSIteratorFlags = Type("FSIteratorFlags", "l")
 #FSVolumeInfo
! FSVolumeRefNum = Type("FSVolumeRefNum", "h")
! HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255")
! SInt64 = Type("SInt64", "L")
! UInt64 = Type("UInt64", "L")
! UInt8_ptr = InputOnlyType("UInt8 *", "s")
 
 includestuff = includestuff + """
--- 17,60 ----
 from macsupport import *
 
! # Various integers:
! SInt64 = Type("SInt64", "L")
! UInt64 = Type("UInt64", "L")
! FNMessage = Type("FNMessage", "l")
! FSAllocationFlags = Type("FSAllocationFlags", "H")
! FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l")
! FSIteratorFlags = Type("FSIteratorFlags", "l")
! FSVolumeRefNum = Type("FSVolumeRefNum", "h")
! AliasInfoType = Type("AliasInfoType", "h")
 
! # Various types of strings:
! #class UniCharCountBuffer(InputOnlyType):
! #	pass
! class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType):
 	pass
! FullPathName = VarReverseInputBufferType()
! ConstStr31Param = OpaqueArrayType("Str31", "PyMac_BuildStr255", "PyMac_GetStr255")
! ConstStr32Param = OpaqueArrayType("Str32", "PyMac_BuildStr255", "PyMac_GetStr255")
 ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
+ Str63 = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
+ 
+ HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255")
+ UInt8_ptr = InputOnlyType("UInt8 *", "s")
+ 
+ # Other types:
 FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
 FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
! AliasHandle = OpaqueByValueType("AliasHandle", "Alias")
! FSSpec = OpaqueType("FSSpec", "FSSpec")
! FSSpec_ptr = OpaqueType("FSSpec", "FSSpec")
! FSRef = OpaqueType("FSRef", "FSRef")
! FSRef_ptr = OpaqueType("FSRef", "FSRef")
! 
! # To be done:
! #CatPositionRec
 #FSCatalogInfo
 #FSForkInfo
 #FSIterator
 #FSVolumeInfo
! #FSSpecArrayPtr
 
 includestuff = includestuff + """
***************
*** 56,59 ****
--- 65,78 ----
 #endif
 
+ /* Forward declarations */
+ extern PyObject *FSRef_New(FSRef *itself);
+ extern PyObject *FSSpec_New(FSSpec *itself);
+ extern PyObject *Alias_New(AliasHandle itself);
+ extern int FSRef_Convert(PyObject *v, FSRef *p_itself);
+ extern int FSSpec_Convert(PyObject *v, FSSpec *p_itself);
+ extern int Alias_Convert(PyObject *v, AliasHandle *p_itself);
+ static int myPyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+ static int myPyMac_GetFSRef(PyObject *v, FSRef *fsr);
+ 
 /*
 ** Parse/generate objsect
***************
*** 66,82 ****
 }
 
- #if 0
- static int
- PyMac_GetHFSUniStr255(PyObject *v, HFSUniStr255 *itself)
- {
- 	return PyArg_ParseTuple(v, "O&O&O&O&O&",
- 		PyMac_GetFixed, &itself->ascent,
- 		PyMac_GetFixed, &itself->descent,
- 		PyMac_GetFixed, &itself->leading,
- 		PyMac_GetFixed, &itself->widMax,
- 		ResObj_Convert, &itself->wTabHandle);
- }
- #endif
- 
 /*
 ** Parse/generate objsect
--- 85,88 ----
***************
*** 104,112 ****
--- 110,315 ----
 		&itself->fdFldr);
 }
+ """
 
+ finalstuff = finalstuff + """
+ static int
+ myPyMac_GetFSSpec(PyObject *v, FSSpec *spec)
+ {
+ 	Str255 path;
+ 	short refnum;
+ 	long parid;
+ 	OSErr err;
+ 	FSRef fsr;
+ 
+ 	if (FSSpec_Check(v)) {
+ 		*spec = ((FSSpecObject *)v)->ob_itself;
+ 		return 1;
+ 	}
+ 
+ 	if (PyArg_Parse(v, "(hlO&)",
+ 						&refnum, &parid, PyMac_GetStr255, &path)) {
+ 		err = FSMakeFSSpec(refnum, parid, path, spec);
+ 		if ( err && err != fnfErr ) {
+ 			PyMac_Error(err);
+ 			return 0;
+ 		}
+ 		return 1;
+ 	}
+ 	PyErr_Clear();
+ #if !TARGET_API_MAC_OSX
+ 	/* On OS9 we now try a pathname */
+ 	if ( PyString_Check(v) ) {
+ 		/* It's a pathname */
+ 		if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
+ 			return 0;
+ 		refnum = 0; /* XXXX Should get CurWD here?? */
+ 		parid = 0;
+ 		err = FSMakeFSSpec(refnum, parid, path, spec);
+ 		if ( err && err != fnfErr ) {
+ 			PyMac_Error(err);
+ 			return 0;
+ 		}
+ 		return 1;
+ 	}
+ 	PyErr_Clear();
+ #endif
+ 	/* Otherwise we try to go via an FSRef. On OSX we go all the way,
+ 	** on OS9 we accept only a real FSRef object
+ 	*/
+ #if TARGET_API_MAX_OSX
+ 	if ( myPyMac_GetFSRef(v, &fsr) >= 0 ) {
+ #else
+ 	if ( PyArg_Parse(v, "O&", FSRef_Convert, &fsr) ) {
+ #endif	
+ 		err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL);
+ 		if (err != noErr) {
+ 			PyMac_Error(err);
+ 			return 0;
+ 		}
+ 		return 1;
+ 	}
+ 	PyErr_SetString(PyExc_TypeError, "FSSpec, FSRef, pathname or (refnum, parid, path) required");
+ 	return 0;
+ }
+ 
+ static int
+ myPyMac_GetFSRef(PyObject *v, FSRef *fsr)
+ {
+ 	if (FSRef_Check(v)) {
+ 		*fsr = ((FSRefObject *)v)->ob_itself;
+ 		return 1;
+ 	}
+ 
+ #if !TARGET_API_MAC_OSX
+ 	/* On OSX we now try a pathname */
+ 	if ( PyString_Check(args) ) {
+ 		OSStatus err;
+ 		if ( (err=FSPathMakeRef(PyString_AsString(v), fsr, NULL)) ) {
+ 			PyErr_Mac(ErrorObject, err);
+ 			return 0;
+ 		}
+ 		return 1;
+ 	}
+ 	/* XXXX Should try unicode here too */
+ #endif
+ 	/* Otherwise we try to go via an FSSpec */
+ 	if (FSSpec_Check(v)) {
+ 		if (FSpMakeFSRef(&((FSSpecObject *)v)->ob_itself, fsr))
+ 			return 1;
+ 		return 0;
+ 	}
+ 	PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
+ 	return 0;
+ }
 """
 
 execfile(string.lower(MODPREFIX) + 'typetest.py')
 
+ # Our object types:
+ class FSSpecDefinition(PEP253Mixin, GlobalObjectDefinition):
+ 	def __init__(self, name, prefix, itselftype):
+ 		GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
+ 		self.argref = "*"	# Store FSSpecs, but pass them by address
+ 
+ 	def outputCheckNewArg(self):
+ 		Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ 
+ 	def output_tp_newBody(self):
+ 		Output("PyObject *self;");
+ 		Output()
+ 		Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ 		Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));", 
+ 			self.objecttype, self.objecttype)
+ 		Output("return self;")
+ 
+ 	def output_tp_initBody(self):
+ 		Output("PyObject *v;")
+ 		Output("char *kw[] = {\"itself\", 0};")
+ 		Output()
+ 		Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"O\", kw, &v))")
+ 		Output("return -1;")
+ 		Output("if (myPyMac_GetFSSpec(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
+ 		Output("return -1;")
+ 	
+ class FSRefDefinition(PEP253Mixin, GlobalObjectDefinition):
+ 	def __init__(self, name, prefix, itselftype):
+ 		GlobalObjectDefinition.__init__(self, name, prefix, itselftype)
+ 		self.argref = "*"	# Store FSRefs, but pass them by address
+ 
+ 	def outputCheckNewArg(self):
+ 		Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ 
+ 	def output_tp_newBody(self):
+ 		Output("PyObject *self;");
+ 		Output()
+ 		Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ 		Output("memset(&((%s *)self)->ob_itself, 0, sizeof(%s));", 
+ 			self.objecttype, self.objecttype)
+ 		Output("return self;")
+ 	
+ 	def output_tp_initBody(self):
+ 		Output("PyObject *v;")
+ 		Output("char *kw[] = {\"itself\", 0};")
+ 		Output()
+ 		Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"O\", kw, &v))")
+ 		Output("return -1;")
+ 		Output("if (myPyMac_GetFSRef(v, &((%s *)self)->ob_itself)) return 0;", self.objecttype)
+ 		Output("return -1;")
+ 	
+ class AliasDefinition(PEP253Mixin, GlobalObjectDefinition):
+ 	# XXXX Should inherit from resource?
+ 
+ 	def outputCheckNewArg(self):
+ 		Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ 		
+ 	def outputStructMembers(self):
+ 		GlobalObjectDefinition.outputStructMembers(self)
+ 		Output("void (*ob_freeit)(%s ptr);", self.itselftype)
+ 		
+ 	def outputInitStructMembers(self):
+ 		GlobalObjectDefinition.outputInitStructMembers(self)
+ 		Output("it->ob_freeit = NULL;")
+ 		
+ 	def outputCleanupStructMembers(self):
+ 		Output("if (self->ob_freeit && self->ob_itself)")
+ 		OutLbrace()
+ 		Output("self->ob_freeit(self->ob_itself);")
+ 		OutRbrace()
+ 		Output("self->ob_itself = NULL;")
+ 
+ 	def output_tp_newBody(self):
+ 		Output("PyObject *self;");
+ 		Output()
+ 		Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ 		Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
+ 		Output("return self;")
+ 	
+ 	def output_tp_initBody(self):
+ 		Output("%s itself;", self.itselftype);
+ 		Output("char *kw[] = {\"itself\", 0};")
+ 		Output()
+ 		Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
+ 			self.prefix)
+ 		OutLbrace()
+ 		Output("((%s *)self)->ob_itself = itself;", self.objecttype)
+ 		Output("return 0;")
+ 		OutRbrace()
+ 		Output("return -1;")
+ 	
+ # Alias methods come in two flavors: those with the alias as arg1 and
+ # those with the alias as arg 2.
+ class Arg2MethodGenerator(MethodGenerator):
+ 	"""Similar to MethodGenerator, but has self as second argument"""
+ 
+ 	def parseArgumentList(self, args):
+ 		args0, arg1, argsrest = args[:1], args[1], args[2:]
+ 		t0, n0, m0 = arg1
+ 		args = args0 + argsrest
+ 		if m0 != InMode:
+ 			raise ValueError, "method's 'self' must be 'InMode'"
+ 		self.itself = Variable(t0, "_self->ob_itself", SelfMode)
+ 		FunctionGenerator.parseArgumentList(self, args)
+ 		self.argumentList.insert(2, self.itself)
+ 
 # From here on it's basically all boiler plate...
 
***************
*** 114,122 ****
--- 317,337 ----
 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
 
+ aliasobject = AliasDefinition('Alias', 'Alias', 'AliasHandle')
+ fsspecobject = FSSpecDefinition('FSSpec', 'FSSpec', 'FSSpec')
+ fsrefobject = FSRefDefinition('FSRef', 'FSRef', 'FSRef')
+ 
+ module.addobject(aliasobject)
+ module.addobject(fsspecobject)
+ module.addobject(fsrefobject)
+ 
 # Create the generator classes used to populate the lists
 Function = OSErrFunctionGenerator
+ Method = OSErrMethodGenerator
 
 # Create and populate the lists
 functions = []
+ alias_methods = []
+ fsref_methods = []
+ fsspec_methods = []
 execfile(INPUTFILE)
 
***************
*** 124,136 ****
 FSRefMakePath_body = """
 OSStatus _err;
- FSRef ref;
 #define MAXPATHNAME 1024
 UInt8 path[MAXPATHNAME];
 UInt32 maxPathSize = MAXPATHNAME;
 
! if (!PyArg_ParseTuple(_args, "O&",
! 					 PyMac_GetFSRef, &ref))
! 	return NULL;
! _err = FSRefMakePath(&ref,
 					 path,
 					 maxPathSize);
--- 339,347 ----
 FSRefMakePath_body = """
 OSStatus _err;
 #define MAXPATHNAME 1024
 UInt8 path[MAXPATHNAME];
 UInt32 maxPathSize = MAXPATHNAME;
 
! _err = FSRefMakePath(&_self->ob_itself,
 					 path,
 					 maxPathSize);
***************
*** 140,149 ****
 """
 f = ManualGenerator("FSRefMakePath", FSRefMakePath_body)
! f.docstring = lambda: "(FSRef) -> string"
! functions.append(f)
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
 for f in functions: module.add(f)
 
 # generate output (open the output file as late as possible)
--- 351,364 ----
 """
 f = ManualGenerator("FSRefMakePath", FSRefMakePath_body)
! f.docstring = lambda: "() -> string"
! fsref_methods.append(f)
! 
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
 for f in functions: module.add(f)
+ for f in alias_methods: aliasobject.add(f)
+ for f in fsspec_methods: fsspecobject.add(f)
+ for f in fsref_methods: fsrefobject.add(f)
 
 # generate output (open the output file as late as possible)

AltStyle によって変換されたページ (->オリジナル) /