[Thuban-commits] r2801 - in branches/WIP-pyshapelib-Unicode/thuban: . Thuban/Model libraries/pyshapelib libraries/shapelib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jan 9 00:33:01 CET 2008


Author: bramz
Date: 2008-01-09 00:32:59 +0100 (Wed, 09 Jan 2008)
New Revision: 2801

Modified:
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/table.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/NEWS
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/README
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_common.h
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelibmodule.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c
   branches/WIP-pyshapelib-Unicode/thuban/setup.py
Log:
- various changes to pyshapelib (see libraries/pyshapelib/ChangeLog)
- forward porting shapelib
- updating setup.py for pyshapelib
- Thuban/Model/table.py creates LDID_ESRI_ANSI dbf files by default

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/table.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/table.py	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/table.py	2008-01-08 23:32:59 UTC (rev 2801)
@@ -462,7 +462,7 @@
     indices to be saved to the file, otherwise all rows are saved.
     """
 
-    dbf = dbflib.create(filename, code_page = dbflib.CPG_UTF_8, return_unicode = True)
+    dbf = dbflib.create(filename, code_page = dbflib.LDID_ESRI_ANSI, return_unicode = True)
 
     dbflib_fieldtypes = {FIELDTYPE_STRING: dbflib.FTString,
                          FIELDTYPE_INT: dbflib.FTInteger,

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2008-01-08 23:32:59 UTC (rev 2801)
@@ -1,3 +1,36 @@
+2008-01-08  Bram de Greve <bram.degreve at bramz.net>
+
+	* shapelibmodule.c, dbflibmodule.c, pyshapelib_common.h:
+	- fixed copyright notice and header
+	- rename PYSHAPELIB_FILESYSTEMENCODING to PYSHAPELIB_FILENAME_ENCODING
+	
+	* shapelibmodule.c, dbflibmodule.c:
+	- add _have_utf8_hooks constant with value of HAVE_UTF8_HOOKS
+	
+	* dbflibmodule.c:
+	- set default code_page and codec to LDID/87 (ESRI ANSI, 0x57) and cp1252.
+	- use again HAVE_CODE_PAGE to disable code_page support when building with
+	older (but official) shapelib libraries
+	- decode ?, t, f, y, n values for the logic field type correctly.
+	
+	* pyshapelib_common.h:
+	- add definitions of Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE
+	if they are not defined yet (for older Python versions)
+
+	* setup.py:
+	- pass HAVE_??? macros to shapelib extension as well.
+	- add HAVE_CODE_PAGE and HAVE_UTF8_HOOKS
+	- only compile and link safileio.c if it exists.
+	- updated library version and authors.
+	
+	* README:
+	- removed references to SWIG
+	- mentioned compatibility issues with current official shapelib releases
+	and how to get the shapelib from the CVS instead.
+	
+	* NEWS:
+	- added an entry for pyshapelib version 0.4 with all new features.	
+
 2007-12-18	Bram de Greve <bram.degreve at bramz.net>
 
 	* dbflibmodule.c: shapelib now has a hook to set your own atof function.

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/NEWS
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/NEWS	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/NEWS	2008-01-08 23:32:59 UTC (rev 2801)
@@ -1,3 +1,70 @@
+pyshapelib 0.4 (2008-??-??)
+
+Module shapelib:
+
+ * Rewritten as a hand-crafted module instead of a SWIG generated one.
+
+ * SHPObject now has a method part_types() to return a tuple of the
+   part types when appropriate.  Otherwise, it returns None.
+
+ * Added support for shapetypes with Z and M values.  When creating measured
+   shapes (XYM), treat M value as optional (defaults to zero).Similar for 3D 
+   shapes (XYZM), treat both Z and M values as optional (both default to zero).
+   None is accepted as an M value, but it is stored as zero internally (ESRI 
+   shapefile specs define any M value smaller than 1e-38 as no-data).
+
+ * Added 'name' and 'mode' keywords for ShapeFile constructors and the module's
+   open() function, similiar to Python's file().  
+
+ * Unicode strings are now accepted as filenames, also on Windows.
+   
+
+Module dbflib:
+
+ * Rewritten as a hand-crafted module instead of a SWIG generated one.
+
+ * DBFFile objects can be requested to return string content as unicode, via
+   the optional return_unicode argument in create(), open() and the DBFFile 
+   constructor.  If so, string content is decoded using the file's codepage.
+   Otherwise, the raw encoded string is returned.  return_unicode is False
+   by default.
+
+ * DBFFiles now support code pages for string content.  These code pages can 
+   either be specified by the numerical LDID field in the .dbf file, or by an 
+   additional .cpg file that contains a single string with the code page name.
+   Both systems are unified into a single string, the former is of the form
+   "LDID/nn" where nn is a _decimal_ number between 1 and 255.
+
+   When creating a DBFFile, you can specify the code page to use by the optional
+   code_page argument that defaults to "LDID/87", the ESRI ANSI code page 0x57.
+   You can inspect the code page of a DBFFile through the readonly code_page 
+   member.  
+
+   Code pages are associated to Python codecs through a codecs map (see below).
+   This codec is used to encode or decode string content to or from dbflib.  You
+   can inspect the used codec by the readonly codec member of DBFFile.
+
+   dbflib supports a number of constants of the form LDID_??? and CPG_??? that
+   are names of code pages that are supported by the builtin codecs map.
+
+ * An optional custom codecs_map can be passed to create(), open() and the 
+   DBFFile constructor to map code pages to codecs, for when the builtin codecs
+   map does not fit your needs.  
+
+   The keys of this map are strings like the values of the constants LDID_??? 
+   and CPG_???.  E.g. "LDID/87" for LDID_ESRI_ANSI (use _decimal_ values in the 
+   string) or "UTF-8" for UTF-8 encoding.
+
+   The values of this map should be names of Python codecs.  See Python Library 
+   Reference - 4.9.2 Standard Encodings to see what codecs are builtin.
+
+ * Added 'name' and 'mode' keywords for ShapeFile constructors and the module's
+   open() function, similiar to Python's file().  
+
+ * Unicode strings are now accepted as filenames, also on Windows.
+
+
+
 pyshapelib 0.3 (2004-05-28)
 ===========================
 

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/README
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/README	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/README	2008-01-08 23:32:59 UTC (rev 2801)
@@ -13,10 +13,6 @@
 Shapelib is a free software library for reading and writing ESRI shape
 files and can be found at http://shapelib.maptools.org/.
 
-The bindings were partly created with SWIG, a tool that can generate
-wrappers of C and C++ libraries for a variety of scripting languages.
-It's homepage is http://www.swig.org.
-
 The bindings themselves don't have a homepage at the moment, but the
 source tarballs/zip files can be downloaded from
 http://ftp.intevation.de/users/bh/pyshapelib/
@@ -28,18 +24,33 @@
 To compile the bindings, you need shapelib 1.2.9 or newer and Python 2.0
 or newer.
 
-SWIG is not required. The files generated by SWIG are contained in the
-archive. If you modify shapelib.i or dbflib.i and need to recreate the
-generated files, you need SWIG 1.3 Alpha 5.  It's unlikely that other
-versions will work.
-In addition you need to add the following lines to  initdbflibc(void)
-in dbflib_wrap.c.
-    /* because we are in a python module now, we can give out
-     * pointers to python's locale agonistic function 
-     * XXX this clearly is a hack
-     */
-    DBFSetatof_function(&PyOS_ascii_atof);
+IMPORTANT:
+To be able to use all features of pyshapelib, you'll need to grab the 
+shapelib source code from the CVS, as the latest official release 1.2.10 is
+rather outdated (April 2003).  
+    
+cvs -d:pserver:cvsanon at cvs.maptools.org:/cvs/maptools/cvsroot co -P shapelib
 
+However, if you build against an official release, the build process will
+degrade gracefully. The following features will be missing when compiled 
+against shapelib 1.2.10 or earlier.  Their availability will be reflected by
+a constant _have_???.
+
+- codepage support for character sets other than ANSI (dbflib):
+The codepage member of DBFFile will be missing, and neither will create() 
+accept the codepage parameter. The codecs_map parameter will be missing from 
+open(), create() and DBFFile(), and so will be the various LDID_xxx and CPG_xxx
+constants. _have_codepage will be set to zero.
+
+- Full Unicode support for filenames on Windows (shapelib, dbflib):
+You will be restricted to ANSI character filenames. _have_utf8_hooks will be set
+to zero.
+
+- The commit() method on DBFFile (dbflib):
+This will be missing. _have_update_header will be set to zero.
+
+
+
 You also need Python, of course.  If you installed prebuilt packages
 such as RPMs of some Linux distributions, please make sure that the
 development package is also installed.

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c	2008-01-08 23:32:59 UTC (rev 2801)
@@ -1,14 +1,17 @@
-/* Copyright (c) 2001, 2002, 2007 by Intevation GmbH
+/* Copyright (c) 2001-2008 by Intevation GmbH
  * Authors:
- * Bram de Greve <bram.degreve at intec.ugent.be>
+ * Bram de Greve <bram.degreve at bramz.net>
  * Bernhard Herzog <bh at intevation.de>
  *
- * This program is free software under the GPL (>=v2)
- * Read the file COPYING coming with Thuban for details.
+ * This program is free software under the LGPL (>=v2)
+ * Read the file COPYING coming with pyshapelib for details.
  */
 
 #include "pyshapelib_common.h"
 
+#define DEFAULT_CODEC "cp1252"
+#define DEFAULT_CODE_PAGE "LDID/87" // 0x57
+
 static PyObject* default_codecs_map = NULL;
 
 /* --- DBFFile ------------------------------------------------------------------------------------------------------- */
@@ -51,8 +54,9 @@
 static int dbffile_init_codec(DBFFileObject* self, PyObject* codecs_map)
 {
 	size_t n = 0;
+	char* codec = DEFAULT_CODEC;
+#if HAVE_CODE_PAGE
 	PyObject* ocodec = NULL;
-	char* codec = NULL;
 	char* code_page = (char*) DBFGetCodePage(self->handle);
 
 	PyMem_Free(self->codec);
@@ -82,16 +86,18 @@
 		if (!codec)
 		{
 			return -1;
-		}		
-		n = strlen(codec);
-		self->codec = PyMem_Malloc(n + 1);
-		if (!self->codec)
-		{
-			PyErr_NoMemory();
-			return -1;
 		}
-		memcpy(self->codec, codec, n + 1);
 	}
+#endif
+	
+	n = strlen(codec);
+	self->codec = PyMem_Malloc(n + 1);
+	if (!self->codec)
+	{
+		PyErr_NoMemory();
+		return -1;
+	}
+	memcpy(self->codec, codec, n + 1);
 
 	return 0;
 }
@@ -106,13 +112,22 @@
 	char* mode = "rb";
 	PyObject* return_unicode = 0;
 	PyObject* codecs_map = NULL;
+#if HAVE_CODE_PAGE
 	static char *kwlist[] = {"name", "mode", "return_unicode", "codecs_map", NULL};
+#else
+	static char *kwlist[] = {"name", "mode", "return_unicode", NULL};
+#endif
 
 	DBFClose(self->handle);
 	self->handle = NULL;
 
+#if HAVE_CODE_PAGE
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|sOO:DBFFile", kwlist, 
-		PYSHAPELIB_FILESYSTEMENCODING, &file, &mode, &return_unicode, &codecs_map)) return -1;	
+		PYSHAPELIB_FILENAME_ENCODING, &file, &mode, &return_unicode, &codecs_map)) return -1;	
+#else
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|sO:DBFFile", kwlist, 
+		PYSHAPELIB_FILENAME_ENCODING, &file, &mode, &return_unicode)) return -1;	
+#endif
 
 	PYSHAPELIB_SETUPHOOKS(&hooks);
 	self->handle = DBFOpenLL(file, mode, &hooks);
@@ -284,11 +299,17 @@
 			{
 				switch (string[0])
 				{
+				case '?':
+					Py_RETURN_NONE;
 				case 'F':
+				case 'f':
 				case 'N':
+				case 'n':
 					Py_RETURN_FALSE;
 				case 'T':
+				case 't':
 				case 'Y':
+				case 'y':
 					Py_RETURN_TRUE;
 				}
 			}
@@ -547,6 +568,8 @@
 #endif
 
 
+#if HAVE_CODE_PAGE
+
 static PyObject* dbffile_code_page(DBFFileObject* self, void* closure)
 {
 	const char* code_page = DBFGetCodePage(self->handle);
@@ -557,6 +580,8 @@
 	return PyString_FromString(code_page);
 }
 
+#endif
+
 static PyObject* dbffile_codec(DBFFileObject* self, void* closure)
 {
 	if (!self->codec)
@@ -620,7 +645,9 @@
 static struct PyGetSetDef dbffile_getsetters[] = 
 {
 	{"codec", (getter)dbffile_codec, NULL, "Python codec name used to encode or decode Unicode strings (read-only)" },
+#if HAVE_CODE_PAGE
 	{"code_page", (getter)dbffile_code_page, NULL, "DBF Code Page from LDID or .CPG file (read-only)" },
+#endif
 	{NULL}
 };
 
@@ -648,15 +675,26 @@
 	int wideargument = 0;
 	PyObject* return_unicode = NULL;
 	PyObject* codecs_map = NULL;
-	char* code_page = NULL;
+	char* code_page = DEFAULT_CODE_PAGE;
 
+#if HAVE_CODE_PAGE
 	static char *kwlist[] = {"name", "code_page", "return_unicode", "codecs_map", NULL};
+#else
+	static char *kwlist[] = {"name", "return_unicode", NULL};
+#endif
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|sOO:create", kwlist, PYSHAPELIB_FILESYSTEMENCODING, 
+	PYSHAPELIB_SETUPHOOKS(&hooks);
+
+#if HAVE_CODE_PAGE
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|sOO:create", kwlist, PYSHAPELIB_FILENAME_ENCODING, 
 			&file, &code_page, &return_unicode, &codecs_map)) return NULL;
+	handle = DBFCreateLL(file, code_page, &hooks);
+#else
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|O:create", kwlist, PYSHAPELIB_FILENAME_ENCODING, 
+			&file, &return_unicode)) return NULL;
+	handle = DBFCreateLL(file, &hooks);
+#endif
 
-	PYSHAPELIB_SETUPHOOKS(&hooks);
-	handle = DBFCreateLL(file, code_page, &hooks);
 	if (!handle)
 	{
 			PyErr_SetFromErrnoWithFilename(PyExc_IOError, file);
@@ -690,15 +728,25 @@
 static struct PyMethodDef dbflib_methods[] = 
 {
 	{"open", (PyCFunction)dbflib_open, METH_VARARGS | METH_KEYWORDS,
+#if HAVE_CODE_PAGE
 		"open(name [, mode [, return_unicode [, codecs_map]]]) -> DBFFile\n\n"
+#else
+		"open(name [, mode [, return_unicode]]) -> DBFFile\n\n"
+#endif
 		"opens a DBFFile" },
 	{"create", (PyCFunction)dbflib_create, METH_VARARGS | METH_KEYWORDS, 
+#if HAVE_CODE_PAGE
 		"create(name [, code_page [, return_unicode [, codecs_map]]]) -> DBFFile\n\n"
+#else
+		"create(name [, return_unicode]) -> DBFFile\n\n"
+#endif
 		"create a DBFFile " },
 	{NULL}
 };
 
 
+#if HAVE_CODE_PAGE
+
 void add_ldid(PyObject* module, int ldid, const char* codec, const char* name)
 {
 	char code_page[64];
@@ -721,6 +769,8 @@
 	PyModule_AddStringConstant(module, constant, code_page);
 }
 
+#endif
+
 PyMODINIT_FUNC initdbflib(void)
 {
 	PyObject* module = Py_InitModule("dbflib", dbflib_methods);
@@ -734,7 +784,10 @@
 	PYSHAPELIB_ADD_CONSTANT(FTLogical);
 	PYSHAPELIB_ADD_CONSTANT(FTInvalid);
 	PyModule_AddIntConstant(module, "_have_commit", HAVE_UPDATE_HEADER);
+	PyModule_AddIntConstant(module, "_have_code_page", HAVE_CODE_PAGE);
+	PyModule_AddIntConstant(module, "_have_utf8_hooks", HAVE_UTF8_HOOKS);
 
+#if HAVE_CODE_PAGE
 	default_codecs_map = PyDict_New();
 
 	/* table compiled from these resources:
@@ -838,4 +891,7 @@
 	add_cpg(module, "ISO 885910", "iso-8859-10", "ISO_8859_10");
 	add_cpg(module, "ISO 885913", "iso-8859-13", "ISO_8859_13");
 	add_cpg(module, "ISO 885915", "iso-8859-15", "ISO_8859_15");
+
+#endif
+
 }

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_common.h
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_common.h	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_common.h	2008-01-08 23:32:59 UTC (rev 2801)
@@ -1,9 +1,9 @@
-/* Copyright (c) 2007 by Intevation GmbH
+/* Copyright (c) 2007-2008 by Intevation GmbH
  * Authors:
- * Bram de Greve <bram.degreve at intec.ugent.be>
+ * Bram de Greve <bram.degreve at bramz.net>
  *
- * This program is free software under the GPL (>=v2)
- * Read the file COPYING coming with Thuban for details.
+ * This program is free software under the LGPL (>=v2)
+ * Read the file COPYING coming with pyshapelib for details.
  */
 
 #ifndef PYSHAPELIB_H
@@ -81,21 +81,32 @@
 		PyModule_AddObject(module, name, (PyObject*)&type); \
 	}
 
-#define PYSHAPELIB_NO_DATA_LIMIT 1e-38
 #define PYSHAPELIB_NO_DATA 0
 
-
-
+/* helpers to setup the shapelib API hooks correctly
+ */
 #if HAVE_UTF8_HOOKS && defined(MS_WINDOWS)
-#	define PYSHAPELIB_FILESYSTEMENCODING "utf-8"
+#	define PYSHAPELIB_FILENAME_ENCODING "utf-8"
 #	define PYSHAPELIB_SETUPHOOKS(pHooks)\
 		SASetupUtf8Hooks(pHooks);\
 		(pHooks)->Atof = PyOS_ascii_atof
 #else
-#	define PYSHAPELIB_FILESYSTEMENCODING Py_FileSystemDefaultEncoding
+#	define PYSHAPELIB_FILENAME_ENCODING Py_FileSystemDefaultEncoding
 #	define PYSHAPELIB_SETUPHOOKS(pHooks)\
 		SASetupDefaultHooks(pHooks);\
 		(pHooks)->Atof = PyOS_ascii_atof
 #endif
 
+
+
+#ifndef Py_RETURN_NONE
+#	define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+#ifndef Py_RETURN_TRUE
+#	define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
+#endif
+#ifndef Py_RETURN_FALSE
+#	define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
+#endif
+
 #endif
\ No newline at end of file

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py	2008-01-08 23:32:59 UTC (rev 2801)
@@ -1,5 +1,6 @@
 
 import os
+import os.path
 import sys
 from distutils.core import setup, Extension
 from distutils.util import convert_path
@@ -30,8 +31,8 @@
 	print >>sys.stderr, "no shapelib directory found"
 	sys.exit(1)
 
-def dbf_macros():
-	"""Return the macros to define when compiling the dbflib wrapper.
+def determine_macros():
+	"""Return the macros to define when compiling the shapelib and dbflib wrapper.
 
 	The returned list specifies following macros:
 	- HAVE_UPDATE_HEADER, which is 
@@ -42,6 +43,8 @@
 	- HAVE_CODE_PAGE, which is '1' if the dbflib version we will 
 	compiling with has the DBFGetCodePage function and '0' otherwise.
 	Again, shapefil.h is scanned to check this.
+	- HAVE_UTF8_HOOKS, which is '1' if shapelib and dbflib can use UTF-8 filenames
+	on Windows.
 	"""
 	f = open(convert_path(shp_dir + "/shapefil.h"))
 	contents = f.read()
