[ck2cti] Fix reading some input files containing non-unicode characters
In Python 3, attempting to convert some mechanisms would give errors like the following: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 348: invalid start byte
This commit is contained in:
parent
94d924e32d
commit
9f6c9e3a46
2 changed files with 10 additions and 0 deletions
|
|
@ -64,15 +64,24 @@ ENERGY_UNITS = {'CAL/': 'cal/mol',
|
|||
'KJOULES/MOL': 'kJ/mol',
|
||||
'KJOULES/MOLE': 'kJ/mol'}
|
||||
|
||||
_open = open
|
||||
if sys.version_info[0] == 2:
|
||||
string_types = (str, unicode)
|
||||
def strip_nonascii(s):
|
||||
return s.decode('ascii', 'ignore')
|
||||
|
||||
def open(filename, *args):
|
||||
return _open(filename, *args)
|
||||
|
||||
else:
|
||||
string_types = (str,)
|
||||
def strip_nonascii(s):
|
||||
return s.encode('ascii', 'ignore').decode()
|
||||
|
||||
def open(filename, *args):
|
||||
return _open(filename, *args, errors='ignore')
|
||||
|
||||
|
||||
def compatible_quantities(quantity_basis, units):
|
||||
if quantity_basis == 'mol':
|
||||
return 'molec' not in units
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
! Generic mechanism header
|
||||
! This line contains a non-unicode character () that should just be ignored.
|
||||
ELEMENTS
|
||||
H C
|
||||
END
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue