From a648f5686e54c98b45167b4946d60033c1a39831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Mon, 20 Jul 2020 13:15:00 +0200 Subject: [PATCH] Updated to client for python 3 --- client-py3/full/src/UDSClient.py | 13 ++----------- client-py3/full/src/uds/rest.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/client-py3/full/src/UDSClient.py b/client-py3/full/src/UDSClient.py index f77fafb8..043ff3cb 100755 --- a/client-py3/full/src/UDSClient.py +++ b/client-py3/full/src/UDSClient.py @@ -30,9 +30,6 @@ ''' @author: Adolfo Gómez, dkmaster at dkmon dot com ''' -# pylint: disable=c-extension-no-member -from __future__ import unicode_literals - import sys import webbrowser import json @@ -118,7 +115,6 @@ class UDSClient(QtWidgets.QMainWindow): def cancelPushed(self): self.close() - @QtCore.pyqtSlot() def updateAnim(self): self.anim += 2 if self.anim > 99: @@ -139,12 +135,10 @@ class UDSClient(QtWidgets.QMainWindow): self.ui.progressBar.invertedAppearance = False self.animTimer.stop() - @QtCore.pyqtSlot() def getVersion(self): self.req = RestRequest('', self, self.version) self.req.get() - @QtCore.pyqtSlot(dict) def version(self, data): try: self.processError(data) @@ -160,14 +154,12 @@ class UDSClient(QtWidgets.QMainWindow): self.getTransportData() except RetryException as e: - self.ui.info.setText(six.text_type(e)) + self.ui.info.setText(str(e)) QtCore.QTimer.singleShot(1000, self.getVersion) except Exception as e: self.showError(e) - - @QtCore.pyqtSlot() def getTransportData(self): try: self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) @@ -176,8 +168,6 @@ class UDSClient(QtWidgets.QMainWindow): logger.exception('Got exception on getTransportData') raise e - - @QtCore.pyqtSlot(dict) def transportDataReceived(self, data): logger.debug('Transport data received') try: @@ -274,6 +264,7 @@ def approveHost(hostName, parentWindow=None): if __name__ == "__main__": logger.debug('Initializing connector') + # Initialize app app = QtWidgets.QApplication(sys.argv) diff --git a/client-py3/full/src/uds/rest.py b/client-py3/full/src/uds/rest.py index 48a0ea51..5857a427 100644 --- a/client-py3/full/src/uds/rest.py +++ b/client-py3/full/src/uds/rest.py @@ -31,13 +31,10 @@ @author: Adolfo Gómez, dkmaster at dkmon dot com ''' # pylint: disable=c-extension-no-member,no-name-in-module -from __future__ import unicode_literals import json import urllib -import six - from PyQt5.QtCore import pyqtSignal, pyqtSlot from PyQt5.QtCore import QObject, QUrl, QSettings from PyQt5.QtCore import Qt @@ -60,8 +57,16 @@ class RestRequest(QObject): super(RestRequest, self).__init__() # private self._manager = QNetworkAccessManager() + try: + if os.path.exists('/etc/ssl/certs/ca-certificates.crt'): + pass + # os.environ['REQUESTS_CA_BUNDLE'] = '/etc/ssl/certs/ca-certificates.crt' + except Exception: + pass + + if params is not None: - url += '?' + '&'.join('{}={}'.format(k, urllib.parse.quote(six.text_type(v).encode('utf8'))) for k, v in params.items()) + url += '?' + '&'.join('{}={}'.format(k, urllib.parse.quote(str(v).encode('utf8'))) for k, v in params.items()) self.url = QUrl(RestRequest.restApiUrl + url) @@ -79,14 +84,12 @@ class RestRequest(QObject): try: if reply.error() != QNetworkReply.NoError: raise Exception(reply.errorString()) - #data = six.text_type(reply.readAll()) data = bytes(reply.readAll()) - #data = data.encode("utf-8") data = json.loads(data) except Exception as e: data = { 'result': None, - 'error': six.text_type(e) + 'error': str(e) } self.done.emit(data) @@ -97,7 +100,7 @@ class RestRequest(QObject): settings = QSettings() settings.beginGroup('ssl') cert = errors[0].certificate() - digest = six.text_type(cert.digest().toHex()) + digest = str(cert.digest().toHex()) approved = settings.value(digest, False)