@@ -53,29 +56,47 @@
 		return "0"
 	
 	return [
-		("HAVE_UPDATE_HEADER", have("DBFUpdateHeader"))]
+		("HAVE_UPDATE_HEADER", have("DBFUpdateHeader")),
+		("HAVE_CODE_PAGE", have("DBFGetCodePage")),
+		("HAVE_UTF8_HOOKS", have("SASetupUtf8Hooks"))]
 
+
+
+def search_sahooks_files():
+	""" 
+	Return a filelist of additional files implementing the SA hooks.
+	"""
+	
+	candidates = [shp_dir + "/safileio.c"]
+	return filter(os.path.exists, candidates)
+
+
+
+macros = determine_macros()
+sahooks_files = search_sahooks_files()
+
 extensions = [Extension("shapelib",
 						["shapelibmodule.c",
 						shp_dir + "/shpopen.c",
-						shp_dir + "/shptree.c",
-						shp_dir + "/safileio.c"],
-						include_dirs = [shp_dir]),
+						shp_dir + "/shptree.c"]
+						+ sahooks_files,
+						include_dirs = [shp_dir],
+						define_macros = macros),
 			Extension("shptree",
 						["shptreemodule.c"],
 						include_dirs = [shp_dir]),
 			Extension("dbflib",
 						["dbflibmodule.c",
-						shp_dir + "/dbfopen.c",
-						shp_dir + "/safileio.c"],
+						shp_dir + "/dbfopen.c"]
+						+ sahooks_files,
 						include_dirs = [shp_dir],
