Package: iso-codes
Version: 0.47

Attached is a patch that makes the Python scripts used to build
iso-codes work with both PyXML and Python's included XML modules.  This
makes it possible to build the package on systems without PyXML installed.

I also made some other minor changes:

    * use "#!/usr/bin/env python" as the first line of scripts so that
      they run when Python is in a non-standard location.
    * return a non-zero error code if the XML file can not be parsed, so
      the build will fail properly in that case.

The patch is against the latest CVS version of the package.

James.
Index: iso2pot.py
===================================================================
RCS file: /cvsroot/pkg-isocodes/iso-codes/iso2pot.py,v
retrieving revision 1.3
diff -u -p -r1.3 iso2pot.py
--- iso2pot.py	15 Jun 2004 20:36:43 -0000	1.3
+++ iso2pot.py	3 Oct 2005 03:25:48 -0000
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 #
 # Read iso-codes data file and output a .pot file
 # 
@@ -6,11 +6,11 @@
 # Released under the GPL.
 # $Id: iso2pot.py,v 1.3 2004/06/15 20:36:43 mckinstry Exp $
 
-from xml.sax import saxutils, make_parser, saxlib, saxexts, ContentHandler
-from xml.sax.handler import feature_namespaces
 import sys, os, getopt, urllib2, locale, time
+from xml.sax import make_parser, SAXException, SAXParseException
+from xml.sax.handler import feature_namespaces, ContentHandler
 
-class printPot(saxutils.DefaultHandler):
+class printPot(ContentHandler):
     def __init__(self, nameslist,comment, ofile):
          """ 
 	 nameslist is the elements to be printed in msgid strings,
@@ -100,17 +100,20 @@ else:
 printHeader(ofile, report_bugs_to, version)
 
 p = make_parser()
-p.setErrorHandler(saxutils.ErrorPrinter())
 
 try:
     dh = printPot(fields, comment, ofile)
     p.setContentHandler(dh)
     p.parse(trail[0])
-except IOError,e:
-    print in_sysID+": "+str(e)
-except saxlib.SAXException,e:
-    print str(e)
-
+except SAXParseException, e:
+    sys.stderr.write('%s:%s:%s: %s\n' % (e.getSystemId(),
+                                         e.getLineNumber(),
+                                         e.getColumnNumber(),
+                                         e.getMessage()))
+    sys.exit(1)
+except Exception, e:
+    sys.stderr.write('<unknown>: %s\n' % str(e))
+    sys.exit(1)
 
 ofile.close()
 
Index: iso2tab.py
===================================================================
RCS file: /cvsroot/pkg-isocodes/iso-codes/iso2tab.py,v
retrieving revision 1.1
diff -u -p -r1.1 iso2tab.py
--- iso2tab.py	16 May 2004 20:20:42 -0000	1.1
+++ iso2tab.py	3 Oct 2005 03:25:48 -0000
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 #
 # Read iso-codes data file and output a .tab file
 # 
@@ -6,11 +6,11 @@
 # Released under the GPL.
 # $Id: iso2tab.py,v 1.1 2004/05/16 20:20:42 mckinstry Exp $
 
-from xml.sax import saxutils, make_parser, saxlib, saxexts, ContentHandler
-from xml.sax.handler import feature_namespaces
 import sys, os, getopt, urllib2
+from xml.sax import make_parser, SAXException, SAXParseException
+from xml.sax.handler import feature_namespaces, ContentHandler
 
-class printLines(saxutils.DefaultHandler):
+class printLines(ContentHandler):
     def __init__(self,element, nameslist, ofile):
          """ 
 	 nameslist is the elements to be printed in  strings,
@@ -65,16 +65,20 @@ else:
     ofile = sys.stdout
 
 p = make_parser()
-p.setErrorHandler(saxutils.ErrorPrinter())
 
 try:
     dh = printLines(element, fields, ofile)
     p.setContentHandler(dh)
     p.parse(trail[0])
-except IOError,e:
-    print in_sysID+": "+str(e)
-except saxlib.SAXException,e:
-    print str(e)
+except SAXParseException, e:
+    sys.stderr.write('%s:%s:%s: %s\n' % (e.getSystemId(),
+                                         e.getLineNumber(),
+                                         e.getColumnNumber(),
+                                         e.getMessage()))
+    sys.exit(1)
+except Exception, e:
+    sys.stderr.write('<unknown>: %s\n' % str(e))
+    sys.exit(1)
 
 
 ofile.close()
