From 813764a1007ca038235ee71c3fd07cf81b586932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 27 Apr 2016 09:43:08 +0200 Subject: [PATCH] Fixed UDS Client to allow host names with unicode characters --- client/src/UDSClient.py | 10 +++++++--- client/src/uds/__init__.py | 2 +- client/src/uds/rest.py | 2 +- client/src/uds/tools.py | 23 +++++++++++++++++++---- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/client/src/UDSClient.py b/client/src/UDSClient.py index b3ed5592d..b6c67ab2b 100755 --- a/client/src/UDSClient.py +++ b/client/src/UDSClient.py @@ -137,8 +137,12 @@ class UDSClient(QtGui.QMainWindow): @QtCore.pyqtSlot() def getTransportData(self): - self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) - self.req.get() + try: + self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) + self.req.get() + except Exception as e: + logger.exception('Got exception: {}'.format(e)) + raise e @QtCore.pyqtSlot(dict) @@ -232,7 +236,7 @@ if __name__ == "__main__": except Exception: logger.debug('Detected execution without valid URI, exiting') - QtGui.QMessageBox.critical(None, 'Notice', 'This program is designed to be used by UDS', QtGui.QMessageBox.Ok) + QtGui.QMessageBox.critical(None, 'Notice', 'UDS Client Version {}'.format(VERSION), QtGui.QMessageBox.Ok) sys.exit(1) # Setup REST api endpoint diff --git a/client/src/uds/__init__.py b/client/src/uds/__init__.py index 5e6d62279..74993a60d 100644 --- a/client/src/uds/__init__.py +++ b/client/src/uds/__init__.py @@ -34,7 +34,7 @@ from __future__ import unicode_literals # On centos, old six release does not includes byte2int, nor six.PY2 import six -VERSION = '1.9.0' +VERSION = '1.9.1' __title__ = 'udclient' __version__ = VERSION diff --git a/client/src/uds/rest.py b/client/src/uds/rest.py index 353299ac0..b110068a5 100644 --- a/client/src/uds/rest.py +++ b/client/src/uds/rest.py @@ -56,7 +56,7 @@ class RestRequest(QObject): # private self._manager = QNetworkAccessManager() if params is not None: - url += '?' + '&'.join('{}={}'.format(k, urllib.quote(six.text_type(v))) for k, v in params.iteritems()) + url += '?' + '&'.join('{}={}'.format(k, urllib.quote(six.text_type(v).encode('utf8'))) for k, v in params.iteritems()) self.url = QUrl(RestRequest.restApiUrl + url) diff --git a/client/src/uds/tools.py b/client/src/uds/tools.py index 82a1908d6..f10e56e1d 100644 --- a/client/src/uds/tools.py +++ b/client/src/uds/tools.py @@ -41,27 +41,36 @@ import stat import six import sys +from log import logger + _unlinkFiles = [] _tasksToWait = [] _execBeforeExit = [] +sys_fs_enc = sys.getfilesystemencoding() or 'mbcs' + def saveTempFile(content, filename=None): if filename is None: - filename = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(16)) + filename = b''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(16)) filename = filename + '.uds' + if 'win32' in sys.platform: - filename = filename.encode('utf-8') + logger.info('Fixing for win32') + filename = filename.encode(sys_fs_enc) + filename = os.path.join(tempfile.gettempdir(), filename) + with open(filename, 'w') as f: f.write(content) + logger.info('Returning filename') return filename def findApp(appName, extraPath=None): if 'win32' in sys.platform and isinstance(appName, six.text_type): - appName = six.binary_type(appName) + appName = appName.encode(sys_fs_enc) searchPath = os.environ['PATH'].split(os.pathsep) if extraPath is not None: searchPath += list(extraPath) @@ -78,7 +87,13 @@ def getHostName(): Returns current host name In fact, it's a wrapper for socket.gethostname() ''' - return six.text_type(socket.gethostname()) + hostname = socket.gethostname() + if 'win32' in sys.platform: + hostname = hostname.decode(sys_fs_enc) + + hostname = six.text_type(hostname) + logger.info('Hostname: {}'.format(hostname)) + return hostname # Queing operations (to be executed before exit)