0
@@ -15,17 +15,17 @@ Copyright (c) 2007 Dustin Sallings <dustin@spy.net>
0
# Copyright (c) 2005 Dustin Sallings <dustin@spy.net>
0
# Permission is hereby granted, free of charge, to any person obtaining a copy
0
# of this software and associated documentation files (the "Software"), to deal
0
# in the Software without restriction, including without limitation the rights
0
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0
# copies of the Software, and to permit persons to whom the Software is
0
# furnished to do so, subject to the following conditions:
0
# The above copyright notice and this permission notice shall be included in
0
# all copies or substantial portions of the Software.
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0
@@ -39,22 +39,23 @@ Copyright (c) 2007 Dustin Sallings <dustin@spy.net>
0
# GAE friendly URL detection (theoretically)
0
- default_fetcher
=urllib2.urlopen
0
+ default_fetcher
= urllib2.urlopen
0
class Repository(object):
0
"""A github repository."""
0
def __init__(self, el):
0
if ch.nodeType != xml.dom.Node.TEXT_NODE and ch.firstChild:
0
- if
ch.attributes.has_key('type'):
0
+ if
'type' in ch.attributes.keys():
0
type = ch.attributes['type'].value
0
self.__dict__[ch.localName] = int(ch.firstChild.data)
0
@@ -65,28 +66,30 @@ class Repository(object):
0
return "<<Repository %s>>" % self.name
0
def __init__(self, el):
0
if ch.nodeType != xml.dom.Node.TEXT_NODE:
0
if ch.localName != 'repositories':
0
self.__dict__[ch.localName] = ch.firstChild.data
0
- repos=[Repository(el) for el in el.getElementsByTagName('repository')]
0
- self.repos=dict([(r.name, r) for r in repos])
0
+ rps = [Repository(el) for el in el.getElementsByTagName('repository')]
0
+ self.repos = dict([(r.name, r) for r in rps])
0
return "<<Person %s <%s>>>" % (self.name, self.email)
0
class SearchResults(object):
0
def __init__(self, el):
0
- self.repos=[Repository(el)
0
+ self.repos = [Repository(el)
0
for el in el.getElementsByTagName('repository')]
0
@@ -104,6 +107,7 @@ class SearchResults(object):
0
return "<<SearchResults with %d repos>>" % len(self.repos)
0
@@ -113,6 +117,7 @@ class User(Person):
0
return "<<User %s with %d repos>>" % (self.login, len(self.repos))
0
class FileModification(object):
0
"""Object representing a specific file modification."""
0
@@ -123,14 +128,15 @@ class FileModification(object):
0
return "<<FileModification: %s>>" % self.filename
0
def __init__(self, el):
0
if ch.nodeType != xml.dom.Node.TEXT_NODE:
0
if ch.localName == 'parents':
0
@@ -165,42 +171,43 @@ class Commit(object):
0
return "<<Commit %s>>" % self.id
0
"""Interface to github."""
0
def __init__(self, fetcher=default_fetcher):
0
+ self.fetcher
= fetcher
0
def user(self, username):
0
"""Get the info for a user."""
0
- x=self.fetcher("http://github.com/api/v1/xml/%s" % username).read()
0
- doc=xml.dom.minidom.parseString(x)
0
+ x = self.fetcher("http://github.com/api/v1/xml/%s" % username).read()
0
+ doc = xml.dom.minidom.parseString(x)
0
def search(self, search_string):
0
"""Search for repositories."""
0
- x
=self.fetcher("http://github.com/api/v1/xml/search/%s"
0
+ x
= self.fetcher("http://github.com/api/v1/xml/search/%s"
0
% search_string.replace(' ', '+')).read()
0
- doc
=xml.dom.minidom.parseString(x)
0
+ doc
= xml.dom.minidom.parseString(x)
0
return SearchResults(doc)
0
def commits(self, username, repo, branch='master'):
0
"""Get the recent commits for the given repo."""
0
- x
=self.fetcher("http://github.com/api/v1/xml/%s/%s/commits/%s"
0
+ x
= self.fetcher("http://github.com/api/v1/xml/%s/%s/commits/%s"
0
% (username, repo, branch)).read()
0
- doc
=xml.dom.minidom.parseString(x)
0
+ doc
= xml.dom.minidom.parseString(x)
0
return [Commit(el) for el in doc.getElementsByTagName('commit')]
0
def commit(self, username, repo, commit):
0
"""Get a specific commit from the given repo."""
0
- x
=self.fetcher("http://github.com/api/v1/xml/%s/%s/commit/%s"
0
+ x
= self.fetcher("http://github.com/api/v1/xml/%s/%s/commit/%s"
0
% (username, repo, commit)).read()
0
- doc
=xml.dom.minidom.parseString(x)
0
+ doc
= xml.dom.minidom.parseString(x)
0
return Commit(doc.getElementsByTagName('commit')[0])
0
if __name__ == '__main__':
0
u = gh.user(sys.argv[1])
0
print "User: %s (%s)" % (u.login, u.name)
Comments
No one has commented yet.