Index: iso_3166/iso3166tab.py
===================================================================
RCS file: /cvsroot/pkg-isocodes/iso-codes/iso_3166/iso3166tab.py,v
retrieving revision 1.2
diff -u -p -r1.2 iso3166tab.py
--- iso_3166/iso3166tab.py	8 Jan 2005 18:06:46 -0000	1.2
+++ iso_3166/iso3166tab.py	3 Oct 2005 03:25:48 -0000
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 #
 # Read iso-codes data file and output a .tab file
 # 
@@ -6,11 +6,11 @@
 # Released under the GPL.
 # $Id: iso3166tab.py,v 1.2 2005/01/08 18:06:46 mckinstry Exp $
 
-from xml.sax import saxutils, make_parser, saxlib, saxexts, ContentHandler
-from xml.sax.handler import feature_namespaces
 import sys, os, getopt, urllib2
+from xml.sax import make_parser, SAXException, SAXParseException
+from xml.sax.handler import feature_namespaces, ContentHandler
 
-class printLines(saxutils.DefaultHandler):
+class printLines(ContentHandler):
 	def __init__(self, ofile):
 		self.ofile = ofile
 
@@ -43,14 +43,18 @@ class printLines(saxutils.DefaultHandler
 
 ofile = sys.stdout
 p = make_parser()
-p.setErrorHandler(saxutils.ErrorPrinter())
 try:
 	dh = printLines(ofile)
 	p.setContentHandler(dh)
 	p.parse(sys.argv[1])
-except IOError,e:
-	print in_sysID+": "+str(e)
-except saxlib.SAXException,e:
-	print str(e)
+except SAXParseException, e:
+	sys.stderr.write('%s:%s:%s: %s\n' % (e.getSystemId(),
+					     e.getLineNumber(),
+					     e.getColumnNumber(),
+					     e.getMessage()))
+	sys.exit(1)
+except Exception, e:
+	sys.stderr.write('<unknown>: %s\n' % str(e))
+	sys.exit(1)
 
 ofile.close()
Index: iso_639/iso639tab.py
===================================================================
RCS file: /cvsroot/pkg-isocodes/iso-codes/iso_639/iso639tab.py,v
retrieving revision 1.1
diff -u -p -r1.1 iso639tab.py
--- iso_639/iso639tab.py	2 Mar 2005 07:24:51 -0000	1.1
+++ iso_639/iso639tab.py	3 Oct 2005 03:25:48 -0000
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 #
 # Read iso-codes iso_639.xml data file and output a .tab file
 # 
@@ -6,11 +6,11 @@
 # Released under the GPL.
 # $Id: iso639tab.py,v 1.1 2005/03/02 07:24:51 mckinstry Exp $
 
-from xml.sax import saxutils, make_parser, saxlib, saxexts, ContentHandler
-from xml.sax.handler import feature_namespaces
 import sys, os, getopt, urllib2
+from xml.sax import make_parser, SAXException, SAXParseException
+from xml.sax.handler import feature_namespaces, ContentHandler
 
-class printLines(saxutils.DefaultHandler):
+class printLines(ContentHandler):
 	def __init__(self, ofile):
 		self.ofile = ofile
 
@@ -68,14 +68,18 @@ ofile.write("""
 ##
 """)
 p = make_parser()
-p.setErrorHandler(saxutils.ErrorPrinter())
 try:
 	dh = printLines(ofile)
 	p.setContentHandler(dh)
 	p.parse(sys.argv[1])
-except IOError,e:
-	print in_sysID+": "+str(e)
-except saxlib.SAXException,e:
-	print str(e)
+except SAXParseException, e:
+	sys.stderr.write('%s:%s:%s: %s\n' % (e.getSystemId(),
+					     e.getLineNumber(),
+					     e.getColumnNumber(),
+					     e.getMessage()))
+	sys.exit(1)
+except Exception, e:
+	sys.stderr.write('<unknown>: %s\n' % str(e))
+	sys.exit(1)
 
 ofile.close()

Reply via email to