-						define_macros = dbf_macros())]
+						define_macros = macros)]
 
 setup(name = "pyshapelib",
-	version = "0.3",
+	version = "0.4",
 	description = "Python bindings for shapelib",
-	author = "Bernhard Herzog",
-	author_email = "bh at intevation.de",
+	author = "Bernhard Herzog, Bram de Greve",
+	author_email = "bh at intevation.de, bram.degreve at bramz.net",
 	url = "ftp:intevation.de/users/bh",
 	ext_modules = extensions)
 

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelibmodule.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelibmodule.c	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelibmodule.c	2008-01-08 23:32:59 UTC (rev 2801)
@@ -1,3 +1,12 @@
+/* Copyright (c) 2001-2008 by Intevation GmbH
+* Authors:
+* Bram de Greve <bram.degreve at bramz.net>
+* Bernhard Herzog <bh at intevation.de>
+*
+* This program is free software under the LGPL (>=v2)
+* Read the file COPYING coming with pyshapelib for details.
+*/
+
 #include "pyshapelib_common.h"
 
 /* --- SHPObject ----------------------------------------------------------------------------------------------------- */
@@ -556,7 +565,7 @@
 	self->handle = NULL;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|s:ShapeFile", kwlist, 
-		PYSHAPELIB_FILESYSTEMENCODING, &file, &mode)) return -1;	
+		PYSHAPELIB_FILENAME_ENCODING, &file, &mode)) return -1;	
 		
 	PYSHAPELIB_SETUPHOOKS(&hooks);
 	self->handle = SHPOpenLL(file, mode, &hooks);
