From edd33578306289dde3444321db3cfca7cd3564a6 Mon Sep 17 00:00:00 2001 From: Anthony Gargiulo Date: Fri, 15 Jun 2012 15:11:51 -0400 Subject: [PATCH 1/2] Updated from python 2.x to python 3 using https://github.com/mitsuhiko/python-modernize --- docs/conf.py | 17 +++++++++-------- pygithub3/__init__.py | 2 +- pygithub3/core/result/base.py | 3 ++- pygithub3/core/result/smart.py | 2 +- pygithub3/core/third_libs/link_header.py | 3 ++- pygithub3/core/utils.py | 2 ++ pygithub3/requests/users/emails.py | 1 + pygithub3/services/gists/__init__.py | 2 +- pygithub3/tests/core/test_result.py | 4 +++- pygithub3/tests/resources/test_core.py | 1 + setup.py | 2 ++ 11 files changed, 25 insertions(+), 14 deletions(-) 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 9a626f3..e13b425 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/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..ecd1851 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])) \ No newline at end of file diff --git a/pygithub3/core/utils.py b/pygithub3/core/utils.py index c6dbf0a..d59a495 100644 --- a/pygithub3/core/utils.py +++ b/pygithub3/core/utils.py @@ -3,6 +3,8 @@ """ Utils to support python 2.6 compatibility """ 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..892be21 100644 --- a/pygithub3/requests/users/emails.py +++ b/pygithub3/requests/users/emails.py @@ -4,6 +4,7 @@ import re from . import Request, ValidationError +from six.moves import filter # Src: http://code.djangoproject.com/svn/django/trunk/django/core/validators.py email_re = re.compile( 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/tests/core/test_result.py b/pygithub3/tests/core/test_result.py index b32fb3d..b885c9f 100644 --- a/pygithub3/tests/core/test_result.py +++ b/pygithub3/tests/core/test_result.py @@ -9,6 +9,8 @@ from pygithub3.tests.utils.core import (mock_paginate_github_in_GET, request, mock_no_paginate_github_in_GET, MockPaginate) +from six.moves import filter +import six class ResultInitMixin(object): @@ -66,7 +68,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..130f784 100644 --- a/pygithub3/tests/resources/test_core.py +++ b/pygithub3/tests/resources/test_core.py @@ -6,6 +6,7 @@ from pygithub3.tests.utils.core import TestCase from pygithub3.resources.base import Raw from pygithub3.tests.utils.resources import Nested, Simple, HasSimple +from six.moves import filter simple_resource = dict(type='simple') has_simple = dict(type='has_simple', simple=simple_resource) diff --git a/setup.py b/setup.py index ad082b9..4a49462 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,8 @@ from setuptools import setup, find_packages import pygithub3 +from six.moves import map +from six.moves import zip setup( name=pygithub3.__name__, From 78b74c3afe37f4172d6b933a90757256efb8ff9b Mon Sep 17 00:00:00 2001 From: Anthony Gargiulo Date: Fri, 15 Jun 2012 15:52:39 -0400 Subject: [PATCH 2/2] python-modernize missed this one import. Should actually work now. --- pygithub3/core/result/link.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygithub3/core/result/link.py b/pygithub3/core/result/link.py index dae8407..a0e619f 100644 --- a/pygithub3/core/result/link.py +++ b/pygithub3/core/result/link.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- encoding: utf-8 -*- -from urlparse import urlparse, parse_qs +from urllib.parse import urlparse, parse_qs from pygithub3.core.third_libs.link_header import parse_link_value