8000 Merge branch 'empty' into develop · pythonthings/github3.py@bb36f3d · GitHub
[go: up one dir, main page]

Skip to content

Commit bb36f3d

Browse files
committed
Merge branch 'empty' into develop
2 parents 67f38a2 + 22f6bd1 commit bb36f3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1198
-720
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ Contributors
137137

138138
- Goodwillcoding (@goodwillcoding)
139139

140+
- Andreas Backx (@AndreasBackx)

docs/empty.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Empty
2+
=====
3+
4+
.. module:: github3
5+
.. module:: github3.empty
6+
7+
This part of the documentation covers the :class:`Empty <Empty>` object.
8+
9+
Empty Object
10+
------------
11+
12+
.. autoclass:: Empty
13+
:inherited-members:

docs/index.rst

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Modules
6868

6969
api
7070
auths
71+
empty
7172
events
7273
gists
7374
git
@@ -120,10 +121,10 @@ Dependencies
120121
Contributing
121122
------------
122123

123-
I'm maintaining two public copies of the project. The first can be found on
124-
GitHub_ and the second on BitBucket_. I would prefer pull requests to take
125-
place on GitHub, but feel free to do them via BitBucket. Please make sure to
126-
add yourself to the list of contributors in AUTHORS.rst, especially if you're
124+
I'm maintaining two public copies of the project. The first can be found on
125+
GitHub_ and the second on BitBucket_. I would prefer pull requests to take
126+
place on GitHub, but feel free to do them via BitBucket. Please make sure to
127+
add yourself to the list of contributors in AUTHORS.rst, especially if you're
127128
going to be working on the list below.
128129

129130
.. links
@@ -137,12 +138,12 @@ In order of importance:
137138

138139
Documentation
139140

140-
I know I'm not the best at writing documentation so if you want to clarify
141+
I know I'm not the best at writing documentation so if you want to clarify
141142
or correct something, please do so.
142143

143144
Examples
144145

145-
Have a clever example that takes advantage of github3.py? Feel free to
146+
Have a clever example that takes advantage of github3.py? Feel free to
146147
share it.
147148

148149
Running the Unittests
@@ -160,8 +161,8 @@ We test against PyPy and the following versions of Python:
160161
- 3.3
161162
- 3.4
162163

163-
If you simply run ``tox`` it will run tests against all of these versions of
164-
python and run ``flake8`` against the codebase as well. If you want to run
164+
If you simply run ``tox`` it will run tests against all of these versions of
165+
python and run ``flake8`` against the codebase as well. If you want to run
165166
against one specific version, you can do::
166167

167168
tox -e py34
@@ -170,8 +171,8 @@ And if you want to run tests against a specific file, you can do::
170171

171172
tox -e py34 -- tests/uni/test_github.py
172173

173-
To run the tests, ``tox`` uses ``py.test`` so you can pass any options or
174-
parameters to ``py.test`` after specifying ``--``. For example, you can get
174+
To run the tests, ``tox`` uses ``py.test`` so you can pass any options or
175+
parameters to ``py.test`` after specifying ``--``. For example, you can get
175176
more verbose output by doing::
176177

177178
tox -e py34 -- -vv
@@ -206,50 +207,50 @@ Testimonials
206207

207208
.. raw:: html
208209

209-
<blockquote class="twitter-tweet"><p>gotta hand it to @<a
210-
href="https://twitter.com/sigmavirus24">sigmavirus24</a> ... github3.py is
210+
<blockquote class="twitter-tweet"><p>gotta hand it to @<a
211+
href="https://twitter.com/sigmavirus24">sigmavirus24</a> ... github3.py is
211212
really well written. It will soon be powering the github stuff on
212213
@<a href="https://twitter.com/workforpie">workforpie</a>
213-
</p>&mdash; Brad Montgomery # (@bkmontgomery) <a
214+
</p>&mdash; Brad Montgomery # (@bkmontgomery) <a
214215
href="https://twitter.com/bkmontgomery/status/325644863561400320">April 20, 2013</a>
215216
</blockquote>
216217

217-
<blockquote class="twitter-tweet"><p>awesome github v3 api wrapper in
218-
python <a href="https://t.co/PhD0Aj5X"
219-
title="https://github.com/sigmavirus24/github3.py">github.com/sigmavirus24/g#</a></p>&mdash;
220-
Mahdi Yusuf (@myusuf3) <a
221-
href="https://twitter.com/myusuf3/status/258571050927915008">October 17,
218+
<blockquote class="twitter-tweet"><p>awesome github v3 api wrapper in
219+
python <a href="https://t.co/PhD0Aj5X"
220+
title="https://github.com/sigmavirus24/github3.py">github.com/sigmavirus24/g#</a></p>&mdash;
221+
Mahdi Yusuf (@myusuf3) <a
222+
href="https://twitter.com/myusuf3/status/258571050927915008">October 17,
222223
2012</a></blockquote>
223224

