Changeset 13618


Ignore:
Timestamp:
Sep 30, 2019 2:31:26 PM (2 months ago)
Author:
randersson
Message:

#5819 Replaced IOError to OSError since it has been merged since python 3.3. Fixed such that self.last is no longer decoded from bytes and is instead the decoding + convert to str is only done on the objects where it is needed (such as when using count, find, split). This enables self.last to be of the type required by the version of xmlparser used, and no longer overridden.

Location:
branches/dev-5819/Python/src/pymodelica
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-5819/Python/src/pymodelica/compiler_logging.py

    r13600 r13618  
    114114            # apparently self.last is of class 'bytes' in py3
    115115            # compared to class 'str' in py2
    116             self.last = self.last.decode('utf-8')
    117             self.line += self.last.count('\n')
     116            self.line += str(self.last.decode('utf-8')).count('\n')
    118117            # Get the two last lines
    119             lines = self.last.rsplit('\n', 2)
     118            lines = str(self.last.decode('utf-8')).rsplit('\n', 2)
    120119            # Update lastLine and secondLastLine depending on how many
    121120            # rows we got
     
    145144        dump_file.write(self.last)
    146145       
    147         lines = self.last.split('\n')
     146        lines = str(self.last.decode('utf-8')).split('\n')
    148147        lines[0] = self.lastLine + lines[0]
    149148       
     
    157156            dump_file.write(more)
    158157            while localLine + 2 >= len(lines) and more:
    159                 pos = more.find('\n')
     158                pos = str(more.decode('utf-8')).find('\n')
    160159                if pos == -1:
    161160                    lines[-1] = lines[-1] + more
     
    191190       
    192191        # Discard remaining data.
    193         data = self.stream.read()
    194         dump_file.write(data)
    195         while data is None or data != '':
     192        # Check if not already closed since later versions of xmlreader closes it by itself
     193        if not self.stream.closed:
    196194            data = self.stream.read()
    197195            dump_file.write(data)
    198         dump_file.close()
     196            while data is None or data != '':
     197                data = self.stream.read()
     198                dump_file.write(data)
     199            dump_file.close()
    199200       
    200201        message += "%sDump of the log has been saved in %s" % (os.linesep, dump_file.name)
  • branches/dev-5819/Python/src/pymodelica/compiler_wrappers.py

    r13593 r13618  
    390390            CompilerError if one or more error is found during compilation.
    391391           
    392             IOError if the model file is not found, can not be read or any other
    393             IO related error.
     392            OSError if the model file is not found, can not be read or any other
     393            OS related error.
    394394           
    395395            Exception if there are general errors related to the parsing of the
     
    471471            ModelicaClassNotFoundError if the model class is not found.
    472472           
    473             IOError if the model file is not found, can not be read or any
    474             other IO related error.
     473            OSError if the model file is not found, can not be read or any
     474            other OS related error.
    475475           
    476476            JError if there was a runtime exception thrown by the underlying
     
    502502        Raises::
    503503       
    504             IOError if the model file is not found, can not be read or any other
    505             IO related error.
     504            OSError if the model file is not found, can not be read or any other
     505            OS related error.
    506506               
    507507            JError if there was a runtime exception thrown by the underlying
     
    566566       
    567567        if _py_handle_exception(ex, jpype.java.io.FileNotFoundException):
    568             raise IOError(
     568            raise OSError(
    569569                '\nMessage: '+ex.message().encode('utf-8')+\
    570570                '\nStacktrace: '+ex.stacktrace().encode('utf-8'))
    571571       
    572572        if _py_handle_exception(ex, jpype.java.io.IOException):
    573             raise IOError(
     573            raise OSError(
    574574                '\nMessage: '+str(ex.message().encode('utf-8'))+\
    575575                '\nStacktrace: '+str(ex.stacktrace().encode('utf-8')))
Note: See TracChangeset for help on using the changeset viewer.