#NEWLINE# def _CAS_login( self ) : #NEWLINE# #INDENT# '\n        exposed as CAS.login(request)\n        returns a token on success, None on failed authentication\n        ' #NEWLINE# import urllib #NEWLINE# self . ticket = current . request . vars . ticket #NEWLINE# if ( not current . request . vars . ticket ) : #NEWLINE# #INDENT# redirect ( ( '%s?service=%s' % ( self . cas_login_url , self . cas_my_url ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# url = ( '%s?service=%s&ticket=%s' % ( self . cas_check_url , self . cas_my_url , self . ticket ) ) #NEWLINE# data = urllib . urlopen ( url ) . read ( ) #NEWLINE# if ( data . startswith ( 'yes' ) or data . startswith ( 'no' ) ) : #NEWLINE# #INDENT# data = data . split ( '\n' ) #NEWLINE# if ( data [ 0 ] == 'yes' ) : #NEWLINE# #INDENT# if ( ':' in data [ 1 ] ) : #NEWLINE# #INDENT# items = data [ 1 ] . split ( ':' ) #NEWLINE# a = items [ 0 ] #NEWLINE# b = ( ( ( len ( items ) > 1 ) and items [ 1 ] ) or a ) #NEWLINE# c = ( ( ( len ( items ) > 2 ) and items [ 2 ] ) or b ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# a = b = c = data [ 1 ] #NEWLINE# #UNINDENT# return dict ( user = a , email = b , username = c ) #NEWLINE# #UNINDENT# return None #NEWLINE# #UNINDENT# import xml.dom.minidom as dom #NEWLINE# import xml.parsers.expat as expat #NEWLINE# try : #NEWLINE# #INDENT# dxml = dom . parseString ( data ) #NEWLINE# envelop = dxml . getElementsByTagName ( 'cas:authenticationSuccess' ) #NEWLINE# if ( len ( envelop ) > 0 ) : #NEWLINE# #INDENT# res = dict ( ) #NEWLINE# for x in envelop [ 0 ] . childNodes : #NEWLINE# #INDENT# if ( x . nodeName . startswith ( 'cas:' ) and len ( x . childNodes ) ) : #NEWLINE# #INDENT# key = x . nodeName [ 4 : ] . encode ( 'utf8' ) #NEWLINE# value = x . childNodes [ 0 ] . nodeValue . encode ( 'utf8' ) #NEWLINE# if ( not ( key in res ) ) : #NEWLINE# #INDENT# res [ key ] = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( res [ key ] , list ) ) : #NEWLINE# #INDENT# res [ key ] = [ res [ key ] ] #NEWLINE# #UNINDENT# res [ key ] . append ( value ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return res #NEWLINE# #UNINDENT# #UNINDENT# except expat . ExpatError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return None