forked from shaba/openuds
Fixed UDS Client to allow host names with unicode characters
This commit is contained in:
parent
09f329db62
commit
813764a100
@ -137,8 +137,12 @@ class UDSClient(QtGui.QMainWindow):
|
|||||||
|
|
||||||
@QtCore.pyqtSlot()
|
@QtCore.pyqtSlot()
|
||||||
def getTransportData(self):
|
def getTransportData(self):
|
||||||
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
|
try:
|
||||||
self.req.get()
|
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)
|
@QtCore.pyqtSlot(dict)
|
||||||
@ -232,7 +236,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug('Detected execution without valid URI, exiting')
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
# Setup REST api endpoint
|
# Setup REST api endpoint
|
||||||
|
@ -34,7 +34,7 @@ from __future__ import unicode_literals
|
|||||||
# On centos, old six release does not includes byte2int, nor six.PY2
|
# On centos, old six release does not includes byte2int, nor six.PY2
|
||||||
import six
|
import six
|
||||||
|
|
||||||
VERSION = '1.9.0'
|
VERSION = '1.9.1'
|
||||||
|
|
||||||
__title__ = 'udclient'
|
__title__ = 'udclient'
|
||||||
__version__ = VERSION
|
__version__ = VERSION
|
||||||
|
@ -56,7 +56,7 @@ class RestRequest(QObject):
|
|||||||
# private
|
# private
|
||||||
self._manager = QNetworkAccessManager()
|
self._manager = QNetworkAccessManager()
|
||||||
if params is not None:
|
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)
|
self.url = QUrl(RestRequest.restApiUrl + url)
|
||||||
|
|
||||||
|
@ -41,27 +41,36 @@ import stat
|
|||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from log import logger
|
||||||
|
|
||||||
_unlinkFiles = []
|
_unlinkFiles = []
|
||||||
_tasksToWait = []
|
_tasksToWait = []
|
||||||
_execBeforeExit = []
|
_execBeforeExit = []
|
||||||
|
|
||||||
|
|
||||||
|
sys_fs_enc = sys.getfilesystemencoding() or 'mbcs'
|
||||||
|
|
||||||
def saveTempFile(content, filename=None):
|
def saveTempFile(content, filename=None):
|
||||||
if filename is 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'
|
filename = filename + '.uds'
|
||||||
|
|
||||||
if 'win32' in sys.platform:
|
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)
|
filename = os.path.join(tempfile.gettempdir(), filename)
|
||||||
|
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
logger.info('Returning filename')
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
def findApp(appName, extraPath=None):
|
def findApp(appName, extraPath=None):
|
||||||
if 'win32' in sys.platform and isinstance(appName, six.text_type):
|
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)
|
searchPath = os.environ['PATH'].split(os.pathsep)
|
||||||
if extraPath is not None:
|
if extraPath is not None:
|
||||||
searchPath += list(extraPath)
|
searchPath += list(extraPath)
|
||||||
@ -78,7 +87,13 @@ def getHostName():
|
|||||||
Returns current host name
|
Returns current host name
|
||||||
In fact, it's a wrapper for socket.gethostname()
|
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)
|
# Queing operations (to be executed before exit)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user