Skip to content

Commit 2f70f9c

Browse files
albu-dikujonasbardino
authored andcommitted
Rewrite the only FancyURLopener to sidestep its removal from the stdlib.
1 parent f076b55 commit 2f70f9c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

mig/server/importusers.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import getopt
3434
import os
3535
import re
36+
import ssl
3637
import sys
3738
import time
3839

@@ -48,7 +49,7 @@
4849
from mig.shared.pwcrypto import generate_random_password, unscramble_password, \
4950
scramble_password
5051
from mig.shared.safeinput import valid_password_chars
51-
from mig.shared.url import FancyURLopener
52+
from mig.shared.url import urlopen
5253
from mig.shared.useradm import init_user_adm, default_search, create_user, \
5354
search_users
5455
from mig.shared.vgridaccess import refresh_user_map
@@ -87,12 +88,13 @@ def dump_contents(url, key_path=None, cert_path=None):
8788

8889
# allow file dump at least until we get certificate based access
8990

90-
browser = FancyURLopener(key_file=key_path,
91-
cert_file=cert_path)
92-
pipe = browser.open(url)
93-
# NOTE: FancyURLopener returns bytes and we want native string for search
94-
data = force_native_str(pipe.read())
95-
browser.close()
91+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
92+
context.load_cert_chain(cert_path, key_path)
93+
94+
# NOTE: reading returns bytes and we want native string for search
95+
response = urlopen(url, context=context)
96+
data = force_native_str(response.read())
97+
response.close()
9698

9799
return data
98100

mig/shared/url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
if sys.version_info[0] >= 3:
5353
from urllib.parse import quote, unquote, urlencode, parse_qs, parse_qsl, \
5454
urlsplit, urlparse, urljoin
55-
from urllib.request import urlopen, FancyURLopener
55+
from urllib.request import urlopen
5656
else:
57-
from urllib import quote, unquote, urlencode, urlopen, FancyURLopener
57+
from urllib import quote, unquote, urlencode, urlopen
5858
from urlparse import parse_qs, parse_qsl, urlsplit, urlparse, urljoin
5959

6060
try:

0 commit comments

Comments
 (0)