From f9267af4716759bc4fa387231a4bde96eb722cb9 Mon Sep 17 00:00:00 2001 From: goosemo Date: Thu, 5 May 2011 15:04:32 -0400 Subject: [PATCH 1/7] Ran 2to3 on it and fixed the one .decode() issue for json I knew of --- github2/core.py | 24 ++++++++++++------------ github2/issues.py | 4 ++-- github2/request.py | 12 ++++++------ github2/users.py | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) 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..22221f8 100644 --- a/github2/request.py +++ b/github2/request.py @@ -6,12 +6,12 @@ import json as simplejson # For Python 2.6 except ImportError: import simplejson -from urlparse import (urlsplit, urlunsplit) +from urllib.parse import (urlsplit, urlunsplit) try: - from urlparse import parse_qs + from urllib.parse import parse_qs except ImportError: from cgi import parse_qs -from urllib import urlencode, quote +from urllib.parse import urlencode, quote #: Hostname for API access @@ -66,11 +66,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,7 +111,7 @@ 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) + json = simplejson.loads(content.decode()) if json.get("error"): raise self.GithubError(json["error"][0]["error"]) 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): From 4950a669b545670d445bf2267846f0d06d4a1124 Mon Sep 17 00:00:00 2001 From: goosemo Date: Thu, 5 May 2011 15:05:43 -0400 Subject: [PATCH 2/7] Cleaned up imports and json on request.py --- github2/request.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/github2/request.py b/github2/request.py index 22221f8..9bca096 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 urllib.parse import (urlsplit, urlunsplit) -try: - from urllib.parse import parse_qs -except ImportError: - from cgi import parse_qs -from urllib.parse import urlencode, quote +import json +from urllib.parse import (urlsplit, urlunsplit, pasrse_qa, + urlencode, quote) #: Hostname for API access @@ -111,7 +104,7 @@ 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.decode()) + json = json.loads(content.decode()) if json.get("error"): raise self.GithubError(json["error"][0]["error"]) From 77c3f5083378899e73b949010c1cd649fb16d61e Mon Sep 17 00:00:00 2001 From: Morgan Goose Date: Thu, 5 May 2011 16:10:51 -0400 Subject: [PATCH 3/7] Commented out troublesome setup.py lines --- setup.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index e08fe80..6ee40f6 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", From 6cfea0b3ce303c71137d81ce4fc556d0e1fb72e0 Mon Sep 17 00:00:00 2001 From: Morgan Goose Date: Thu, 5 May 2011 16:13:30 -0400 Subject: [PATCH 4/7] Made the setup.py state this is a python 3 lib --- setup.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 6ee40f6..f157363 100644 --- a/setup.py +++ b/setup.py @@ -36,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", ], From 0956c0eff24d6ef69c52394cb0f9c8e4bf2e44aa Mon Sep 17 00:00:00 2001 From: Morgan Goose Date: Thu, 5 May 2011 16:14:47 -0400 Subject: [PATCH 5/7] fixed spelling error --- github2/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github2/request.py b/github2/request.py index 9bca096..e892aae 100644 --- a/github2/request.py +++ b/github2/request.py @@ -3,7 +3,7 @@ import time import httplib2 import json -from urllib.parse import (urlsplit, urlunsplit, pasrse_qa, +from urllib.parse import (urlsplit, urlunsplit, parse_qa, urlencode, quote) From 590a50e291e66f2048bd672248cd74efc5d7dd75 Mon Sep 17 00:00:00 2001 From: Morgan Goose Date: Thu, 5 May 2011 16:17:42 -0400 Subject: [PATCH 6/7] fixed spelling error. more. --- github2/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github2/request.py b/github2/request.py index e892aae..aba52a1 100644 --- a/github2/request.py +++ b/github2/request.py @@ -3,7 +3,7 @@ import time import httplib2 import json -from urllib.parse import (urlsplit, urlunsplit, parse_qa, +from urllib.parse import (urlsplit, urlunsplit, parse_qs, urlencode, quote) From 7ace07acb611d50e2514c0c3d82ad55ad37e3bef Mon Sep 17 00:00:00 2001 From: Morgan Goose Date: Thu, 5 May 2011 16:20:04 -0400 Subject: [PATCH 7/7] Addressed my 'fixing' of the simplejson stuff, as I made a var the same name as the module. --- github2/request.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github2/request.py b/github2/request.py index aba52a1..c3e4512 100644 --- a/github2/request.py +++ b/github2/request.py @@ -104,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 = json.loads(content.decode()) - 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):