@@ -700,7 +709,7 @@
 	SHPHandle handle = NULL;
 	int wideargument = 0;
 
-	if (!PyArg_ParseTuple(args, "eti:create", PYSHAPELIB_FILESYSTEMENCODING, &file, &type)) return NULL;
+	if (!PyArg_ParseTuple(args, "eti:create", PYSHAPELIB_FILENAME_ENCODING, &file, &type)) return NULL;
 	
 	PYSHAPELIB_SETUPHOOKS(&hooks);
 	handle = SHPCreateLL(file, type, &hooks);
@@ -779,6 +788,8 @@
 	PYSHAPELIB_ADD_TYPE(SHPObjectType, "SHPObject");
 	PYSHAPELIB_ADD_TYPE(ShapeFileType, "ShapeFile");
 	
+	PyModule_AddIntConstant(module, "_have_utf8_hooks", HAVE_UTF8_HOOKS);
+
 	PYSHAPELIB_ADD_CONSTANT(SHPT_NULL);
 	PYSHAPELIB_ADD_CONSTANT(SHPT_POINT);
 	PYSHAPELIB_ADD_CONSTANT(SHPT_ARC);

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c	2008-01-08 23:32:59 UTC (rev 2801)
@@ -34,6 +34,17 @@
  ******************************************************************************
  *
  * $Log: dbfopen.c,v $
