<s> try : <EOL> import simplejson as json <EOL> except : <EOL> import json <EOL> import base64 <EOL> import requests <EOL> from githubcollective . config import BASE_URL <EOL> class Github ( object ) : <EOL> """<STR_LIT:U+0020>""" <EOL> _cache = { } <EOL> _request_count = <NUM_LIT:0> <EOL> _request_limit = <NUM_LIT> <EOL> _request_remaining = <NUM_LIT> <EOL> def __init__ ( self , organization , username , password , verbose , pretend ) : <EOL> self . org = organization <EOL> self . verbose = verbose <EOL> self . pretend = pretend <EOL> self . headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' % base64 . encodestring ( <EOL> '<STR_LIT>' % ( username , password ) ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> } <EOL> def _request ( self , method , url , data = None ) : <EOL> kw = { '<STR_LIT:url>' : BASE_URL + url + '<STR_LIT>' , <EOL> '<STR_LIT>' : self . headers } <EOL> if data : <EOL> kw [ '<STR_LIT:data>' ] = data <EOL> response = method ( ** kw ) <EOL> self . _request_count += <NUM_LIT:1> <EOL> self . _request_limit = response . headers [ '<STR_LIT>' ] <EOL> self . _request_remaining = response . headers [ '<STR_LIT>' ] <EOL> if self . verbose : <EOL> print '<STR_LIT>' % ( <EOL> self . _request_count , <EOL> self . _request_remaining , <EOL> self . _request_limit , <EOL> method . __name__ . upper ( ) , <EOL> kw [ '<STR_LIT:url>' ] , <EOL> ) <EOL> response . raise_for_status ( ) <EOL> return response <EOL> def _get_request ( self , url ) : <EOL> return json . loads ( self . _request ( requests . get , url ) . text ) <EOL> def _delete_request ( self , url ) : <EOL> if self . pretend : <EOL> return <EOL> return self . _request ( requests . delete , url ) <EOL> def _post_request ( self , url , data ) : <EOL> if self . pretend : <EOL> return <EOL> return self . _request ( requests . post , url , data ) <EOL> def _put_request ( self , url ) : <EOL> if self . pretend : <EOL> return <EOL> return self . _request ( requests . put , url ) <EOL> def _patch_request ( self , url , data ) : <EOL> if self . pretend : <EOL> return <EOL> return self . _request ( requests . patch , url , data ) <EOL> def _gh_org_teams ( self ) : <EOL> return self . _get_request ( '<STR_LIT>' % self . org ) <EOL> def _gh_team ( self , team_id ) : <EOL> return self . _get_request ( '<STR_LIT>' % team_id ) <EOL> def _gh_team_members ( self , team_id ) : <EOL> return self . _get_request ( '<STR_LIT>' % team_id ) <EOL> def _gh_team_repos ( self , team_id ) : <EOL> return self . _get_request ( '<STR_LIT>' % team_id ) <EOL> def _gh_org_repos ( self ) : <EOL> return self . _get_request ( '<STR_LIT>' % self . org ) <EOL> def _gh_org_fork_repo ( self , fork_url ) : <EOL> return self . _post_request ( '<STR_LIT>' % fork_url , <EOL> { '<STR_LIT>' : self . org } ) <EOL> def _gh_org_create_repo ( self , name ) : <EOL> return self . _post_request ( '<STR_LIT>' % self . org , json . dumps ( { <EOL> '<STR_LIT:name>' : name , <EOL> } ) ) <EOL> def _gh_org_create_team ( self , name , permission = '<STR_LIT>' ) : <EOL> assert permission in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return self . _post_request ( '<STR_LIT>' % self . org , json . dumps ( { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : permission , <EOL> } ) ) <EOL> def _gh_org_edit_team ( self , id , name , permission = None ) : <EOL> data = { '<STR_LIT:name>' : name } <EOL> if permission is not None : <EOL> data [ '<STR_LIT>' ] = permission <EOL> assert permission in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return self . _patch_request ( '<STR_LIT>' % id , json . dumps ( data ) ) <EOL> def _gh_org_delete_team ( self , id ) : <EOL> return self . _delete_request ( '<STR_LIT>' % id ) <EOL> def _gh_org_add_team_member ( self , id , member ) : <EOL> return self . _put_request ( '<STR_LIT>' % ( id , member ) ) <EOL> def _gh_org_remove_team_member ( self , id , member ) : <EOL> return self . _delete_request ( '<STR_LIT>' % ( id , member ) ) <EOL> def _gh_org_add_team_repo ( self , id , repo ) : <EOL> return self . _put_request ( '<STR_LIT>' % <EOL> ( id , self . org , repo ) ) <EOL> def _gh_org_remove_team_repo ( self , id , repo ) : <EOL> return self . _delete_request ( '<STR_LIT>' % <EOL> ( id , self . org , repo ) ) </s>
