1111from requests import session
1212
1313
14- class GitHubCore (object ):
14+ class GitHubObject (object ):
15+ """The :class:`GitHubObject <GitHubObject>` object. A basic class to be
16+ subclassed by GitHubCore and other classes that would otherwise subclass
17+ object."""
18+ def __init__ (self , json ):
19+ super (GitHubObject , self ).__init__ ()
20+ self ._json_data = json
21+
22+ def to_json (self ):
23+ """Return the json representing this object."""
24+ return self ._json_data
25+
26+ @classmethod
27+ def from_json (cls , json ):
28+ """Return an instance of ``cls`` formed from ``json``."""
29+ return cls (json )
30+
31+
32+ class GitHubCore (GitHubObject ):
1533 """The :class:`GitHubCore <GitHubCore>` object. This class provides some
1634 basic attributes to other classes that are very useful to have.
1735 """
@@ -35,14 +53,14 @@ def _json(self, request, status_code):
3553 if request .status_code == status_code and request .content :
3654 ret = request .json
3755 if request .status_code >= 400 :
38- raise Error (request )
56+ raise GitHubError (request )
3957 return ret
4058
4159 def _boolean (self , request , true_code , false_code ):
4260 if request .status_code == true_code :
4361 return True
4462 if request .status_code != false_code and request .status_code >= 400 :
45- raise Error (request )
63+ raise GitHubError (request )
4664 return False
4765
4866 def _delete (self , url , ** kwargs ):
@@ -96,15 +114,6 @@ def ratelimit_remaining(self):
96114 self ._remaining = json .get ('rate' , {}).get ('remaining' , 0 )
97115 return self ._remaining
98116
99- def to_json (self ):
100- """Return the json representing this object."""
101- return self ._json_data
102-
103- @classmethod
104- def from_json (cls , json ):
105- """Return an instance of ``cls`` formed from ``json``."""
106- return cls (json )
107-
108117 @staticmethod
109118 def requires_auth (func ):
110119 """Decorator to note which class methods require authorization."""
@@ -117,7 +126,7 @@ def auth_wrapper(self, *args, **kwargs):
117126 if auth :
118127 return func (self , * args , ** kwargs )
119128 else :
120- raise Error (type ('Faux Request' , (object , ),
129+ raise GitHubError (type ('Faux Request' , (object , ),
121130 {'status_code' : 401 , 'message' : 'Requires authentication' }
122131 ))
123132
@@ -373,9 +382,9 @@ def public_repos(self):
373382 return self ._public_repos
374383
375384
376- class Error (Exception ):
385+ class GitHubError (Exception ):
377386 def __init__ (self , resp ):
378- super (Error , self ).__init__ ()
387+ super (GitHubError , self ).__init__ ()
379388 self ._code = resp .status_code
380389 error = resp .json
381390 self ._message = error .get ('message' )
0 commit comments