+ * Revision 1.81  2008/01/03 17:48:13  bram
+ * in DBFCreate, use default code page LDID/87 (= 0x57, ANSI)
+ * instead of LDID/3.  This seems to be the same as what ESRI
+ * would be doing by default.
+ *
+ * Revision 1.80  2007/12/30 14:36:39  fwarmerdam
+ * avoid syntax issue with last comment.
+ *
+ * Revision 1.79  2007/12/30 14:35:48  fwarmerdam
+ * Avoid char* / unsigned char* warnings.
+ *
  * Revision 1.78  2007/12/18 18:28:07  bram
  * - create hook for client specific atof (bugzilla ticket 1615)
  * - check for NULL handle before closing cpCPG file, and close after reading.
@@ -465,7 +476,7 @@
         char *buffer = (char *) pabyBuf;
         buffer[0] = '\0';
         psDBF->sHooks.FRead( pabyBuf, nBufSize - 1, 1, pfCPG );
-        n = strcspn( pabyBuf, "\n\r" );
+        n = strcspn( (char *) pabyBuf, "\n\r" );
         if( n > 0 )
         {
             pabyBuf[n] = '\0';
@@ -476,9 +487,9 @@
     }
     if( psDBF->pszCodePage == NULL && pabyBuf[29] != 0 )
     {
-        sprintf( pabyBuf, "LDID/%i", psDBF->iLanguageDriver );
-        psDBF->pszCodePage = (char *) malloc(strlen(pabyBuf) + 1);
-        strcpy( psDBF->pszCodePage, pabyBuf );
+        sprintf( (char *) pabyBuf, "LDID/%d", psDBF->iLanguageDriver );
+        psDBF->pszCodePage = (char *) malloc(strlen((char*)pabyBuf) + 1);
+        strcpy( psDBF->pszCodePage, (char *) pabyBuf );
     }
 
 /* -------------------------------------------------------------------- */
