Skip to content

Commit ea94fb4

Browse files
committed
Deal with renamed modules in python3
six.moves handles some of the reorganized modules. With dircache, it was simply removed as it has been deprecated for a long time. os.listdir performs fine these days.
1 parent 45f88c1 commit ea94fb4

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/saml2/httpbase.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import calendar
2-
import cookielib
2+
from six.moves import http_cookiejar
33
import copy
44
import re
55
import urllib
6-
import urlparse
6+
from six.moves.urllib.parse import urlparse
77
import requests
88
import time
9-
from Cookie import SimpleCookie
9+
from six.moves.http_cookies import SimpleCookie
1010
from saml2.time_util import utc_now
1111
from saml2 import class_name, SAMLError
1212
from saml2.pack import http_form_post_message
@@ -98,7 +98,7 @@ def __init__(self, verify=True, ca_bundle=None, key_file=None,
9898
cert_file=None):
9999
self.request_args = {"allow_redirects": False}
100100
#self.cookies = {}
101-
self.cookiejar = cookielib.CookieJar()
101+
self.cookiejar = http_cookiejar.CookieJar()
102102

103103
self.request_args["verify"] = verify
104104
if verify:
@@ -118,7 +118,7 @@ def cookies(self, url):
118118
:param url:
119119
:return:
120120
"""
121-
part = urlparse.urlparse(url)
121+
part = urlparse(url)
122122

123123
#if part.port:
124124
# _domain = "%s:%s" % (part.hostname, part.port)
@@ -143,12 +143,12 @@ def cookies(self, url):
143143
return cookie_dict
144144

145145
def set_cookie(self, kaka, request):
146-
"""Returns a cookielib.Cookie based on a set-cookie header line"""
146+
"""Returns a http_cookiejar.Cookie based on a set-cookie header line"""
147147

148148
if not kaka:
149149
return
150150

151-
part = urlparse.urlparse(request.url)
151+
part = urlparse(request.url)
152152
_domain = part.hostname
153153
logger.debug("%s: '%s'" % (_domain, kaka))
154154

@@ -205,7 +205,7 @@ def set_cookie(self, kaka, request):
205205
except ValueError:
206206
pass
207207
else:
208-
new_cookie = cookielib.Cookie(**std_attr)
208+
new_cookie = http_cookiejar.Cookie(**std_attr)
209209
self.cookiejar.set_cookie(new_cookie)
210210

211211
def send(self, url, method="GET", **kwargs):

src/saml2/mdstore.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from __future__ import print_function
2-
from dircache import listdir
32
import logging
43
import os
54
import sys
@@ -765,7 +764,7 @@ def load(self, typ, *args, **kwargs):
765764
key = args[0]
766765
# if library read every file in the library
767766
if os.path.isdir(key):
768-
files = [f for f in listdir(key) if isfile(join(key, f))]
767+
files = [f for f in os.listdir(key) if isfile(join(key, f))]
769768
for fil in files:
770769
_fil = join(key, fil)
771770
_md = MetaDataFile(self.onts, self.attrc, _fil)
@@ -838,7 +837,7 @@ def imp(self, spec):
838837
for key in item['metadata']:
839838
# Separately handle MetaDataFile and directory
840839
if MDloader == MetaDataFile and os.path.isdir(key[0]):
841-
files = [f for f in listdir(key[0]) if isfile(join(key[0], f))]
840+
files = [f for f in os.listdir(key[0]) if isfile(join(key[0], f))]
842841
for fil in files:
843842
_fil = join(key[0], fil)
844843
_md = MetaDataFile(self.onts, self.attrc, _fil)

src/saml2/pack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- how to package the information
1111
- which protocol to use
1212
"""
13-
import urlparse
13+
from six.moves.urllib.parse import urlparse
1414
import saml2
1515
import base64
1616
import urllib
@@ -129,7 +129,7 @@ def http_redirect_message(message, location, relay_state="", typ="SAMLRequest",
129129
else:
130130
string = urllib.urlencode(args)
131131

132-
glue_char = "&" if urlparse.urlparse(location).query else "?"
132+
glue_char = "&" if urlparse(location).query else "?"
133133
login_url = glue_char.join([location, string])
134134
headers = [('Location', str(login_url))]
135135
body = []

src/saml2/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import calendar
2-
import urlparse
2+
from six.moves.urllib.parse import urlparse
33
import re
44
import time_util
55
import struct
@@ -46,7 +46,7 @@ def valid_id(oid):
4646
def valid_any_uri(item):
4747
"""very simplistic, ..."""
4848
try:
49-
part = urlparse.urlparse(item)
49+
part = urlparse(item)
5050
except Exception:
5151
raise NotValid("AnyURI")
5252

0 commit comments

Comments
 (0)