<s> import requests <EOL> import json <EOL> import webbrowser <EOL> class Session ( object ) : <EOL> name = None <EOL> visualizations = [ ] <EOL> def __init__ ( self , lgn = None , id = None , json = None ) : <EOL> self . lgn = lgn <EOL> self . host = lgn . host <EOL> self . auth = lgn . auth <EOL> self . id = id <EOL> if json : <EOL> self . id = json . get ( '<STR_LIT:id>' ) <EOL> self . name = json . get ( '<STR_LIT:name>' ) <EOL> def __str__ ( self ) : <EOL> if self . name : <EOL> return self . name <EOL> return str ( self . id ) <EOL> def __repr__ ( self ) : <EOL> s = "<STR_LIT>" <EOL> s += "<STR_LIT>" + str ( self . id ) <EOL> if self . name : <EOL> s += "<STR_LIT>" + str ( self . name ) <EOL> return s <EOL> def open ( self ) : <EOL> webbrowser . open ( self . host + '<STR_LIT>' + str ( self . id ) + '<STR_LIT>' ) <EOL> @ classmethod <EOL> def create ( cls , lgn , name = None ) : <EOL> url = lgn . host + '<STR_LIT>' <EOL> payload = { } <EOL> if name : <EOL> payload = { '<STR_LIT:name>' : name } <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> r = requests . post ( url , data = json . dumps ( payload ) , headers = headers , auth = lgn . auth ) <EOL> return cls ( lgn = lgn , json = r . json ( ) ) </s>
