Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions github2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_value(self, *args, **kwargs):
# unicode keys are not accepted as kwargs by python, see:
#http://mail-archives.apache.org/mod_mbox/qpid-dev/200609.mbox/%[email protected]%3E
# So we make a local dict with the same keys but as strings:
return datatype(**dict((str(k), v) for (k, v) in value.iteritems()))
return datatype(**dict((str(k), v) for (k, v) in value.items()))
return value

def get_values(self, *args, **kwargs):
Expand All @@ -76,7 +76,7 @@ def get_values(self, *args, **kwargs):
if datatype:
# Same as above, unicode keys will blow up in **args, so we need to
# create a new 'values' dict with string keys
return [datatype(**dict((str(k), v) for (k, v) in value.iteritems()))
return [datatype(**dict((str(k), v) for (k, v) in value.items()))
for value in values]
else:
return values
Expand All @@ -94,7 +94,7 @@ def bullet(title, text):
return """.. py:attribute:: %s\n\n %s\n""" % (title, text)

b = "\n".join([bullet(attr_name, attr.help)
for attr_name, attr in attributes.items()])
for attr_name, attr in list(attributes.items())])
return "\n\n".join([docstring, b])


Expand Down Expand Up @@ -143,19 +143,19 @@ def __new__(cls, name, bases, attrs):
super_new = super(BaseDataType, cls).__new__

_meta = dict([(attr_name, attr_value)
for attr_name, attr_value in attrs.items()
for attr_name, attr_value in list(attrs.items())
if isinstance(attr_value, Attribute)])
attrs["_meta"] = _meta
attributes = _meta.keys()
attributes = list(_meta.keys())
attrs.update(dict([(attr_name, None)
for attr_name in attributes]))

def _contribute_method(name, func):
func.func_name = name
func.__name__ = name
attrs[name] = func

def constructor(self, **kwargs):
for attr_name, attr_value in kwargs.items():
for attr_name, attr_value in list(kwargs.items()):
attr = self._meta.get(attr_name)
if attr:
setattr(self, attr_name, attr.to_python(attr_value))
Expand All @@ -168,24 +168,24 @@ def to_dict(self):
_meta = self._meta
dict_ = vars(self)
return dict([(attr_name, _meta[attr_name].from_python(attr_value))
for attr_name, attr_value in dict_.items()])
for attr_name, attr_value in list(dict_.items())])
# I don't understand what this is trying to do.
# whatever it was meant to do is broken and is breaking the ability to call "vars" on instantiations, which is breaking all kindsa shit. -AS
#_contribute_method("__dict__", to_dict)

def iterate(self):
not_empty = lambda e: e[1] is not None # AS I *think* this is what was intended.
return iter(filter(not_empty, vars(self).items()))
return iter(filter(not_empty, list(vars(self).items())))
_contribute_method("__iter__", iterate)

result_cls = super_new(cls, name, bases, attrs)
result_cls.__doc__ = doc_generator(result_cls.__doc__, _meta)
return result_cls

def contribute_method_to_cls(cls, name, func):
func.func_name = name
func.__name__ = name
return func


class BaseData(object):
__metaclass__ = BaseDataType
class BaseData(object, metaclass=BaseDataType):
pass
4 changes: 2 additions & 2 deletions github2/issues.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib
import urllib.request, urllib.parse, urllib.error

from github2.core import GithubCommand, BaseData, Attribute, DateAttribute

Expand Down Expand Up @@ -47,7 +47,7 @@ def search(self, project, term, state="open"):
:param str state: can be either ``open`` or ``closed``.
"""
return self.get_values("search", project, state,
urllib.quote_plus(term), filter="issues",
urllib.parse.quote_plus(term), filter="issues",
datatype=Issue)

def list(self, project, state="open"):
Expand Down
25 changes: 9 additions & 16 deletions github2/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@
import sys
import time
import httplib2
try:
import json as simplejson # For Python 2.6
except ImportError:
import simplejson
from urlparse import (urlsplit, urlunsplit)
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from urllib import urlencode, quote
import json
from urllib.parse import (urlsplit, urlunsplit, parse_qs,
urlencode, quote)


#: Hostname for API access
Expand Down Expand Up @@ -66,11 +59,11 @@ def encode_authentication_data(self, extra_post_data):
return urlencode(post_data)

def get(self, *path_components):
path_components = filter(None, path_components)
path_components = [_f for _f in path_components if _f]
return self.make_request("/".join(path_components))

def post(self, *path_components, **extra_post_data):
path_components = filter(None, path_components)
path_components = [_f for _f in path_components if _f]
return self.make_request("/".join(path_components), extra_post_data,
method="POST")

Expand Down Expand Up @@ -111,11 +104,11 @@ def raw_request(self, url, extra_post_data, method="GET"):
if response.status >= 400:
raise RuntimeError("unexpected response from github.com %d: %r" % (
response.status, content))
json = simplejson.loads(content)
if json.get("error"):
raise self.GithubError(json["error"][0]["error"])
json_content = json.loads(content.decode())
if json_content.get("error"):
raise self.GithubError(json_content["error"][0]["error"])

return json
return json_content

@property
def http_headers(self):
Expand Down
4 changes: 2 additions & 2 deletions github2/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from github2.core import BaseData, GithubCommand, Attribute
import urllib
import urllib.request, urllib.parse, urllib.error


class User(BaseData):
Expand Down Expand Up @@ -42,7 +42,7 @@ def search(self, query):

:param str query: term to search for
"""
return self.get_values("search", urllib.quote_plus(query),
return self.get_values("search", urllib.parse.quote_plus(query),
filter="users", datatype=User)

def search_by_email(self, query):
Expand Down
15 changes: 5 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@


install_requires = ['httplib2', ]
# simplejson is included in the standard library since Python 2.6 as json.
if sys.version_info[:2] < (2, 6):
install_requires.append('simplejson >= 2.0.9')

long_description = (codecs.open('README.rst', "r", "utf-8").read()
+ "\n" + codecs.open('NEWS.rst', "r", "utf-8").read())
Expand All @@ -28,8 +25,8 @@
keywords="git github api",
platforms=["any"],
packages=find_packages(exclude=['tests']),
scripts=['github2/bin/github_manage_collaborators'],
setup_requires=["sphinxcontrib-cheeseshop"],
# scripts=['github2/bin/github_manage_collaborators'],
# setup_requires=["sphinxcontrib-cheeseshop"],
install_requires=install_requires,
zip_safe=True,
test_suite="tests",
Expand All @@ -39,11 +36,9 @@
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.4",
"Programming Language :: Python :: 2.5",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.0",
"Programming Language :: Python :: 3.1",
"Programming Language :: Python :: 3.2",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
],
Expand Down