@@ -591,14 +602,14 @@
 /************************************************************************/
 /*                             DBFCreate()                              */
 /*                                                                      */
-/*      Create a new .dbf file with default code page LDID/3            */
+/* Create a new .dbf file with default code page LDID/87 (0x57)         */
 /************************************************************************/
 
 DBFHandle SHPAPI_CALL
 DBFCreate( const char * pszFilename )
 
 {
-    return DBFCreateEx( pszFilename, "LDID/3" );
+    return DBFCreateEx( pszFilename, "LDID/87" ); // 0x57
 }
 
 /************************************************************************/
@@ -1690,4 +1701,4 @@
     if( psDBF == NULL )
         return NULL;
     return psDBF->pszCodePage;
-}
\ No newline at end of file
+}

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/safileio.c	2008-01-08 23:32:59 UTC (rev 2801)
@@ -228,8 +228,8 @@
     {
         file = (SAFile) _wfopen( pwszFileName, pwszAccess );
     }
-    free (pwszFileName);
-    free (pwszAccess);
+    free ((wchar_t*) pwszFileName);
+    free ((wchar_t*) pwszAccess);
     return file;
 }
 
@@ -240,11 +240,13 @@
 int SAUtf8WRemove( const char *pszFilename )
 {
     const wchar_t *pwszFileName = Utf8ToWideChar( pszFilename );
-    if( pwszFileName == NULL )
+    int rc = -1; 
+    if( pwszFileName != NULL )
     {
-        return -1;
-    }    
-    return _wremove( pwszFileName );
+        rc = _wremove( pwszFileName );
+    }
+    free ((wchar_t*) pwszFileName);
+    return rc;
 }
 
 #endif

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c	2008-01-08 23:32:59 UTC (rev 2801)
@@ -34,6 +34,9 @@
  ******************************************************************************
  *
  * $Log: shpopen.c,v $
