From 477dc3753550f4d491c8b265e8bb811bb8c7c710 Mon Sep 17 00:00:00 2001 From: albertosottile Date: Mon, 28 May 2018 15:00:17 +0200 Subject: [PATCH] Use requests instead of urllib in getListOfPublicServers and checkForUpdate --- .travis.yml | 1 + buildPy2app.py | 2 +- buildPy2exe.py | 4 ++-- resources/third-party-notices.rtf | 16 +++++++++++++++- syncplay/client.py | 20 ++++++++++++-------- syncplay/utils.py | 14 +++++++++----- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index a2c67ae..6044335 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ before_install: install: - pip install twisted appnope +- pip install -U https://github.com/requests/requests/zipball/master #- git clone -b qtpy-pyside2 https://github.com/alby128/syncplay.git syncplay-qtpy-PySide2 #- cd syncplay-qtpy-PySide2 #- git checkout qtpy-pyside2 diff --git a/buildPy2app.py b/buildPy2app.py index f889c3d..74cb424 100644 --- a/buildPy2app.py +++ b/buildPy2app.py @@ -15,7 +15,7 @@ DATA_FILES = [ ] OPTIONS = { 'iconfile':'resources/icon.icns', - 'includes': {'PySide2.QtCore', 'PySide2.QtUiTools', 'PySide2.QtGui','PySide2.QtWidgets'}, + 'includes': {'PySide2.QtCore', 'PySide2.QtUiTools', 'PySide2.QtGui','PySide2.QtWidgets', 'certifi'}, 'excludes': {'PySide', 'PySide.QtCore', 'PySide.QtUiTools', 'PySide.QtGui'}, 'qt_plugins': ['platforms/libqcocoa.dylib', 'platforms/libqminimal.dylib','platforms/libqoffscreen.dylib'], 'plist': { diff --git a/buildPy2exe.py b/buildPy2exe.py index bff96a4..881667c 100755 --- a/buildPy2exe.py +++ b/buildPy2exe.py @@ -721,8 +721,8 @@ info = dict( options={'py2exe': { 'dist_dir': OUT_DIR, 'packages': 'PySide2.QtUiTools', - 'includes': 'twisted, sys, encodings, datetime, os, time, math, PySide2, liburl, ast, unicodedata', - 'excludes': 'venv, _ssl, doctest, pdb, unittest, win32clipboard, win32file, win32pdh, win32security, win32trace, win32ui, winxpgui, win32pipe, win32process, Tkinter', + 'includes': 'twisted, sys, encodings, datetime, os, time, math, PySide2, liburl, ast, unicodedata, _ssl', + 'excludes': 'venv, doctest, pdb, unittest, win32clipboard, win32file, win32pdh, win32security, win32trace, win32ui, winxpgui, win32pipe, win32process, Tkinter', 'dll_excludes': 'msvcr71.dll, MSVCP90.dll, POWRPROF.dll', 'optimize': 2, 'compressed': 1 diff --git a/resources/third-party-notices.rtf b/resources/third-party-notices.rtf index 5ef095d..e67066e 100644 --- a/resources/third-party-notices.rtf +++ b/resources/third-party-notices.rtf @@ -208,4 +208,18 @@ furnished to do so, subject to the following conditions:\ The above copyright notice and this permission notice shall be included in\ all copies or substantial portions of the Software.\ \ -} \ No newline at end of file + +\b Requests\ +\ + +\b0 Copyright 2018 Kenneth Reitz\ +\ +Licensed under the Apache License, Version 2.0 (the \'93License\'94); you may not use this file\ +except in compliance with the License. You may obtain a copy of the License at\ +\ +http://www.apache.org/licenses/LICENSE-2.0\ +\ +Unless required by applicable law or agreed to in writing, software distributed under the \ +License is distributed on an \'93AS IS\'94 BASIS, WITHOUT WARRANTIES OR CONDI-\ +TIONS OF ANY KIND, either express or implied. See the License for the specific lang-\ +uage governing permissions and limitations under the License.} \ No newline at end of file diff --git a/syncplay/client.py b/syncplay/client.py index e8cb8b5..665da98 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -11,7 +11,8 @@ from twisted.internet import reactor, task, defer, threads from functools import wraps from copy import deepcopy from syncplay.protocols import SyncClientProtocol -from syncplay import utils, constants +from syncplay import utils, constants, version +from syncplay.utils import isMacOS from syncplay.messages import getMissingStrings, getMessage from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE, \ PRIVACY_HIDDENFILENAME @@ -910,12 +911,15 @@ class SyncplayClient(object): def checkForUpdate(self, userInitiated): try: - import urllib, syncplay, sys, messages, json - params = urllib.urlencode({'version': syncplay.version, 'milestone': syncplay.milestone, 'release_number': syncplay.release_number, - 'language': messages.messages["CURRENT"], 'platform': sys.platform, 'userInitiated': userInitiated}) - - f = urllib.urlopen(constants.SYNCPLAY_UPDATE_URL.format(params)) - response = f.read() + import syncplay, sys, messages, urllib, json + params = urllib.urlencode({'version': syncplay.version, 'milestone': syncplay.milestone, 'release_number': syncplay.release_number, 'language': messages.messages["CURRENT"], 'platform': sys.platform, 'userInitiated': userInitiated}) + if isMacOS(): + import requests + response = requests.get(constants.SYNCPLAY_UPDATE_URL.format(params)) + response = response.text + else: + f = urllib.urlopen(constants.SYNCPLAY_UPDATE_URL.format(params)) + response = f.read() response = response.replace("

","").replace("

","").replace("
","").replace("“","\"").replace("”","\"") # Fix Wordpress response = json.loads(response) publicServers = None @@ -926,7 +930,7 @@ class SyncplayClient(object): return response["version-status"], response["version-message"] if response.has_key("version-message")\ else None, response["version-url"] if response.has_key("version-url") else None, publicServers except: - return "failed", getMessage("update-check-failed-notification").format(syncplay.version), constants.SYNCPLAY_DOWNLOAD_URL, None + return "failed", getMessage("update-check-failed-notification").format(version), constants.SYNCPLAY_DOWNLOAD_URL, None class _WarningManager(object): def __init__(self, player, userlist, ui, client): diff --git a/syncplay/utils.py b/syncplay/utils.py index 17d7fcc..5ad8b6c 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -374,11 +374,15 @@ def open_system_file_browser(path): def getListOfPublicServers(): try: - import urllib, syncplay, sys, messages, json - params = urllib.urlencode({'version': syncplay.version, 'milestone': syncplay.milestone, 'release_number': syncplay.release_number, - 'language': messages.messages["CURRENT"]}) - f = urllib.urlopen(constants.SYNCPLAY_PUBLIC_SERVER_LIST_URL.format(params)) - response = f.read() + import syncplay, sys, messages, urllib + params = urllib.urlencode({'version': syncplay.version, 'milestone': syncplay.milestone, 'release_number': syncplay.release_number, 'language': messages.messages["CURRENT"]}) + if isMacOS(): + import requests + response = requests.get(constants.SYNCPLAY_PUBLIC_SERVER_LIST_URL.format(params)) + response = response.text + else: + f = urllib.urlopen(constants.SYNCPLAY_PUBLIC_SERVER_LIST_URL.format(params)) + response = f.read() response = response.replace("

","").replace("

","").replace("
","").replace("“","'").replace("”","'").replace(":’","'").replace("’","'").replace("′","'").replace("\n","").replace("\r","") # Fix Wordpress response = ast.literal_eval(response)