comparison venv/lib/python2.7/site-packages/github/Legacy.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2
3 # ########################## Copyrights and license ############################
4 # #
5 # Copyright 2012 Steve English <steve.english@navetas.com> #
6 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
7 # Copyright 2012 Zearin <zearin@gonk.net> #
8 # Copyright 2013 AKFish <akfish@gmail.com> #
9 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
10 # #
11 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
12 # #
13 # PyGithub is free software: you can redistribute it and/or modify it under #
14 # the terms of the GNU Lesser General Public License as published by the Free #
15 # Software Foundation, either version 3 of the License, or (at your option) #
16 # any later version. #
17 # #
18 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
21 # details. #
22 # #
23 # You should have received a copy of the GNU Lesser General Public License #
24 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
25 # #
26 # ##############################################################################
27
28 import urlparse
29
30 import github.PaginatedList
31
32
33 class PaginatedList(github.PaginatedList.PaginatedListBase):
34 def __init__(self, url, args, requester, key, convert, contentClass):
35 github.PaginatedList.PaginatedListBase.__init__(self)
36 self.__url = url
37 self.__args = args
38 self.__requester = requester
39 self.__key = key
40 self.__convert = convert
41 self.__contentClass = contentClass
42 self.__nextPage = 0
43 self.__continue = True
44
45 def _couldGrow(self):
46 return self.__continue
47
48 def _fetchNextPage(self):
49 page = self.__nextPage
50 self.__nextPage += 1
51 return self.get_page(page)
52
53 def get_page(self, page):
54 assert isinstance(page, (int, long)), page
55 args = dict(self.__args)
56 if page != 0:
57 args["start_page"] = page + 1
58 headers, data = self.__requester.requestJsonAndCheck(
59 "GET",
60 self.__url,
61 parameters=args
62 )
63 self.__continue = len(data[self.__key]) > 0
64
65 return [
66 self.__contentClass(self.__requester, headers, self.__convert(element), completed=False)
67 for element in data[self.__key]
68 ]
69
70
71 def convertUser(attributes):
72 convertedAttributes = {
73 "login": attributes["login"],
74 "url": "/users/" + attributes["login"],
75 }
76 if "gravatar_id" in attributes: # pragma no branch
77 convertedAttributes["gravatar_id"] = attributes["gravatar_id"]
78 if "followers" in attributes: # pragma no branch
79 convertedAttributes["followers"] = attributes["followers"]
80 if "repos" in attributes: # pragma no branch
81 convertedAttributes["public_repos"] = attributes["repos"]
82 if "name" in attributes: # pragma no branch
83 convertedAttributes["name"] = attributes["name"]
84 if "created_at" in attributes: # pragma no branch
85 convertedAttributes["created_at"] = attributes["created_at"]
86 if "location" in attributes: # pragma no branch
87 convertedAttributes["location"] = attributes["location"]
88 return convertedAttributes
89
90
91 def convertRepo(attributes):
92 convertedAttributes = {
93 "owner": {"login": attributes["owner"], "url": "/users/" + attributes["owner"]},
94 "url": "/repos/" + attributes["owner"] + "/" + attributes["name"],
95 }
96 if "pushed_at" in attributes: # pragma no branch
97 convertedAttributes["pushed_at"] = attributes["pushed_at"]
98 if "homepage" in attributes: # pragma no branch
99 convertedAttributes["homepage"] = attributes["homepage"]
100 if "created_at" in attributes: # pragma no branch
101 convertedAttributes["created_at"] = attributes["created_at"]
102 if "watchers" in attributes: # pragma no branch
103 convertedAttributes["watchers"] = attributes["watchers"]
104 if "has_downloads" in attributes: # pragma no branch
105 convertedAttributes["has_downloads"] = attributes["has_downloads"]
106 if "fork" in attributes: # pragma no branch
107 convertedAttributes["fork"] = attributes["fork"]
108 if "has_issues" in attributes: # pragma no branch
109 convertedAttributes["has_issues"] = attributes["has_issues"]
110 if "has_wiki" in attributes: # pragma no branch
111 convertedAttributes["has_wiki"] = attributes["has_wiki"]
112 if "forks" in attributes: # pragma no branch
113 convertedAttributes["forks"] = attributes["forks"]
114 if "size" in attributes: # pragma no branch
115 convertedAttributes["size"] = attributes["size"]
116 if "private" in attributes: # pragma no branch
117 convertedAttributes["private"] = attributes["private"]
118 if "open_issues" in attributes: # pragma no branch
119 convertedAttributes["open_issues"] = attributes["open_issues"]
120 if "description" in attributes: # pragma no branch
121 convertedAttributes["description"] = attributes["description"]
122 if "language" in attributes: # pragma no branch
123 convertedAttributes["language"] = attributes["language"]
124 if "name" in attributes: # pragma no branch
125 convertedAttributes["name"] = attributes["name"]
126 return convertedAttributes
127
128
129 def convertIssue(attributes):
130 convertedAttributes = {
131 "number": attributes["number"],
132 "url": "/repos" + urlparse.urlparse(attributes["html_url"]).path,
133 "user": {"login": attributes["user"], "url": "/users/" + attributes["user"]},
134 }
135 if "labels" in attributes: # pragma no branch
136 convertedAttributes["labels"] = [{"name": label} for label in attributes["labels"]]
137 if "title" in attributes: # pragma no branch
138 convertedAttributes["title"] = attributes["title"]
139 if "created_at" in attributes: # pragma no branch
140 convertedAttributes["created_at"] = attributes["created_at"]
141 if "comments" in attributes: # pragma no branch
142 convertedAttributes["comments"] = attributes["comments"]
143 if "body" in attributes: # pragma no branch
144 convertedAttributes["body"] = attributes["body"]
145 if "updated_at" in attributes: # pragma no branch
146 convertedAttributes["updated_at"] = attributes["updated_at"]
147 if "state" in attributes: # pragma no branch
148 convertedAttributes["state"] = attributes["state"]
149 return convertedAttributes