Our old data acquisition unit still uses the old Macintosh (OS9 and older) LF-
only line terminators.  This patch adds the U flag to the file read commands so 
that python will handle this special case.  It should also allow python to 
properly handle windows terminators on Linux and vise-versa.  (Both worked for 
me on my Linux box pre-patch, so you may be specifically looking for a carriage 
return somewhere.  I didn't test the mac/windows terminators that much to see 
if the behavior was correct.  All my data is in the MAC format.  I can confirm 
that this works correctly for me with my LF-only data files.  I did check that 
the other two still seem to work post-patch.)

FYI, Windows(DOS) uses CR-LF and linux(unix) uses CR-only.

Bryan
-- 
Bryan Harris
Research Engineer
Structures and Materials Evaluation Group
[email protected]
http://www.udri.udayton.edu/
(937) 229-5561

diff -ru veusz-1.3/dialogs/importdialog.py veusz-1.3-BH/dialogs/importdialog.py
--- veusz-1.3/dialogs/importdialog.py	2009-02-11 03:25:51.000000000 -0500
+++ veusz-1.3-BH/dialogs/importdialog.py	2009-03-19 11:07:32.000000000 -0400
@@ -134,7 +134,7 @@
         """Standard preview - show start of text."""
 
         try:
-            ifile = open(filename, 'r')
+            ifile = open(filename, 'rU')
         except IOError:
             self.previewedit.setPlainText('')
             return False
@@ -154,7 +154,7 @@
         t.setColumnCount(0)
         t.setRowCount(0)
         try:
-            ifile = open(filename, 'r')
+            ifile = open(filename, 'rU')
 
             # construct list of rows from input file
             reader = csv.reader(ifile)
@@ -209,7 +209,7 @@
         
         # try to identify fits file
         try:
-            ifile = open(filename)
+            ifile = open(filename,  'rU')
             line = ifile.readline()
             # is this a hack?
             if line.find('SIMPLE  =                    T') == -1:
@@ -226,7 +226,7 @@
         """Preview 2d dataset files."""
         
         try:
-            ifile = open(filename, 'r')
+            ifile = open(filename, 'rU')
         except IOError:
             self.twod_previewedit.setPlainText('')
             return False
diff -ru veusz-1.3/document/commandinterpreter.py veusz-1.3-BH/document/commandinterpreter.py
--- veusz-1.3/document/commandinterpreter.py	2009-02-11 03:25:57.000000000 -0500
+++ veusz-1.3-BH/document/commandinterpreter.py	2009-03-19 10:50:21.000000000 -0400
@@ -171,7 +171,7 @@
         # FIXME: should update filename in main window
         # This gives the document a __file__ variable so it
         # knows what it is
-        f = open(filename, 'r')
+        f = open(filename, 'rU')
         self.document.wipe()
         self.interface.To('/')
         oldfile = self.globals['__file__']
diff -ru veusz-1.3/document/datasets.py veusz-1.3-BH/document/datasets.py
--- veusz-1.3/document/datasets.py	2009-02-11 03:25:57.000000000 -0500
+++ veusz-1.3-BH/document/datasets.py	2009-03-19 11:06:01.000000000 -0400
@@ -122,7 +122,7 @@
         
         tempdoc = doc.Document()
         sr = simpleread.SimpleRead(self.descriptor)
-        sr.readData( simpleread.FileStream(open(self.filename)),
+        sr.readData( simpleread.FileStream(open(self.filename,  'rU')),
                      useblocks=self.useblocks )
         sr.setInDocument(tempdoc, linkedfile=self)
 
diff -ru veusz-1.3/document/operations.py veusz-1.3-BH/document/operations.py
--- veusz-1.3/document/operations.py	2009-02-11 03:25:57.000000000 -0500
+++ veusz-1.3-BH/document/operations.py	2009-03-19 11:09:26.000000000 -0400
@@ -665,7 +665,7 @@
         
         # open stream to import data from
         if self.filename is not None:
-            stream = simpleread.FileStream( open(self.filename) )
+            stream = simpleread.FileStream( open(self.filename,  'rU') )
         elif self.datastr is not None:
             stream = simpleread.StringStream(self.datastr)
         else:
diff -ru veusz-1.3/windows/mainwindow.py veusz-1.3-BH/windows/mainwindow.py
--- veusz-1.3/windows/mainwindow.py	2009-02-11 03:25:53.000000000 -0500
+++ veusz-1.3-BH/windows/mainwindow.py	2009-03-19 10:50:21.000000000 -0400
@@ -657,7 +657,7 @@
 
         # read script
         try:
-            script = open(filename, 'r').read()
+            script = open(filename, 'rU').read()
         except IOError, e:
             qt4.QApplication.restoreOverrideCursor()
             qt4.QMessageBox("Cannot open document",
_______________________________________________
Veusz-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/veusz-discuss

Répondre à