mailr17712 - in /trunk: generic_fns/structure/internal.py relax_io.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 07, 2012 - 15:50:
Author: bugman
Date: Sun Oct  7 15:50:10 2012
New Revision: 17712

URL: http://svn.gna.org/viewcvs/relax?rev=17712&view=rev
Log:
Reverted revisions r17702, r17701, r17693, r17687, r17685, r17684, and r17669.

The command used were:
svn merge -r17702:17669 relax_io.py
svn merge -r17702:r17701 
/data/relax/relax-trunk/generic_fns/structure/internal.py

The relax_io module should now handle all files as text, independent of 
compression.  These reverted
revisions were attempts at fixing the buggy behaviour of Python 3.0, 3.1 and 
3.2.  But now the
io.TextIOWrapper() class is being used to eliminate the byte streams, which 
should be text streams.


Modified:
    trunk/generic_fns/structure/internal.py
    trunk/relax_io.py

Modified: trunk/generic_fns/structure/internal.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/generic_fns/structure/internal.py?rev=17712&r1=17711&r2=17712&view=diff
==============================================================================
--- trunk/generic_fns/structure/internal.py (original)
+++ trunk/generic_fns/structure/internal.py Sun Oct  7 15:50:10 2012
@@ -37,7 +37,7 @@
 from generic_fns.mol_res_spin import Selection
 from generic_fns.structure.api_base import Base_struct_API, ModelList, 
Displacements
 from relax_errors import RelaxError, RelaxNoneIntError, RelaxNoPdbError
-from relax_io import file_root, open_read_file, readlines
+from relax_io import file_root, open_read_file
 from relax_warnings import RelaxWarning
 
 
@@ -262,8 +262,10 @@
         @rtype:             tuple of int and array of str
         """
 
-        # Read the lines from the file.
-        lines = readlines(file_path)
+        # Open the file.
+        file = open_read_file(file_path)
+        lines = file.readlines()
+        file.close()
 
         # Check for empty files.
         if lines == []:
@@ -314,8 +316,10 @@
         @rtype:             tuple of int and array of str
         """
 
-        # Read the lines from the file.
-        lines = readlines(file_path)
+        # Open the file.
+        file = open_read_file(file_path)
+        lines = file.readlines()
+        file.close()
 
         # Check for empty files.
         if lines == []:

Modified: trunk/relax_io.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/relax_io.py?rev=17712&r1=17711&r2=17712&view=diff
==============================================================================
--- trunk/relax_io.py (original)
+++ trunk/relax_io.py Sun Oct  7 15:50:10 2012
@@ -47,7 +47,6 @@
 
 # relax module imports.
 from check_types import is_filetype
-from compat import py_version
 import generic_fns
 from relax_errors import RelaxError, RelaxFileError, 
RelaxFileOverwriteError, RelaxInvalidSeqError, RelaxMissingBinaryError, 
RelaxNoInPathError, RelaxNonExecError
 from relax_warnings import RelaxWarning, RelaxFileEmptyWarning
@@ -154,7 +153,7 @@
     data = []
     for i in range(len(file_data)):
         # Python 3 support - conversion of bytes type objects to strings.
-        if py_version == 3 and hasattr(file_data[i], 'decode'):
+        if hasattr(file_data[i], 'decode'):
             file_data[i] = file_data[i].decode()
 
         if sep:
@@ -695,34 +694,6 @@
         raise RelaxError("No corresponding data could be found within the 
file.")
 
 
-def readlines(file_path):
-    """Open the file given by the file path and returning a list of strings 
for each line.
-
-    The method is needed as bz2 compressed files return lists of byte 
strings and no longer normal
-    strings in Python 3!  This might be a temporary workaround to a 
temporary bug.
-
-
-    @param file_path:   The path of the file to open and read.
-    @type file_path:    str
-    @return:            The list of lines.
-    @rtype:             list of str
-    """
-
-    # Open the file.
-    file = open_read_file(file_path)
-    lines = file.readlines()
-    file.close()
-
-    # Convert the data from byte strings if needed.
-    if len(lines) and isinstance(lines[0], bytes):
-        for i in range(len(lines)):
-            print(dir(lines[i]))
-            lines[i] = lines[i].decode()
-
-    # Return the list of strings.
-    return lines
-
-
 def strip(data, comments=True):
     """Remove all comment and empty lines from the file data structure.
 
@@ -1097,17 +1068,8 @@
     def __init__(self):
         """Set up the dummy object to act as a file object."""
 
-        # Initialise for Python 2.
-        if py_version == 2:
-            self.data = ''
-            self._newline = '\n'
-            self._empty = ''
-
-        # Initialise for Python 3 (inside a eval statements to allow Python 
2.5 and lower to parse this and run).
-        elif py_version == 3:
-            self.data = eval("b''")
-            self._newline = eval("b'\n'")
-            self._empty = eval("b''")
+        # Initialise an object for adding the string from all write calls to.
+        self.data = ''
 
         # Set the closed flag.
         self.closed = False
@@ -1146,15 +1108,15 @@
         """
 
         # Split up the string.
-        lines = self.data.split(self._newline)
+        lines = self.data.split('\n')
 
         # Remove the last line if empty.
-        if lines[-1] == self._empty:
+        if lines[-1] == '':
             lines.pop()
 
         # Loop over the lines, re-adding the newline character to match the 
file object readlines() method.
         for i in range(len(lines)):
-            lines[i] = lines[i] + self._newline
+            lines[i] = lines[i] + '\n'
 
         # Return the file lines.
         return lines




Related Messages


Powered by MHonArc, Updated Sun Oct 07 16:00:02 2012