Changeset 9efdb29 in sasview


Ignore:
Timestamp:
Sep 25, 2017 9:13:29 AM (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:
9e6aeaf
Parents:
b796c72
Message:

further python3 conversion cleanup for cansas

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    re6e89c4 r9efdb29  
    3434INVALID_XML = "\n\nThe loaded xml file, {0} does not fully meet the CanSAS v1.x specification. SasView loaded " + \ 
    3535              "as much of the data as possible.\n\n" 
    36 HAS_CONVERTER = True 
    3736 
    3837CONSTANTS = CansasConstants() 
     
    160159                raise fc_exc 
    161160        except Exception as e: # Convert all other exceptions to FileContentsExceptions 
    162             raise 
    163161            raise FileContentsException(str(e)) 
    164162 
     
    634632                        and local_unit.lower() != default_unit.lower() 
    635633                        and local_unit.lower() != "none"): 
    636                     if HAS_CONVERTER: 
    637                         # Check local units - bad units raise KeyError 
    638                         #print("loading", tagname, node_value, local_unit, default_unit) 
    639                         data_conv_q = Converter(local_unit) 
    640                         value_unit = default_unit 
    641                         node_value = data_conv_q(node_value, units=default_unit) 
    642                     else: 
    643                         value_unit = local_unit 
    644                         err_msg = "Unit converter is not available.\n" 
     634                    # Check local units - bad units raise KeyError 
     635                    #print("loading", tagname, node_value, local_unit, default_unit) 
     636                    data_conv_q = Converter(local_unit) 
     637                    value_unit = default_unit 
     638                    node_value = data_conv_q(node_value, units=default_unit) 
    645639                else: 
    646640                    value_unit = local_unit 
     
    12871281                local_unit = getattr(storage, toks[0]+"_unit") 
    12881282                if local_unit is not None and units.lower() != local_unit.lower(): 
    1289                     if HAS_CONVERTER == True: 
    1290                         try: 
    1291                             conv = Converter(units) 
    1292                             setattrchain(storage, variable, conv(value, units=local_unit)) 
    1293                         except Exception: 
    1294                             _, exc_value, _ = sys.exc_info() 
    1295                             err_mess = "CanSAS reader: could not convert" 
    1296                             err_mess += " %s unit [%s]; expecting [%s]\n  %s" \ 
    1297                                 % (variable, units, local_unit, exc_value) 
    1298                             self.errors.add(err_mess) 
    1299                             if optional: 
    1300                                 logger.info(err_mess) 
    1301                             else: 
    1302                                 raise ValueError(err_mess) 
    1303                     else: 
    1304                         err_mess = "CanSAS reader: unrecognized %s unit [%s];"\ 
    1305                         % (variable, units) 
    1306                         err_mess += " expecting [%s]" % local_unit 
     1283                    try: 
     1284                        conv = Converter(units) 
     1285                        setattrchain(storage, variable, conv(value, units=local_unit)) 
     1286                    except Exception: 
     1287                        _, exc_value, _ = sys.exc_info() 
     1288                        err_mess = "CanSAS reader: could not convert" 
     1289                        err_mess += " %s unit [%s]; expecting [%s]\n  %s" \ 
     1290                            % (variable, units, local_unit, exc_value) 
    13071291                        self.errors.add(err_mess) 
    13081292                        if optional: 
     
    13331317        entry = get_content(location, node) 
    13341318        if entry is not None and entry.text is not None: 
    1335             exec("storage.%s = entry.text.strip()" % variable) 
     1319            setattrchain(storage, variable, entry.text.strip()) 
    13361320 
    13371321# DO NOT REMOVE Called by outside packages: 
Note: See TracChangeset for help on using the changeset viewer.