Skip to content

Commit

Permalink
Fix #344, 'raw_unicode_escape' -> 'latin-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-carboni committed Jan 21, 2024
1 parent 0391c67 commit 9aaa625
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions simulators/acu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def __init__(self, sampling_time=default_sampling_time):
self.command_threads = Queue()

self.status = Array(c_char, 813)
self.status[0:4] = bytes(start_flag, 'raw_unicode_escape')
self.status[0:4] = bytes(start_flag, 'latin-1')
self.status[4:8] = utils.uint_to_bytes(813)
self.status[-4:] = bytes(end_flag, 'raw_unicode_escape')
self.status[-4:] = bytes(end_flag, 'latin-1')

subsystems = []
subsystems.append(self.PS.update_status)
Expand Down
5 changes: 1 addition & 4 deletions simulators/gaia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ def _execute(self, msg):

def _error(self, error_code):
error_string = self.errors.get(error_code)
hex_string = codecs.encode(
error_string.encode('raw_unicode_escape'),
'hex'
)
hex_string = codecs.encode(error_string.encode('latin-1'), 'hex')
retval = f'{self.header}ERROR({error_code})[{error_string}]'
retval += f'({hex_string}) {self.cmd_id}{self.tail}'
return retval
Expand Down
8 changes: 4 additions & 4 deletions simulators/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _execute_custom_command(self, msg_body):
response = getattr(self.system, name)(*params)
if isinstance(response, str):
self.socket.sendto(
response.encode('raw_unicode_escape'),
response.encode('latin-1'),
self.client_address
)
if response == '$server_shutdown%%%%%':
Expand All @@ -82,7 +82,7 @@ def setup(self):
greet_msg = self.system.system_greet()
if greet_msg:
self.socket.sendto(
greet_msg.encode('raw_unicode_escape'),
greet_msg.encode('latin-1'),
self.client_address
)
else: # UDP client
Expand Down Expand Up @@ -134,7 +134,7 @@ def _handle(self, msg):
pass
elif response and isinstance(response, str):
try:
response = response.encode('raw_unicode_escape')
response = response.encode('latin-1')
self.socket.sendto(response, self.client_address)
except IOError: # skip coverage
# Something went wrong while sending the response,
Expand Down Expand Up @@ -183,7 +183,7 @@ def handle(self):
# Check if the client is sending a custom command
if not custom_msg:
break
custom_msg = custom_msg.decode('raw_unicode_escape')
custom_msg = custom_msg.decode('latin-1')
if (
custom_msg.startswith(self.custom_header)
and custom_msg.endswith(self.custom_tail)
Expand Down
2 changes: 1 addition & 1 deletion simulators/totalpower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _get_status(self, ascii_format=False):
status += '111'
status = binary_to_string(status)
if not ascii_format:
return status.encode('raw_unicode_escape')
return status.encode('latin-1')
else:
return ''.join([hex(ord(c))[-2:] for c in status[::-1]])

Expand Down
16 changes: 8 additions & 8 deletions simulators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def binary_to_string(binary_string, little_endian=True):
return binary_to_bytes(
binary_string,
little_endian
).decode('raw_unicode_escape')
).decode('latin-1')


def bytes_to_int(byte_string, little_endian=True):
Expand Down Expand Up @@ -235,7 +235,7 @@ def string_to_int(string, little_endian=True):
>>> string_to_int('hello', False)
448378203247
"""
return bytes_to_int(string.encode('raw_unicode_escape'), little_endian)
return bytes_to_int(string.encode('latin-1'), little_endian)


def bytes_to_binary(byte_string, little_endian=True):
Expand Down Expand Up @@ -277,7 +277,7 @@ def string_to_binary(string, little_endian=True):
>>> string_to_binary('hi', little_endian=False)
'0110100001101001'
"""
return bytes_to_binary(string.encode('raw_unicode_escape'), little_endian)
return bytes_to_binary(string.encode('latin-1'), little_endian)


def bytes_to_uint(byte_string, little_endian=True):
Expand Down Expand Up @@ -311,7 +311,7 @@ def string_to_uint(string, little_endian=True):
>>> string_to_uint('hi', little_endian=False)
26729
"""
return bytes_to_uint(string.encode('raw_unicode_escape'), little_endian)
return bytes_to_uint(string.encode('latin-1'), little_endian)


def real_to_binary(num, precision=1):
Expand Down Expand Up @@ -403,7 +403,7 @@ def real_to_string(num, precision=1, little_endian=True):

binary_number = real_to_binary(num, precision)
binary_number = binary_to_bytes(binary_number, little_endian=little_endian)
return binary_number.decode('raw_unicode_escape')
return binary_number.decode('latin-1')


def bytes_to_real(bytes_real, precision=1, little_endian=True):
Expand Down Expand Up @@ -459,7 +459,7 @@ def string_to_real(string_real, precision=1, little_endian=True):
>>> round(string_to_real('\x40\x7A\x25\x7D\x2E\x68\x51\x5D', 2, False), 2)
418.34
"""
bytes_real = bytes(string_real, 'raw_unicode_escape')
bytes_real = bytes(string_real, 'latin-1')
return bytes_to_real(bytes_real, precision, little_endian)


Expand Down Expand Up @@ -505,7 +505,7 @@ def int_to_string(val, n_bytes=4, little_endian=True):
val,
n_bytes,
little_endian
).decode('raw_unicode_escape')
).decode('latin-1')


def uint_to_bytes(val, n_bytes=4, little_endian=True):
Expand Down Expand Up @@ -558,7 +558,7 @@ def uint_to_string(val, n_bytes=4, little_endian=True):
val,
n_bytes,
little_endian
).decode('raw_unicode_escape')
).decode('latin-1')


def sign(number):
Expand Down

0 comments on commit 9aaa625

Please sign in to comment.