+ * Revision 1.58  2008/01/08 23:28:26  bram
+ * on line 2095, use a float instead of a double to avoid a compiler warning
+ *
  * Revision 1.57  2007/12/06 07:00:25  fwarmerdam
  * dbfopen now using SAHooks for fileio
  *
@@ -2092,7 +2095,7 @@
                     /* Rule #2:
                     * Test if edge-ray intersection is on the right from the test point (dfTestY,dfTestY)
                     */
-                    float const intersect = 
+                    double const intersect = 
                         ( psObject->padfX[iEdge+nVertStart]
                           + ( dfTestY - psObject->padfY[iEdge+nVertStart] ) 
                           / ( psObject->padfY[iNext+nVertStart] - psObject->padfY[iEdge+nVertStart] )

Modified: branches/WIP-pyshapelib-Unicode/thuban/setup.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/setup.py	2008-01-08 15:55:20 UTC (rev 2800)
+++ branches/WIP-pyshapelib-Unicode/thuban/setup.py	2008-01-08 23:32:59 UTC (rev 2801)
@@ -269,38 +269,44 @@
 # shapelib wrappers are also distributed with thuban
 #
 
-def dbf_macros():
-	"""determine the macros to define when compiling the dbflib wrapper.
-	"""
-	f = open(convert_path(shp_dir + "/shapefil.h"))
-	contents = f.read()
-	f.close()
-	
-	def have(keyword):
-		if keyword in contents:
-			return "1"
-		return "0"
-	
-	return [
-		("HAVE_UPDATE_HEADER", have("DBFUpdateHeader")),
-		("HAVE_CODE_PAGE", have("DBFGetCodePage"))]
+def determine_macros():
+    f = open(convert_path(shp_dir + "/shapefil.h"))
+    contents = f.read()
+    f.close()
+    
+    def have(keyword):
+        if keyword in contents:
+            return "1"
+        return "0"
+    
+    return [
+        ("HAVE_UPDATE_HEADER", have("DBFUpdateHeader")),
+        ("HAVE_CODE_PAGE", have("DBFGetCodePage")),
+        ("HAVE_UTF8_HOOKS", have("SASetupUtf8Hooks"))]
 
+def search_sahooks_files():
+    candidates = [shp_dir + "/safileio.c"]
+    return filter(os.path.exists, candidates)
 
+macros = determine_macros()
+sahooks_files = search_sahooks_files()
+
 extensions.append(Extension("Lib.shapelib",
                             [ext_dir + "/pyshapelib/shapelibmodule.c",
                              shp_dir + "/shpopen.c",
-                             shp_dir + "/shptree.c",
-                             shp_dir + "/safileio.c"],
-                            include_dirs = [shp_dir]))
+                             shp_dir + "/shptree.c"]
+                             + sahooks_files],
+                            include_dirs = [shp_dir],
+                            define_macros = macros))
 extensions.append(Extension("Lib.shptree",
                             [ext_dir + "/pyshapelib/shptreemodule.c"],
                             include_dirs = [shp_dir]))
 extensions.append(Extension("Lib.dbflib",
                             [ext_dir + "/pyshapelib/dbflibmodule.c",
-                             shp_dir + "/dbfopen.c",
-                             shp_dir + "/safileio.c"],
+                             shp_dir + "/dbfopen.c"]
+                             + sahooks_files,
                             include_dirs = [shp_dir],
-                            define_macros = dbf_macros()))
+                            define_macros = macros))
 
 
 #
