Added charset decoding of data read from an urlopen() object in a few places, and removed some use-once functions that were now dead code.

- Legacy-Id: 17355
This commit is contained in:
Henrik Levkowetz 2020-02-27 13:39:45 +00:00
parent 4b35ee43d2
commit ebdad3a5a5
2 changed files with 5 additions and 12 deletions

View file

@ -23,6 +23,7 @@ from ietf.doc.models import Document, DocEvent, State, StateDocEvent, StateType
from ietf.doc.utils import add_state_change_event
from ietf.person.models import Person
from ietf.utils.mail import parseaddr
from ietf.utils.text import decode
from ietf.utils.timezone import local_timezone_to_utc, email_time_to_local_timezone, utc_to_local_timezone
@ -31,7 +32,7 @@ from ietf.utils.timezone import local_timezone_to_utc, email_time_to_local_timez
def fetch_protocol_page(url):
f = urlopen(settings.IANA_SYNC_PROTOCOLS_URL)
text = force_str(f.read())
text = decode(f.read())
f.close()
return text
@ -80,7 +81,7 @@ def fetch_changes_json(url, start, end):
password = settings.IANA_SYNC_PASSWORD
request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""))
f = urlopen(request)
text = f.read()
text = decode(f.read())
f.close()
return text

View file

@ -7,7 +7,6 @@ from __future__ import absolute_import, print_function, unicode_literals
import base64
import datetime
import re
import socket
import six
from six.moves.urllib.request import Request, urlopen
@ -28,6 +27,7 @@ from ietf.name.models import StdLevelName, StreamName
from ietf.person.models import Person
from ietf.utils.log import log
from ietf.utils.mail import send_mail_text
from ietf.utils.text import decode
#QUEUE_URL = "https://www.rfc-editor.org/queue2.xml"
#INDEX_URL = "https://www.rfc-editor.org/rfc/rfc-index.xml"
@ -45,10 +45,6 @@ def get_child_text(parent_node, tag_name):
return '\n\n'.join(text)
def fetch_queue_xml(url):
socket.setdefaulttimeout(30)
return urlopen(url)
def parse_queue(response):
"""Parse RFC Editor queue XML into a bunch of tuples + warnings."""
@ -234,10 +230,6 @@ def update_drafts_from_queue(drafts):
return changed, warnings
def fetch_index_xml(url):
socket.setdefaulttimeout(30)
return urlopen(url)
def parse_index(response):
"""Parse RFC Editor index XML into a bunch of tuples."""
@ -550,7 +542,7 @@ def post_approved_draft(url, name):
text = error = ""
try:
f = urlopen(request, data=smart_bytes(urlencode({ 'draft': name })), timeout=20)
text = f.read()
text = decode(f.read())
status_code = f.getcode()
f.close()
log("RFC-Editor notification result for draft '%s': %s:'%s'" % (name, status_code, text))