From 25e8f4aef1f7e3bcd92ca17a7c21f0d97a1dfd7f Mon Sep 17 00:00:00 2001 From: niphlod Date: Mon, 19 Sep 2016 21:33:01 +0200 Subject: [PATCH] fixes #1449 codename "he who late imports by default makes everybody's life a misery for no speedup at all" --- gluon/contrib/login_methods/cas_auth.py | 21 +++++++++------------ gluon/globals.py | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/gluon/contrib/login_methods/cas_auth.py b/gluon/contrib/login_methods/cas_auth.py index 61d99868b..1a07c5f11 100644 --- a/gluon/contrib/login_methods/cas_auth.py +++ b/gluon/contrib/login_methods/cas_auth.py @@ -8,9 +8,11 @@ Tinkered by Szabolcs Gyuris < szimszo n @ o regpreshaz dot eu> """ +import xml.dom.minidom as dom +import xml.parsers.expat as expat from gluon import current, redirect, URL - +from gluon._compat import urlopen, to_native class CasAuth(object): """ @@ -59,7 +61,7 @@ def __init__(self, g=None, # g for backward compatibility ### # vars commented because of # https://code.google.com/p/web2py/issues/detail?id=1774 self.cas_my_url = URL(args=current.request.args, - #vars=current.request.vars, + #vars=current.request.vars, scheme=True) def login_url(self, next="/"): @@ -86,7 +88,6 @@ def _CAS_login(self): exposed as CAS.login(request) returns a token on success, None on failed authentication """ - import urllib self.ticket = current.request.vars.ticket if not current.request.vars.ticket: redirect("%s?service=%s" % (self.cas_login_url, @@ -95,7 +96,7 @@ def _CAS_login(self): url = "%s?service=%s&ticket=%s" % (self.cas_check_url, self.cas_my_url, self.ticket) - data = urllib.urlopen(url).read() + data = to_native(urlopen(url).read()) if data.startswith('yes') or data.startswith('no'): data = data.split('\n') if data[0] == 'yes': @@ -108,19 +109,16 @@ def _CAS_login(self): a = b = c = data[1] return dict(user=a, email=b, username=c) return None - import xml.dom.minidom as dom - import xml.parsers.expat as expat try: dxml = dom.parseString(data) - envelop = dxml.getElementsByTagName( - "cas:authenticationSuccess") + envelop = dxml.getElementsByTagName("cas:authenticationSuccess") if len(envelop) > 0: res = dict() for x in envelop[0].childNodes: if x.nodeName.startswith('cas:') and len(x.childNodes): - key = x.nodeName[4:].encode('utf8') - value = x.childNodes[0].nodeValue.encode('utf8') - if not key in res: + key = to_native(x.nodeName[4:]) + value = to_native(x.childNodes[0].nodeValue) + if key not in res: res[key] = value else: if not isinstance(res[key], list): @@ -136,5 +134,4 @@ def _CAS_logout(self): exposed CAS.logout() redirects to the CAS logout page """ - import urllib redirect("%s?service=%s" % (self.cas_logout_url, self.cas_my_url)) diff --git a/gluon/globals.py b/gluon/globals.py index 41ac708e8..ae4e0bc94 100644 --- a/gluon/globals.py +++ b/gluon/globals.py @@ -13,7 +13,7 @@ - Session """ -from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT +from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT, long from gluon.storage import Storage, List from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE from gluon.contenttype import contenttype