diff --git a/github2/core.py b/github2/core.py index caf20a9..24d9cc8 100644 --- a/github2/core.py +++ b/github2/core.py @@ -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/%3C1159389941.4505.10.camel@localhost.localdomain%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): @@ -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 @@ -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]) @@ -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)) @@ -168,14 +168,14 @@ 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) @@ -183,9 +183,9 @@ def iterate(self): 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 diff --git a/github2/issues.py b/github2/issues.py index f58bf83..86deb94 100644 --- a/github2/issues.py +++ b/github2/issues.py @@ -1,4 +1,4 @@ -import urllib +import urllib.request, urllib.parse, urllib.error from github2.core import GithubCommand, BaseData, Attribute, DateAttribute @@ -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"): diff --git a/github2/request.py b/github2/request.py index 557e8fd..c3e4512 100644 --- a/github2/request.py +++ b/github2/request.py @@ -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 @@ -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") @@ -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): diff --git a/github2/users.py b/github2/users.py index 4251cb3..344eee5 100644 --- a/github2/users.py +++ b/github2/users.py @@ -1,5 +1,5 @@ from github2.core import BaseData, GithubCommand, Attribute -import urllib +import urllib.request, urllib.parse, urllib.error class User(BaseData): @@ -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): diff --git a/setup.py b/setup.py index e08fe80..f157363 100644 --- a/setup.py +++ b/setup.py @@ -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()) @@ -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", @@ -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", ],