#NEWLINE# def http_auth_helper( request ) : #NEWLINE# #INDENT# if request [ 'headers' ] . has_key ( 'Authorization' ) : #NEWLINE# #INDENT# auth = request [ 'headers' ] [ 'Authorization' ] . split ( ) #NEWLINE# if ( len ( auth ) == 2 ) : #NEWLINE# #INDENT# if ( auth [ 0 ] . lower ( ) == 'basic' ) : #NEWLINE# #INDENT# ( uname , passwd ) = base64 . b64decode ( auth [ 1 ] ) . split ( ':' ) #NEWLINE# if ( ( not uname ) and ( not passwd ) and ( not settings . ALLOW_EMPTY_HTTP_AUTH ) ) : #NEWLINE# #INDENT# raise BadRequest ( 'Must supply auth credentials' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not uname ) and ( not passwd ) and settings . ALLOW_EMPTY_HTTP_AUTH ) : #NEWLINE# #INDENT# request [ 'auth' ] [ 'user' ] = None #NEWLINE# request [ 'auth' ] [ 'agent' ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( uname or passwd ) : #NEWLINE# #INDENT# user = authenticate ( username = uname , password = passwd ) #NEWLINE# if user : #NEWLINE# #INDENT# request [ 'auth' ] [ 'user' ] = user #NEWLINE# request [ 'auth' ] [ 'agent' ] = user . agent #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Unauthorized ( 'Authorization failed, please verify your username and password' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# request [ 'auth' ] [ 'define' ] = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Unauthorized ( 'HTTP Basic Authorization Header must start with Basic' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise Unauthorized ( 'The format of the HTTP Basic Authorization Header value is incorrect' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise Unauthorized ( 'Authorization header missing' )