#NEWLINE# def open_session( self , app , request ) : #NEWLINE# #INDENT# sid = request . cookies . get ( app . session_cookie_name ) #NEWLINE# if sid : #NEWLINE# #INDENT# stored_session = self . cls . objects ( sid = sid ) . first ( ) #NEWLINE# if stored_session : #NEWLINE# #INDENT# expiration = stored_session . expiration #NEWLINE# if ( not expiration . tzinfo ) : #NEWLINE# #INDENT# expiration = expiration . replace ( tzinfo = utc ) #NEWLINE# #UNINDENT# if ( expiration > datetime . datetime . utcnow ( ) . replace ( tzinfo = utc ) ) : #NEWLINE# #INDENT# return MongoEngineSession ( initial = stored_session . data , sid = stored_session . sid ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return MongoEngineSession ( sid = str ( uuid . uuid4 ( ) ) )