[chirp_devel] [PATCH] [ft857/897] Safe convert Yaesu char sequences to string
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1448303630 -3600 # Mon Nov 23 19:33:50 2015 +0100 # Node ID 59f64701ea49dc7558955f0b4f1efbfcec2d3605 # Parent 833076e84df1b34708e44ddce138638faef6e837 [ft857/897] Safe convert Yaesu char sequences to string
Sometime in beacon text (or similar settings) an unknown char can be found, we now convert those settings to string in a safer way
Fix #3017
diff -r 833076e84df1 -r 59f64701ea49 chirp/drivers/ft857.py --- a/chirp/drivers/ft857.py Tue Nov 17 05:55:32 2015 -0600 +++ b/chirp/drivers/ft857.py Mon Nov 23 19:33:50 2015 +0100 @@ -25,6 +25,7 @@ import os import logging from textwrap import dedent +from chirp.util import safe_charset_string
LOG = logging.getLogger(__name__)
@@ -569,29 +570,34 @@ RadioSettingValueBoolean(_settings.arts_id)) extended.append(rs) st = RadioSettingValueString(0, 10, - ''.join([self._CALLSIGN_CHARSET[x] - for x in self._memobj.arts_idw])) + safe_charset_string( + self._memobj.arts_idw, + self._CALLSIGN_CHARSET) + ) st.set_charset(self._CALLSIGN_CHARSET) rs = RadioSetting("arts_idw", "ARTS IDW", st) extended.append(rs) st = RadioSettingValueString(0, 40, - ''.join([self._BEACON_CHARSET[x] - for x in self._memobj.beacon_text1 - ])) + safe_charset_string( + self._memobj.beacon_text1, + self._BEACON_CHARSET) + ) st.set_charset(self._BEACON_CHARSET) rs = RadioSetting("beacon_text1", "Beacon text1", st) extended.append(rs) st = RadioSettingValueString(0, 40, - ''.join([self._BEACON_CHARSET[x] - for x in - self._memobj.beacon_text2])) + safe_charset_string( + self._memobj.beacon_text2, + self._BEACON_CHARSET) + ) st.set_charset(self._BEACON_CHARSET) rs = RadioSetting("beacon_text2", "Beacon text2", st) extended.append(rs) st = RadioSettingValueString(0, 40, - ''.join([self._BEACON_CHARSET[x] - for x in - self._memobj.beacon_text3])) + safe_charset_string( + self._memobj.beacon_text3, + self._BEACON_CHARSET) + ) st.set_charset(self._BEACON_CHARSET) rs = RadioSetting("beacon_text3", "Beacon text3", st) extended.append(rs) @@ -856,16 +862,18 @@ RadioSettingValueInteger(0, 100, _settings.nb_level)) basic.append(rs) st = RadioSettingValueString(0, 4, - ''.join([self._CALLSIGN_CHARSET[x] - for x in - self._memobj.op_filter1_name])) + safe_charset_string( + self._memobj.op_filter1_name, + self._CALLSIGN_CHARSET) + ) st.set_charset(self._CALLSIGN_CHARSET) rs = RadioSetting("op_filter1_name", "Optional filter1 name", st) extended.append(rs) st = RadioSettingValueString(0, 4, - ''.join([self._CALLSIGN_CHARSET[x] - for x in - self._memobj.op_filter2_name])) + safe_charset_string( + self._memobj.op_filter2_name, + self._CALLSIGN_CHARSET) + ) st.set_charset(self._CALLSIGN_CHARSET) rs = RadioSetting("op_filter2_name", "Optional filter2 name", st) extended.append(rs) diff -r 833076e84df1 -r 59f64701ea49 chirp/util.py --- a/chirp/util.py Tue Nov 17 05:55:32 2015 -0600 +++ b/chirp/util.py Mon Nov 23 19:33:50 2015 +0100 @@ -94,3 +94,16 @@ for k, v in thedict.items(): _dict[v] = k return _dict[value] + + +def safe_charset_string(indexes, charset, safechar = " "): + """Return a string from an array of charset indexes, + replaces out of charset values with safechar""" + assert safechar in charset + _string = "" + for i in indexes: + try: + _string += charset[i] + except IndexError: + _string += safechar + return _string \ No newline at end of file
participants (1)
-
Marco Filippi IZ3GME