diff --git a/docs/conf.py b/docs/conf.py index c10f5c0..b71d592 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,7 @@ # serve to show the default. import sys, os +import six # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -41,8 +42,8 @@ master_doc = 'index' # General information about the project. -project = u'pygithub3' -copyright = u'2012, David Medina' +project = six.u('pygithub3') +copyright = six.u('2012, David Medina') # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -189,8 +190,8 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'pygithub3.tex', u'pygithub3 Documentation', - u'David Medina', 'manual'), + ('index', 'pygithub3.tex', six.u('pygithub3 Documentation'), + six.u('David Medina'), 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -219,8 +220,8 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'pygithub3', u'pygithub3 Documentation', - [u'David Medina'], 1) + ('index', 'pygithub3', six.u('pygithub3 Documentation'), + [six.u('David Medina')], 1) ] # If true, show URL addresses after external links. @@ -233,8 +234,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'pygithub3', u'pygithub3 Documentation', - u'David Medina', 'pygithub3', 'One line description of project.', + ('index', 'pygithub3', six.u('pygithub3 Documentation'), + six.u('David Medina'), 'pygithub3', 'One line description of project.', 'Miscellaneous'), ] diff --git a/pygithub3/__init__.py b/pygithub3/__init__.py index f46dec1..771593e 100644 --- a/pygithub3/__init__.py +++ b/pygithub3/__init__.py @@ -8,4 +8,4 @@ __license__ = 'ISC' __copyright__ = 'Copyright 2012 David Medina' -from github import Github +from .github import Github diff --git a/pygithub3/core/result/base.py b/pygithub3/core/result/base.py index b33f97e..9e7cecb 100644 --- a/pygithub3/core/result/base.py +++ b/pygithub3/core/result/base.py @@ -2,6 +2,7 @@ # -*- encoding: utf-8 -*- import functools +import six class Method(object): @@ -72,7 +73,7 @@ def wrapper(self): @get_content def __next__(self): try: - return self.iterable.next() + return six.advance_iterator(self.iterable) except StopIteration: self.iterable = iter(self.getter(self.page)) raise StopIteration diff --git a/pygithub3/core/result/link.py b/pygithub3/core/result/link.py index dae8407..a20ec9c 100644 --- a/pygithub3/core/result/link.py +++ b/pygithub3/core/result/link.py @@ -1,7 +1,12 @@ #!/usr/bin/env python # -*- encoding: utf-8 -*- -from urlparse import urlparse, parse_qs +try: + # Python 3 + from urllib.parse import urlparse, parse_qs +except ImportError: + from urlparse import urlparse, parse_qs + from pygithub3.core.third_libs.link_header import parse_link_value diff --git a/pygithub3/core/result/smart.py b/pygithub3/core/result/smart.py index 0343a9b..d93c9c2 100644 --- a/pygithub3/core/result/smart.py +++ b/pygithub3/core/result/smart.py @@ -105,6 +105,6 @@ def get_page(self, page): :param int page: Page number """ - if page in xrange(1, self.pages + 1): + if page in range(1, self.pages + 1): return base.Page(self.getter, page) return None diff --git a/pygithub3/core/third_libs/link_header.py b/pygithub3/core/third_libs/link_header.py index 3959604..67e70d1 100644 --- a/pygithub3/core/third_libs/link_header.py +++ b/pygithub3/core/third_libs/link_header.py @@ -5,6 +5,7 @@ Simple routines to parse and manipulate Link headers. """ +from __future__ import print_function __license__ = """ Copyright (c) 2009 Mark Nottingham @@ -86,4 +87,4 @@ def parse_link_value(instr): if __name__ == '__main__': import sys if len(sys.argv) > 1: - print parse_link_value(sys.argv[1]) \ No newline at end of file + print(parse_link_value(sys.argv[1])) diff --git a/pygithub3/core/utils.py b/pygithub3/core/utils.py index 24a3bbf..7ac7b38 100644 --- a/pygithub3/core/utils.py +++ b/pygithub3/core/utils.py @@ -8,6 +8,8 @@ import json from collections import MutableMapping +from six.moves import map +from six.moves import zip def _import_module(module_uri): diff --git a/pygithub3/requests/users/emails.py b/pygithub3/requests/users/emails.py index ff89b62..f4a1556 100644 --- a/pygithub3/requests/users/emails.py +++ b/pygithub3/requests/users/emails.py @@ -30,7 +30,7 @@ def is_email(email): raise ValidationError("'%s' request needs emails" % (self.__class__.__name__)) - return filter(is_email, self.body) + return tuple([ele for ele in self.body if is_email(ele)]) class Delete(Request): diff --git a/pygithub3/services/gists/__init__.py b/pygithub3/services/gists/__init__.py index aadb136..579e291 100644 --- a/pygithub3/services/gists/__init__.py +++ b/pygithub3/services/gists/__init__.py @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- from pygithub3.services.base import Service -from comments import Comments +from .comments import Comments class Gist(Service): diff --git a/pygithub3/services/issues/labels.py b/pygithub3/services/issues/labels.py index d1119d3..5bc0d81 100644 --- a/pygithub3/services/issues/labels.py +++ b/pygithub3/services/issues/labels.py @@ -2,6 +2,8 @@ # -*- encoding: utf-8 -*- from pygithub3.services.base import Service +from six.moves import map +from six.moves import zip class Labels(Service): diff --git a/pygithub3/tests/core/test_result.py b/pygithub3/tests/core/test_result.py index b32fb3d..2112777 100644 --- a/pygithub3/tests/core/test_result.py +++ b/pygithub3/tests/core/test_result.py @@ -9,6 +9,7 @@ from pygithub3.tests.utils.core import (mock_paginate_github_in_GET, request, mock_no_paginate_github_in_GET, MockPaginate) +import six class ResultInitMixin(object): @@ -38,7 +39,7 @@ def test_iteration_CALLS(self): def test_consumed_are_Pages(self): pages_that_are_Pages = len( - filter(lambda page: isinstance(page, base.Page), list(self.r))) + [page for page in self.r if isinstance(page, base.Page)]) self.assertEqual(pages_that_are_Pages, 3, 'There are not 3 Pages objs') def test_all_iteration_CALLS(self): @@ -66,7 +67,7 @@ def mock(self): return mock_no_paginate_github_in_GET def test_iteration_stop_at_1(self): - self.r.next() + six.advance_iterator(self.r) self.assertRaises(StopIteration, self.r.next) def test_get_only_1page(self): diff --git a/pygithub3/tests/resources/test_core.py b/pygithub3/tests/resources/test_core.py index d8b8541..a7ec5dc 100644 --- a/pygithub3/tests/resources/test_core.py +++ b/pygithub3/tests/resources/test_core.py @@ -38,8 +38,8 @@ def test_MAPS(self): self.assertEqual(self.r.simple.type, 'simple') def test_LIST_collection_map(self): - has_simple_objects = filter(lambda x: isinstance(x, HasSimple), - self.r.list_collection) + has_simple_objects = [obj for obj in self.r.list_collection + if isinstance(obj, HasSimple)] self.assertEqual(len(has_simple_objects), 2) self.assertEqual(self.r.list_collection[0].type, 'has_simple') self.assertEqual(self.r.list_collection[0].simple.type, 'simple') diff --git a/requirements/base.txt b/requirements/base.txt index 285540e..d5aa090 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1 +1,2 @@ requests >= 0.12.1 +six diff --git a/setup.py b/setup.py index 37062b3..2e0abaf 100644 --- a/setup.py +++ b/setup.py @@ -28,12 +28,16 @@ 'nose', 'mock', ], - install_requires=map(str.strip, open(join('requirements', 'base.txt'))), + install_requires=[ + s.strip() for s in open(join('requirements', 'base.txt'))], include_package_data=True, classifiers=( 'Programming Language :: Python', + 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', 'License :: OSI Approved :: ISC License (ISCL)', 'Operating System :: OS Independent', 'Development Status :: 2 - Pre-Alpha',