224225
<blockquote class="twitter-tweet">
225-
<p>@<a href="https://twitter.com/sigmavirus24">sigmavirus24</a> github3 is
226-
awesome! Made my life much easier tonight, which is a very good
227-
thing.</p>&mdash; Mike Grouchy (@mgrouchy) <a
228-
href="https://twitter.com/mgrouchy/status/316370772782350336">March 26,
226+
<p>@<a href="https://twitter.com/sigmavirus24">sigmavirus24</a> github3 is
227+
awesome! Made my life much easier tonight, which is a very good
228+
thing.</p>&mdash; Mike Grouchy (@mgrouchy) <a
229+
href="https://twitter.com/mgrouchy/status/316370772782350336">March 26,
229230
2013</a></blockquote>
230231

231232
<blockquote class="twitter-tweet" data-conversation="none">
232-
<p>@<a href="https://twitter.com/sigmavirus24">sigmavirus24</a> "There are
233-
so many Python client libraries for GitHub API, I tried all of them, and
234-
my conclusion is: github3.py is the best."</p>&mdash; Hong Minhee
235-
(@hongminhee) <a
236-
href="https://twitter.com/hongminhee/status/315295733899210752">March 23,
233+
<p>@<a href="https://twitter.com/sigmavirus24">sigmavirus24</a> "There are
234+
so many Python client libraries for GitHub API, I tried all of them, and
235+
my conclusion is: github3.py is the best."</p>&mdash; Hong Minhee
236+
(@hongminhee) <a
237+
href="https://twitter.com/hongminhee/status/315295733899210752">March 23,
237238
2013</a></blockquote>
238239

239240
<blockquote class="twitter-tweet">
240-
<p>@<a href="https://twitter.com/sigmavirus24">sigmavirus24</a> I cannot
241-
wait to use your github package for <a
242-
href="https://twitter.com/search/%23zci">#zci</a>. Do you have it packaged
243-
for debian by any chance?</p>&mdash; Zygmunt Krynicki (@zygoon) <a
244-
href="https://twitter.com/zygoon/status/316608301527887872">March 26,
241+
<p>@<a href="https://twitter.com/sigmavirus24">sigmavirus24</a> I cannot
242+
wait to use your github package for <a
243+
href="https://twitter.com/search/%23zci">#zci</a>. Do you have it packaged
244+
for debian by any chance?</p>&mdash; Zygmunt Krynicki (@zygoon) <a
245+
href="https://twitter.com/zygoon/status/316608301527887872">March 26,
245246
2013</a></blockquote>
246247

247248
<blockquote class="twitter-tweet">
248-
<p>Developing against github3.py's API is a joy, kudos to @<a
249-
href="https://twitter.com/sigmavirus24">sigmavirus24</a></p>&mdash;
250-
Alejandro Gomez (@dialelo) <a
251-
href="https://twitter.com/dialelo/status/316846075015229440">March 27,
249+
<p>Developing against github3.py's API is a joy, kudos to @<a
250+
href="https://twitter.com/sigmavirus24">sigmavirus24</a></p>&mdash;
251+
Alejandro Gomez (@dialelo) <a
252+
href="https://twitter.com/dialelo/status/316846075015229440">March 27,
252253
2013</a></blockquote>
253254

254-
<script async src="//platform.twitter.com/widgets.js"
255+
<script async src="//platform.twitter.com/widgets.js"
255256
charset="utf-8"></script>

github3/auths.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,34 @@ class Authorization(GitHubCore):
3131
"""
3232

3333
def _update_attributes(self, auth):
34-
self._api = auth.get('url')
34+
self._api = self._get_attribute(auth, 'url')
35+
3536
#: Details about the application (name, url)
36-
self.app = auth.get('app', {})
37+
self.app = self._get_attribute(auth, 'app', {})
38+
3739
#: Returns the Authorization token
38-
self.token = auth.get('token', '')
40+
self.token = self._get_attribute(auth, 'token')
41+
3942
#: App name
40-
self.name = self.app.get('name', '')
43+
self.name = self._get_attribute(self.app, 'name')
44+
4145
#: URL about the note
42-
self.note_url = auth.get('note_url') or ''
46+
self.note_url = self._get_attribute(auth, 'note_url')
47+
4348
#: Note about the authorization
44-
self.note = auth.get('note') or ''
49+
self.note = self._get_attribute(auth, 'note')
50+
4551
#: List of scopes this applies to
46-
self.scopes = auth.get('scopes', [])
52+
self.scopes = self._get_attribute(auth, 'scopes')
53+
4754
#: Unique id of the authorization
48-
self.id = auth.get('id', 0)
55+
self.id = self._get_attribute(auth, 'id')
56+
4957
#: datetime object representing when the authorization was created.
50-
self.created_at = self._strptime(auth.get('created_at'))
58+
self.created_at = self._strptime_attribute(auth, 'created_at')
59+
5160
#: datetime object representing when the authorization was updated.
52-
self.updated_at = self._strptime(auth.get('updated_at'))
61+
self.updated_at = self._strptime_attribute(auth, 'updated_at')
5362

5463
def _repr(self):
5564
return '<Authorization [{0}]>'.format(self.name)

github3/empty.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
github3.empty
4+
=============
5+
6+
This module contains everything relating to the Empty class.
7+
8+
"""
9+
10+
11+
class Empty(object):
12+
13+
"""Class to indicate something wasn't returned by the API.
14+
15+
The :class:`Empty <Empty>` class indicates that the attribute requested
16+
was not found in the json returned by the API. The Empty class is declared
17+
in every GitHubCore subclass using GitHubCore.Empty.
18+
19+
A model's field can be checked for Empty like so::
20+
21+
# type(user) == github3.users.User
22+
user.owner_private_repos is not user.Empty
23+
24+
And that is equivalent to::
25+
26+
from github3.empty import Empty
27+
user.owner_private_repos is not Empty
28+
29+
"""

