3737import datetime
3838
3939from . import cadef
40- from . import py23
4140
4241
4342__all__ = [
@@ -215,6 +214,11 @@ class ca_timestamp(ctypes.Structure):
215214# ----------------------------------------------------------------------------
216215# DBR type definitions
217216
217+ # Default string decoding method
218+ def decode (s ):
219+ return s .decode ('UTF-8' , 'replace' )
220+
221+
218222# All the following types are used to overlay dbr data returned from channel
219223# access or passed into channel access.
220224
@@ -241,7 +245,7 @@ def copy_attributes_ctrl(self, other):
241245 other .status = self .status
242246 other .severity = self .severity
243247
244- other .units = py23 . decode (ctypes .string_at (self .units ))
248+ other .units = decode (ctypes .string_at (self .units ))
245249 other .upper_disp_limit = self .upper_disp_limit
246250 other .lower_disp_limit = self .lower_disp_limit
247251 other .upper_alarm_limit = self .upper_alarm_limit
@@ -431,7 +435,7 @@ def copy_attributes(self, other):
431435 other .status = self .status
432436 other .severity = self .severity
433437 other .enums = [
434- py23 . decode (ctypes .string_at (s ))
438+ decode (ctypes .string_at (s ))
435439 for s in self .raw_strs [:self .no_str ]]
436440
437441class dbr_ctrl_char (ctypes .Structure ):
@@ -631,10 +635,9 @@ def _datatype_to_dbr(datatype):
631635 # with filtering through our array of acceptable types.
632636 return NumpyCharCodeToDbr [numpy .dtype (datatype ).char ]
633637 except Exception as error :
634- py23 .raise_from (
635- InvalidDatatype (
636- 'Datatype "%s" not supported for channel access' % datatype ),
637- error )
638+ raise InvalidDatatype (
639+ 'Datatype "%s" not supported for channel access' % datatype
640+ ) from error
638641
639642def _type_to_dbrcode (datatype , format ):
640643 '''Converts a datatype and format request to a dbr value, or raises an
@@ -704,7 +707,7 @@ def _string_at(raw_value, count):
704707
705708# Conversion from char array to strings
706709def _convert_char_str (raw_dbr , count ):
707- return ca_str (py23 . decode (_string_at (raw_dbr .raw_value , count )))
710+ return ca_str (decode (_string_at (raw_dbr .raw_value , count )))
708711
709712# Conversion from char array to bytes strings
710713def _convert_char_bytes (raw_dbr , count ):
@@ -717,9 +720,9 @@ def _convert_char_unicode(raw_dbr, count):
717720
718721# Arrays of standard strings.
719722def _convert_str_str (raw_dbr , count ):
720- return ca_str (py23 . decode (_make_strings (raw_dbr , count )[0 ]))
723+ return ca_str (decode (_make_strings (raw_dbr , count )[0 ]))
721724def _convert_str_str_array (raw_dbr , count ):
722- strings = [py23 . decode (s ) for s in _make_strings (raw_dbr , count )]
725+ strings = [decode (s ) for s in _make_strings (raw_dbr , count )]
723726 return _string_array (strings , count , str_char_code )
724727
725728# Arrays of bytes strings.
0 commit comments