From: Daniel Martí Date: Mon, 4 Jan 2016 17:02:36 +0000 (+0100) Subject: Port urllib and HTMLParser imports to python3 X-Git-Tag: 0.7.0~86^2~26 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d39bf37ce88f4f3c9bed1b45c18b969734ee7b82;p=fdroidserver.git Port urllib and HTMLParser imports to python3 --- diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 8ca14edc..46200199 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -20,12 +20,13 @@ import sys import os import re -import urllib2 +import urllib.request +import urllib.error import time import subprocess from argparse import ArgumentParser import traceback -import HTMLParser +from html.parser import HTMLParser from distutils.version import LooseVersion import logging import copy @@ -51,8 +52,8 @@ def check_http(app): vercode = "99999999" if len(urlcode) > 0: logging.debug("...requesting {0}".format(urlcode)) - req = urllib2.Request(urlcode, None) - resp = urllib2.urlopen(req, None, 20) + req = urllib.request.Request(urlcode, None) + resp = urllib.request.urlopen(req, None, 20) page = resp.read() m = re.search(codeex, page) @@ -64,8 +65,8 @@ def check_http(app): if len(urlver) > 0: if urlver != '.': logging.debug("...requesting {0}".format(urlver)) - req = urllib2.Request(urlver, None) - resp = urllib2.urlopen(req, None, 20) + req = urllib.request.Request(urlver, None) + resp = urllib.request.urlopen(req, None, 20) page = resp.read() m = re.search(verex, page) @@ -275,11 +276,11 @@ def check_gplay(app): time.sleep(15) url = 'https://play.google.com/store/apps/details?id=' + app.id headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0'} - req = urllib2.Request(url, None, headers) + req = urllib.request.Request(url, None, headers) try: - resp = urllib2.urlopen(req, None, 20) + resp = urllib.request.urlopen(req, None, 20) page = resp.read() - except urllib2.HTTPError as e: + except urllib.error.HTTPError as e: return (None, str(e.code)) except Exception as e: return (None, 'Failed:' + str(e)) @@ -288,7 +289,7 @@ def check_gplay(app): m = re.search('itemprop="softwareVersion">[ ]*([^<]+)[ ]*', page) if m: - html_parser = HTMLParser.HTMLParser() + html_parser = HTMLParser() version = html_parser.unescape(m.group(1)) if version == 'Varies with device': diff --git a/fdroidserver/update.py b/fdroidserver/update.py index e47f908a..a9fe6738 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -26,7 +26,7 @@ import socket import zipfile import hashlib import pickle -import urlparse +import urllib.parse from datetime import datetime, timedelta from xml.dom.minidom import Document from argparse import ArgumentParser @@ -773,7 +773,7 @@ def make_index(apps, sortedids, apks, repodir, archive, categories): mirrorcheckfailed = False for mirror in config.get('mirrors', []): - base = os.path.basename(urlparse.urlparse(mirror).path.rstrip('/')) + base = os.path.basename(urllib.parse.urlparse(mirror).path.rstrip('/')) if config.get('nonstandardwebroot') is not True and base != 'fdroid': logging.error("mirror '" + mirror + "' does not end with 'fdroid'!") mirrorcheckfailed = True @@ -787,9 +787,9 @@ def make_index(apps, sortedids, apks, repodir, archive, categories): repoel.setAttribute("icon", os.path.basename(config['archive_icon'])) repoel.setAttribute("url", config['archive_url']) addElement('description', config['archive_description'], doc, repoel) - urlbasepath = os.path.basename(urlparse.urlparse(config['archive_url']).path) + urlbasepath = os.path.basename(urllib.parse.urlparse(config['archive_url']).path) for mirror in config.get('mirrors', []): - addElement('mirror', urlparse.urljoin(mirror, urlbasepath), doc, repoel) + addElement('mirror', urllib.parse.urljoin(mirror, urlbasepath), doc, repoel) else: repoel.setAttribute("name", config['repo_name']) @@ -798,9 +798,9 @@ def make_index(apps, sortedids, apks, repodir, archive, categories): repoel.setAttribute("icon", os.path.basename(config['repo_icon'])) repoel.setAttribute("url", config['repo_url']) addElement('description', config['repo_description'], doc, repoel) - urlbasepath = os.path.basename(urlparse.urlparse(config['repo_url']).path) + urlbasepath = os.path.basename(urllib.parse.urlparse(config['repo_url']).path) for mirror in config.get('mirrors', []): - addElement('mirror', urlparse.urljoin(mirror, urlbasepath), doc, repoel) + addElement('mirror', urllib.parse.urljoin(mirror, urlbasepath), doc, repoel) repoel.setAttribute("version", "15") repoel.setAttribute("timestamp", str(int(time.time())))