<s> import facebook <EOL> from raggregate . models . user import User <EOL> import sqlalchemy <EOL> from raggregate . queries import users <EOL> from raggregate . login_adapters import LoginAdapterExc <EOL> import sqlahelper <EOL> dbsession = sqlahelper . get_session ( ) <EOL> def extract_from_cookie ( request ) : <EOL> r = request <EOL> rrs = request . registry . settings <EOL> fb_cookie = facebook . get_user_from_cookie ( request . cookies , rrs [ '<STR_LIT>' ] , rrs [ '<STR_LIT>' ] ) <EOL> if fb_cookie is None : <EOL> raise LoginAdapterExc ( "<STR_LIT>" ) <EOL> graph = facebook . GraphAPI ( fb_cookie [ '<STR_LIT>' ] ) <EOL> try : <EOL> u_fbinfo = graph . get_object ( "<STR_LIT>" ) <EOL> except facebook . GraphAPIError : <EOL> raise LoginAdapterExc ( "<STR_LIT>" ) <EOL> r . session [ '<STR_LIT>' ] = graph <EOL> r . session [ '<STR_LIT>' ] = u_fbinfo <EOL> return { '<STR_LIT:info>' : u_fbinfo , '<STR_LIT>' : "<STR_LIT>" . format ( id = u_fbinfo [ '<STR_LIT:id>' ] ) , '<STR_LIT>' : r } <EOL> def create_local_user ( fb_info , local_username , request = None ) : <EOL> u = users . create_user ( origination = '<STR_LIT>' , remote_object = fb_info , username = local_username ) <EOL> if request : <EOL> profile_picture = request . session [ '<STR_LIT>' ] . get_connections ( fb_info [ '<STR_LIT:id>' ] , "<STR_LIT>" ) <EOL> up = users . add_user_picture ( "<STR_LIT>" . format ( fb_info [ '<STR_LIT:id>' ] ) , fb_info [ '<STR_LIT:id>' ] , request . registry . settings [ '<STR_LIT>' ] , profile_picture ) <EOL> u . picture = up <EOL> dbsession . add ( u ) <EOL> return u </s>
