1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 00:40:11 +01:00

Port urllib and HTMLParser imports to python3

This commit is contained in:
Daniel Martí 2016-01-04 18:02:36 +01:00
parent fc21dbc667
commit d39bf37ce8
2 changed files with 17 additions and 16 deletions

View File

@ -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">[ ]*([^<]+)[ ]*</div>', page)
if m:
html_parser = HTMLParser.HTMLParser()
html_parser = HTMLParser()
version = html_parser.unescape(m.group(1))
if version == 'Varies with device':

View File

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