Skip to content
Browse files

Stuck in repos

Power went out woohoo
  • Loading branch information...
1 parent 55a36b7 commit dc1851ca55577da56828bdf3f6b4cc1d53e52a33 @sigmavirus24 committed
Showing with 54 additions and 71 deletions.
  1. +5 −4 github3/auths.py
  2. +2 −2 github3/gists.py
  3. +2 −1 github3/git.py
  4. +6 −5 github3/github.py
  5. +9 −7 github3/issues.py
  6. +13 −38 github3/models.py
  7. +4 −3 github3/notifications.py
  8. +3 −2 github3/orgs.py
  9. +3 −2 github3/pulls.py
  10. +6 −6 github3/repos.py
  11. +1 −1 requirements.txt
View
9 github3/auths.py
@@ -8,6 +8,7 @@
from github3.decorators import requires_basic_auth
from github3.models import GitHubCore
+from json import dumps
class Authorization(GitHubCore):
@@ -65,22 +66,22 @@ def update(self, scopes=[], add_scopes=[], rm_scopes=[], note='',
success = False
if scopes:
d = {'scopes': scopes}
- json = self._json(self._post(self._api, data=d), 200)
+ json = self._json(self._post(self._api, data=dumps(d)), 200)
self._update_(json)
success = True
if add_scopes:
d = {'add_scopes': add_scopes}
- json = self._json(self._post(self._api, data=d), 200)
+ json = self._json(self._post(self._api, data=dumps(d)), 200)
self._update_(json)
success = True
if rm_scopes:
d = {'remove_scopes': rm_scopes}
- json = self._json(self._post(self._api, data=d), 200)
+ json = self._json(self._post(self._api, data=dumps(d)), 200)
self._update_(json)
success = True
if note or note_url:
d = {'note': note, 'note_url': note_url}
- json = self._json(self._post(self._api, data=d), 200)
+ json = self._json(self._post(self._api, data=dumps(d)), 200)
self._update_(json)
success = True
return success
View
4 github3/gists.py
@@ -78,7 +78,7 @@ def create_comment(self, body):
:returns: :class:`GistComment <GistComment>`
"""
url = self._build_url('comments', base_url=self._api)
- json = self._json(self._post(url, {'body': body}), 201)
+ json = self._json(self._post(url, dumps({'body': body})), 201)
return GistComment(json, self) if json else None
@requires_auth
@@ -107,7 +107,7 @@ def edit(self, description='', files={}):
if files:
data['files'] = files
if data:
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
return True
View
3 github3/git.py
@@ -6,6 +6,7 @@
"""
+from json import dumps
from base64 import b64decode
from github3.models import GitHubObject, GitHubCore, BaseCommit
from github3.users import User
@@ -127,7 +128,7 @@ def update(self, sha, force=False):
:returns: bool
"""
data = {'sha': sha, 'force': force}
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
return True
View
11 github3/github.py
@@ -6,6 +6,7 @@
"""
+from json import dumps
from requests import session
from github3.auths import Authorization
from github3.events import Event
@@ -98,7 +99,7 @@ def authorize(self, login, password, scopes, note='', note_url='',
data = {'scopes': scopes, 'note': note, 'note_url': note_url,
'client_id': client_id, 'client_secret': client_secret}
if self._session.auth:
- json = self._json(self._post(url, data=data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
else:
ses = session()
ses.auth = (login, password)
@@ -120,7 +121,7 @@ def create_gist(self, description, files, public=True):
new_gist = {'description': description, 'public': public,
'files': files}
url = self._build_url('gists')
- json = self._json(self._post(url, new_gist), 201)
+ json = self._json(self._post(url, data=dumps(new_gist)), 201)
return Gist(json, self) if json else None
@requires_auth
@@ -173,7 +174,7 @@ def create_key(self, title, key):
if title and key:
url = self._build_url('user', 'keys')
- req = self._post(url, {'title': title, 'key': key})
+ req = self._post(url, data=dumps({'title': title, 'key': key}))
json = self._json(req, 201)
if json:
created = Key(json, self)
@@ -216,7 +217,7 @@ def create_repo(self,
'has_issues': has_issues, 'has_wiki': has_wiki,
'has_downloads': has_downloads, 'auto_init': auto_init,
'gitignore_template': gitignore_template}
- json = self._json(self._post(url, data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
return Repository(json, self) if json else None
@requires_auth
@@ -711,7 +712,7 @@ def markdown(self, text, mode='', context='', raw=False):
data = data
if data:
- req = self._post(url, data=data, headers=headers)
+ req = self._post(url, data=dumps(data), headers=headers)
if req.ok:
return req.content
return '' # (No coverage)
View
16 github3/issues.py
@@ -7,6 +7,7 @@
"""
from re import match
+from json import dumps
from github3.models import GitHubCore, BaseComment
from github3.users import User
from github3.decorators import requires_auth
@@ -53,8 +54,8 @@ def update(self, name, color):
if name and color:
if color[0] == '#':
color = color[1:]
- json = self._json(self._patch(self._api, data={'name': name,
- 'color': color}), 200)
+ json = self._json(self._patch(self._api, data=dumps({
+ 'name': name, 'color': color})), 200)
if json:
self._update_(json)
@@ -149,7 +150,7 @@ def update(self, title, state='', description='', due_on=''):
json = None
if title:
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
return True
@@ -228,7 +229,7 @@ def add_labels(self, *args):
:returns: bool
"""
url = self._build_url('labels', base_url=self._api)
- json = self._json(self._post(url, data=list(args)),
+ json = self._json(self._post(url, data=dumps(args)),
status_code=200)
return True if json else False
@@ -285,7 +286,8 @@ def create_comment(self, body):
json = None
if body:
url = self._build_url('comments', base_url=self._api)
- json = self._json(self._post(url, {'body': body}), 201)
+ json = self._json(self._post(url, data=dumps({'body': body})),
+ 201)
return IssueComment(json, self) if json else None
@requires_auth
@@ -313,7 +315,7 @@ def edit(self, title=None, body=None, assignee=None, state=None,
if v is None:
del data[k]
if data:
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
return True
@@ -392,7 +394,7 @@ def replace_labels(self, labels):
:returns: bool
"""
url = self._build_url('labels', base_url=self._api)
- return self._boolean(self._put(url, data=labels), 200, 404)
+ return self._boolean(self._put(url, data=dumps(labels)), 200, 404)
@requires_auth
def reopen(self):
View
51 github3/models.py
@@ -61,18 +61,10 @@ def __init__(self, json, ses=None):
'User-Agent': 'github3.py/{0}'.format(__version__),
}
- # Requests hook
- def json_hook(args):
- if args.get('data') and not args.get('files'):
- args['data'] = dumps(args['data'])
-
self._session.headers.update(headers)
- self._session.config['base_headers'].update(headers)
- self._session.hooks.update({'args': [json_hook]})
# set a sane default
self._github_url = 'https://api.github.com'
- self._remaining = 5000
def __repr__(self):
return '<github3-core at 0x{0:x}>'.format(id(self))
@@ -82,12 +74,12 @@ def _remove_none(self, data):
if v is None:
del(data[k])
- def _json(self, request, status_code):
+ def _json(self, response, status_code):
ret = None
- if request.status_code == status_code and request.content:
- ret = request.json
- if request.status_code >= 400:
- raise GitHubError(request)
+ if response.status_code == status_code and response.content:
+ ret = response.json()
+ if response.status_code >= 400:
+ raise GitHubError(response)
return ret
def _boolean(self, request, true_code, false_code):
@@ -98,36 +90,19 @@ def _boolean(self, request, true_code, false_code):
return False
def _delete(self, url, **kwargs):
- req = False
- if self._remaining > 0:
- req = self._session.delete(url, **kwargs)
- return req
+ return self._session.delete(url, **kwargs)
def _get(self, url, **kwargs):
- req = None
- if self._remaining > 0:
- req = self._session.get(url, **kwargs)
- return req
+ return self._session.get(url, **kwargs)
def _patch(self, url, **kwargs):
- req = None
- if self._remaining > 0:
- req = self._session.patch(url, **kwargs)
- return req
+ return self._session.patch(url, **kwargs)
def _post(self, url, data=None, **kwargs):
- req = None
- if self._remaining > 0:
- req = self._session.post(url, data, **kwargs)
- return req
+ return self._session.post(url, data, **kwargs)
def _put(self, url, **kwargs):
- req = False
- if self._remaining > 0:
- if 'data' not in kwargs:
- kwargs.update(headers={'Content-Length': '0'})
- req = self._session.put(url, **kwargs)
- return req
+ return self._session.put(url, **kwargs)
def _build_url(self, *args, **kwargs):
"""Builds a new API url from scratch."""
@@ -183,8 +158,8 @@ def ratelimit_remaining(self):
return self._remaining
def refresh(self):
- """Re-retrieve the information for this object and returns the refreshed
- instance."""
+ """Re-retrieve the information for this object and returns the
+ refreshed instance."""
json = self._json(self._get(self._api), 200)
self.__init__(json, self._session)
return self
@@ -240,7 +215,7 @@ def edit(self, body):
"""
if body:
json = self._json(self._patch(self._api,
- data={'body': body}), 200)
+ data=dumps({'body': body})), 200)
if json:
self._update_(json)
return True
View
7 github3/notifications.py
@@ -6,6 +6,7 @@
"""
+from json import dumps
from github3.models import GitHubCore
@@ -59,7 +60,7 @@ def mark(self):
:returns: bool
"""
mark = {'read': True}
- return self._boolean(self._patch(self._api, data=mark), 205,
+ return self._boolean(self._patch(self._api, data=dumps(mark)), 205,
404)
def set_subscription(self, subscribed, ignored):
@@ -73,7 +74,7 @@ def set_subscription(self, subscribed, ignored):
"""
url = self._build_url('subscription', base_url=self._api)
sub = {'subscribed': subscribed, 'ignored': ignored}
- json = self._json(self._put(url, data=sub), 200)
+ json = self._json(self._put(url, data=dumps(sub)), 200)
return Subscription(json, self) if json else None
def subscription(self):
@@ -122,5 +123,5 @@ def set(self, subscribed, ignored):
ignored from this thread.
"""
sub = {'subscribed': subscribed, 'ignored': ignored}
- json = self._json(self._put(self._api, data=sub), 200)
+ json = self._json(self._put(self._api, data=dumps(sub)), 200)
self.__init__(json, self._session)
View
5 github3/orgs.py
@@ -6,6 +6,7 @@
"""
+from json import dumps
from github3.events import Event
from github3.models import BaseAccount, GitHubCore
from github3.repos import Repository
@@ -71,7 +72,7 @@ def edit(self, name, permission=''):
"""
if name:
data = {'name': name, 'permission': permission}
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
return True
@@ -282,7 +283,7 @@ def edit(self,
del data[k]
if data:
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
View
5 github3/pulls.py
@@ -7,6 +7,7 @@
"""
from re import match
+from json import dumps
from github3.git import Commit
from github3.models import GitHubObject, GitHubCore, BaseComment
from github3.users import User
@@ -259,7 +260,7 @@ def merge(self, commit_message=''):
if commit_message:
data = {'commit_message': commit_message}
url = self._build_url('merge', base_url=self._api)
- resp = self._put(url, data)
+ resp = self._put(url, data=dumps(data))
self.merge_commit_sha = resp['merge_commit_sha']
return resp.json['merged']
@@ -293,7 +294,7 @@ def update(self, title=None, body=None, state=None):
del data[k]
if data:
- json = self._json(self._patch(self._api, data=data), 200)
+ json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_(json)
View
12 github3/repos.py
@@ -124,7 +124,7 @@ def _create_pull(self, data):
json = None
if data:
url = self._build_url('pulls', base_url=self._api)
- json = self._json(self._post(url, data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
return PullRequest(json, self._session) if json else None
@requires_auth
@@ -266,7 +266,7 @@ def create_blob(self, content, encoding):
if encoding in ('base64', 'utf-8') and content:
url = self._build_url('git', 'blobs', base_url=self._api)
data = {'content': content, 'encoding': encoding}
- json = self._json(self._post(url, data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
if json:
sha = json.get('sha')
return sha
@@ -292,7 +292,7 @@ def create_comment(self, body, sha, path='', position=1, line=1):
'path': path, 'position': position}
url = self._build_url('commits', sha, 'comments',
base_url=self._api)
- json = self._json(self._post(url, data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
return RepoComment(json, self) if json else None
@requires_auth
@@ -321,7 +321,7 @@ def create_commit(self, message, tree, parents, author={}, committer={}):
url = self._build_url('git', 'commits', base_url=self._api)
data = {'message': message, 'tree': tree, 'parents': parents,
'author': author, 'committer': committer}
- json = self._json(self._post(url, data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
return Commit(json, self) if json else None
@requires_auth
@@ -351,7 +351,7 @@ def create_download(self, name, path, description='',
data = {'name': name, 'size': info.st_size,
'description': description,
'content_type': content_type}
- json = self._json(self._post(url, data), 201)
+ json = self._json(self._post(url, data=dumps(data)), 201)
if not json:
return None
@@ -380,7 +380,7 @@ def create_fork(self, organization=None):
"""
url = self._build_url('forks', base_url=self._api)
if organization:
- resp = self._post(url, data={'organization': organization})
+ resp = self._post(url, data=dumps({'organization': organization}))
else:
resp = self._post(url)
json = self._json(resp, 202)
View
2 requirements.txt
@@ -1,4 +1,4 @@
-requests==0.14.1
+requests>=1.0.3
git+git://github.com/garybernhardt/expecter.git
coverage>=3.5.2
mock>=1.0.0

0 comments on commit dc1851c

Please sign in to comment.
Something went wrong with that request. Please try again.