<s> import requests <EOL> from requests . auth import HTTPDigestAuth <EOL> import json <EOL> from cloudapp . exceptions import CloudAppHttpError <EOL> class CloudAppAPI : <EOL> def __init__ ( self , username , password ) : <EOL> self . username = username <EOL> self . password = password <EOL> def upload ( self , path ) : <EOL> data = self . __get ( '<STR_LIT>' ) <EOL> url = data [ '<STR_LIT:url>' ] <EOL> params = data [ '<STR_LIT>' ] <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> response = requests . post ( url , files = { '<STR_LIT:file>' : open ( path , '<STR_LIT:rb>' ) } , data = params , allow_redirects = False ) <EOL> uri = response . headers [ '<STR_LIT:location>' ] <EOL> data = self . __get ( uri ) <EOL> return data [ '<STR_LIT>' ] <EOL> def __get ( self , uri ) : <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> r = requests . get ( uri , auth = HTTPDigestAuth ( self . username , self . password ) , <EOL> headers = headers ) <EOL> if r . status_code != <NUM_LIT:200> : <EOL> raise CloudAppHttpError ( response = r ) <EOL> return json . loads ( r . text ) </s>
