Changeset 7b50f14 in sasview for src


Ignore:
Timestamp:
Sep 22, 2017 7:40:41 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
d04ac05
Parents:
46cf4c9
Message:

restore python 2 functionality

Location:
src/sas/sascalc/dataloader
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/file_reader_base_class.py

    r26183bf r7b50f14  
    66 
    77import os 
     8import sys 
    89import re 
    910import logging 
     
    1819logger = logging.getLogger(__name__) 
    1920 
     21if sys.version_info[0] < 3: 
     22    def decode(s): 
     23        return s 
     24else: 
     25    def decode(s): 
     26        return s.decode() if isinstance(s, bytes) else s 
    2027 
    2128class FileReader(object): 
     
    8592        """ 
    8693        #return self.f_open.readline() 
    87         return self.f_open.readline().decode() 
     94        return decode(self.f_open.readline()) 
    8895 
    8996    def nextlines(self): 
     
    93100        for line in self.f_open: 
    94101            #yield line 
    95             yield line.decode() 
     102            yield decode(line) 
    96103 
    97104    def readall(self): 
     
    100107        """ 
    101108        #return self.f_open.read() 
    102         return self.f_open.read().decode() 
     109        return decode(self.f_open.read()) 
    103110 
    104111    def handle_error_message(self, msg): 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    r5c5e7fd r7b50f14  
    99import sys 
    1010 
    11 from sas.sascalc.dataloader.data_info import plottable_1D, plottable_2D,\ 
     11from ..data_info import plottable_1D, plottable_2D,\ 
    1212    Data1D, Data2D, DataInfo, Process, Aperture, Collimation, \ 
    1313    TransmissionSpectrum, Detector 
    14 from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
    15 from sas.sascalc.dataloader.loader_exceptions import FileContentsException, DefaultReaderException 
    16 from sas.sascalc.dataloader.file_reader_base_class import FileReader 
    17  
    18 def decode(s): 
    19     return s.decode() if isinstance(s, bytes) else s 
     14from ..data_info import combine_data_info_with_plottable 
     15from ..loader_exceptions import FileContentsException, DefaultReaderException 
     16from ..file_reader_base_class import FileReader, decode 
    2017 
    2118def h5attr(node, key, default=None): 
     
    135132            # Get all information for the current key 
    136133            value = data.get(key) 
    137             classname = h5attr(value, u'canSAS_class') 
    138             if classname is None: 
     134            class_name = h5attr(value, u'canSAS_class') 
     135            if class_name is None: 
    139136                class_name = h5attr(value, u'NX_class') 
    140137            if class_name is not None: 
     
    240237                            run_dict = {data_point: run_name} 
    241238                            self.current_datainfo.run_name = run_dict 
    242                         except: 
     239                        except Exception: 
    243240                            pass 
    244241                    elif key == u'title': 
  • src/sas/sascalc/dataloader/readers/xml_reader.py

    r5a6a84e r7b50f14  
    2020from lxml.builder import E 
    2121 
    22 from sas.sascalc.dataloader.file_reader_base_class import FileReader 
     22from ..file_reader_base_class import FileReader, decode 
    2323 
    2424logger = logging.getLogger(__name__) 
     
    153153        Converts an etree element into a string 
    154154        """ 
    155         return etree.tostring(elem, pretty_print=pretty_print, 
    156                               encoding=encoding).decode() 
     155        return decode(etree.tostring(elem, pretty_print=pretty_print, 
     156                                     encoding=encoding)) 
    157157 
    158158    def break_processing_instructions(self, string, dic): 
Note: See TracChangeset for help on using the changeset viewer.