@@ -342,8 +348,8 @@
 
 #add the Lib content to the output
 if os.path.isdir("Lib"):
-	for d in os.listdir("Lib"):
-		data_files.append(("Lib", ["Lib/"+d]))
+    for d in os.listdir("Lib"):
+        data_files.append(("Lib", ["Lib/"+d]))
 
 
 #
@@ -960,14 +966,14 @@
         # Obviously have to build before we can install
 
         # add gdal to the build
-	for (dirpath, dnames, fnames) in os.walk('gdal'):			
-		files_in_dir = []
-		dp = '/'.join(dirpath.split('\\'))
-		for f in fnames:
-			if os.path.isfile(os.path.join(dirpath,f)):			
-				files_in_dir.append( dp + '/' + f)		
-		if len(files_in_dir) > 0:
-			data_files.append(( dp , files_in_dir))
+    for (dirpath, dnames, fnames) in os.walk('gdal'):			
+        files_in_dir = []
+        dp = '/'.join(dirpath.split('\\'))
+        for f in fnames:
+            if os.path.isfile(os.path.join(dirpath,f)):			
+                files_in_dir.append( dp + '/' + f)		
+        if len(files_in_dir) > 0:
+            data_files.append(( dp , files_in_dir))
         # add thubaninit to the build
 
 
@@ -1089,7 +1095,7 @@
             "warn_dir": 0,
             "extra_files": ["COPYING", "Lib/proj.dll"],
             }
-	install_options["extra_files"].extend(self.get_gdal_content())
+    install_options["extra_files"].extend(self.get_gdal_content())
 
         # don't make a symlink because we're simulating windows, so
         # that we can generate the iss-file even on Linux
@@ -1101,12 +1107,12 @@
         '''
         Return the list of files in the gdal directory of the Thuban installation
         '''
-	gdal_files = []
-	for (dirpath, dnames, fnames) in os.walk('gdal'):		    
-	    if len(fnames) > 0:
-	        for file in fnames :
-		    gdal_files.append(dirpath + os.sep + file)
-	return gdal_files
+    gdal_files = []
+    for (dirpath, dnames, fnames) in os.walk('gdal'):		    
+        if len(fnames) > 0:
+            for file in fnames :
+            gdal_files.append(dirpath + os.sep + file)
+    return gdal_files
 
 class thuban_build_docs(Command):
 
@@ -1198,8 +1204,8 @@
       packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI",
                   "Extensions", "Extensions.gns2shp", "Extensions.wms",
                   "Extensions.importAPR", "Extensions.profiling", 
-		          "Extensions.svgexport", "Extensions.mouseposition", 
-		          "Extensions.bboxdump", "Extensions.ogr", 
+                  "Extensions.svgexport", "Extensions.mouseposition", 
+                  "Extensions.bboxdump", "Extensions.ogr", 
                   "Extensions.umn_mapserver"],
       ext_modules = extensions,
       py_modules = py_modules,



More information about the Thuban-commits mailing list