Skip to content

Commit

Permalink
fixes web2py#1449
Browse files Browse the repository at this point in the history
codename "he who late imports by default makes everybody's life a misery
for no speedup at all"
  • Loading branch information
niphlod committed Sep 19, 2016
1 parent 44362aa commit 25e8f4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions gluon/contrib/login_methods/cas_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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="/"):
Expand All @@ -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,
Expand All @@ -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':
Expand All @@ -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):
Expand All @@ -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))
2 changes: 1 addition & 1 deletion gluon/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25e8f4a

Please sign in to comment.