Skip to content

Commit

Permalink
Fix bug parsing unicode in pyserial extract.
Browse files Browse the repository at this point in the history
Also added unicode file parsing for ServerCompilersettings configparser.
  • Loading branch information
carlosperate committed Jun 16, 2015
1 parent 6e9f9e8 commit 452fafd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ArdublocklyServer/PySerialListPorts/list_ports_windows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals, absolute_import
import ctypes
import sys
import re

def ValidHandle(value, func, arguments):
Expand Down Expand Up @@ -43,7 +44,11 @@ def string(buffer):
for c in buffer:
if c == 0: break
s.append(chr(c & 0xff)) # "& 0xff": hack to convert signed to unsigned
return ''.join(s)

if sys.version_info[0] == 3:
return ''.join(s)
else:
return bytearray(s).decode('utf8')


class GUID(ctypes.Structure):
Expand Down
20 changes: 16 additions & 4 deletions ArdublocklyServer/ServerCompilerSettings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# -*- coding: utf-8 -*-
#
# Save and retrieve the compiler settings into a text file.
#
# Copyright (c) 2015 carlosperate https://github.com/carlosperate/
# Licensed under the Apache License, Version 2.0 (the "License"):
# http://www.apache.org/licenses/LICENSE-2.0
#
from __future__ import unicode_literals, absolute_import
import sys
import os
import re
import codecs
import sys
try:
# 2.x name
import ConfigParser
Expand Down Expand Up @@ -486,14 +495,16 @@ def save_settings(self):

# Set the path and create/overwrite the file
try:
settings_file = open(self.get_settings_file_path(), 'w')
settings_file = codecs.open(
self.get_settings_file_path(), 'wb+', 'utf8')
settings_parser.write(settings_file)
settings_file.close()
print('Settings file saved to:')
sys.stdout.flush()
except Exception as e:
print(e)
print('\nUnable to write the settings file to:')
finally:
settings_file.close()
print('\t' + self.get_settings_file_path())

def read_settings(self):
Expand Down Expand Up @@ -536,7 +547,8 @@ def read_settings_file(self):
settings_dict = {}
settings_parser = ConfigParser.ConfigParser()
try:
settings_parser.read(self.get_settings_file_path())
settings_parser.readfp(
codecs.open(self.get_settings_file_path(), 'r', 'utf8'))
settings_dict['arduino_exec_path'] =\
settings_parser.get('Arduino_IDE', 'arduino_exec_path')
settings_dict['arduino_board'] =\
Expand Down

0 comments on commit 452fafd

Please sign in to comment.