Use requests instead of urllib in getListOfPublicServers and checkForUpdate

This commit is contained in:
albertosottile 2018-05-28 15:00:17 +02:00 committed by Alberto Sottile
parent 5e6cc80efb
commit 477dc37535
6 changed files with 40 additions and 17 deletions

View File

@ -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

View File

@ -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': {

View File

@ -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

View File

@ -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.\
\
}
\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.}

View File

@ -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("<p>","").replace("</p>","").replace("<br />","").replace("&#8220;","\"").replace("&#8221;","\"") # 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):

View File

@ -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("<p>","").replace("</p>","").replace("<br />","").replace("&#8220;","'").replace("&#8221;","'").replace(":&#8217;","'").replace("&#8217;","'").replace("&#8242;","'").replace("\n","").replace("\r","") # Fix Wordpress
response = ast.literal_eval(response)