github3/events.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,31 @@ def _update_attributes(self, event):
4040
from .users import User
4141
from .orgs import Organization
4242
#: :class:`User <github3.users.User>` object representing the actor.
43-
self.actor = User(event.get('actor')) if event.get('actor') else None
43+
self.actor = self._class_attribute(event, 'actor', User)
4444
#: datetime object representing when the event was created.
45-
self.created_at = self._strptime(event.get('created_at'))
45+
self.created_at = self._strptime_attribute(event, 'created_at')
46+
4647
#: Unique id of the event
47-
self.id = event.get('id')
48+
self.id = self._get_attribute(event, 'id')
49+
4850
#: List all possible types of Events
49-
self.org = None
50-
if event.get('org'):
51-
self.org = Organization(event.get('org'))
51+
self.org = self._class_attribute(event, 'org', Organization)
52+
5253
#: Event type https://developer.github.com/v3/activity/events/types/
53-
self.type = event.get('type')
54+
self.type = self._get_attribute(event, 'type')
5455
handler = _payload_handlers.get(self.type, identity)
56+
5557
#: Dictionary with the payload. Payload structure is defined by type_.
5658
# _type: http://developer.github.com/v3/events/types
57-
self.payload = handler(event.get('payload'), self)
59+
self.payload = self._class_attribute(event, 'payload', handler, self)
60+
5861
#: Return ``tuple(owner, repository_name)``
59-
self.repo = event.get('repo')
60-
if self.repo is not None:
62+
self.repo = self._get_attribute(event, 'repo')
63+
if self.repo and self.repo is not self.Empty:
6164
self.repo = tuple(self.repo['name'].split('/'))
65+
6266
#: Indicates whether the Event is public or not.
63-
self.public = event.get('public')
67+
self.public = self._get_attribute(event, 'public')
6468

6569
def _repr(self):
6670
return '<Event [{0}]>'.format(self.type[:-5])

github3/gists/comment.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ class GistComment(BaseComment):
3131
"""
3232

3333
def _update_attributes(self, comment):
34-
self._api = comment.get('url')
34+
self._api = self._get_attribute(comment, 'url')
3535
#: :class:`User <github3.users.User>` who made the comment
3636
#: Unless it is not associated with an account
37-
self.user = None
38-
if comment.get('user'):
39-
self.user = User(comment.get('user'), self) # (No coverage)
37+
self.user = self._class_attribute(comment, 'user', User, self)
4038

4139
def _repr(self):
4240
return '<Gist Comment [{0}]>'.format(self.user.login)

github3/gists/file.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ class GistFile(GitHubCore):
1919
2020
"""
2121

22-
def _update_attributes(self, attributes):
22+
def _update_attributes(self, gistfile):
2323
#: The raw URL for the file at GitHub.
24-
self.raw_url = attributes.get('raw_url')
24+
self.raw_url = self._get_attribute(gistfile, 'raw_url')
25+
2526
#: The name of the file.
26-
self.filename = attributes.get('filename')
27+
self.filename = self._get_attribute(gistfile, 'filename')
28+
2729
#: The name of the file.
28-
self.name = attributes.get('filename')
30+
self.name = self._get_attribute(gistfile, 'filename')
31+
2932
#: The language associated with the file.
30-
self.language = attributes.get('language')
33+
self.language = self._get_attribute(gistfile, 'language')
34+
3135
#: The size of the file.
32-
self.size = attributes.get('size')
36+
self.size = self._get_attribute(gistfile, 'size')
37+
3338
#: The content of the file.
34-
self.original_content = attributes.get('content')
39+
self.original_content = self._get_attribute(gistfile, 'content')
3540

3641
def _repr(self):
3742
return '<Gist File [{0}]>'.format(self.name)

0 commit comments

Comments
 (0)
0