<s> import urllib2 <EOL> import json <EOL> import base64 <EOL> import datetime <EOL> def parse_time ( timestr ) : <EOL> return datetime . datetime . strptime ( timestr , '<STR_LIT>' ) <EOL> def parse_short_time ( timestr ) : <EOL> return datetime . datetime . strptime ( timestr , '<STR_LIT>' ) <EOL> class ReapBase : <EOL> def __init_request ( self , path ) : <EOL> auth = base64 . b64encode ( self . username + '<STR_LIT::>' + self . password ) <EOL> uri = self . base_uri + path <EOL> request = urllib2 . Request ( uri ) <EOL> request . add_header ( '<STR_LIT:Content-Type>' , '<STR_LIT:application/json>' ) <EOL> request . add_header ( '<STR_LIT>' , '<STR_LIT:application/json>' ) <EOL> request . add_header ( '<STR_LIT>' , '<STR_LIT>' + auth ) <EOL> request . add_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return request <EOL> def get_request ( self , path ) : <EOL> request = self . __init_request ( path ) <EOL> try : <EOL> result = urllib2 . urlopen ( request ) <EOL> result_json = json . load ( result ) <EOL> return result_json <EOL> except : <EOL> return None <EOL> def post_request ( self , path , data , follow = False ) : <EOL> request = self . __init_request ( path ) <EOL> try : <EOL> request . add_data ( json . dumps ( data ) ) <EOL> result = urllib2 . urlopen ( request ) <EOL> if result . code == <NUM_LIT> and follow : <EOL> return self . get_request ( result . headers . getheader ( '<STR_LIT>' ) [ <NUM_LIT:1> : ] ) <EOL> result_json = json . load ( result ) <EOL> return result_json <EOL> except : <EOL> return None <EOL> def delete_request ( self , path ) : <EOL> request = self . __init_request ( path ) <EOL> request . get_method = lambda : '<STR_LIT>' <EOL> try : <EOL> result = urllib2 . urlopen ( request ) <EOL> if result : <EOL> return True <EOL> else : <EOL> return False <EOL> except : <EOL> return None </s>
