From 991ab2968e4330ef2c3b0150ad7e6060bc59e692 Mon Sep 17 00:00:00 2001 From: Bas ten Berge Date: Fri, 7 Aug 2015 17:29:19 +0200 Subject: [PATCH 1/6] Now works on python version 2.6 as well Prevents the AttributeError concerning the version dependent code when running on python 2.6 --- choice/basicterm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/choice/basicterm.py b/choice/basicterm.py index 902a40e..41b3ff8 100644 --- a/choice/basicterm.py +++ b/choice/basicterm.py @@ -1,7 +1,12 @@ from __future__ import division, absolute_import, print_function, unicode_literals import sys -if sys.version_info.major < 3: + +try: + if sys.version_info.major < 3: + input = raw_input +except AttributeError: + # Python 2.6 has a version tuple input = raw_input from choice.util import idNameList From d6e5644292542721c0ac67c1d483e332ce5bcb89 Mon Sep 17 00:00:00 2001 From: Bas ten Berge Date: Fri, 7 Aug 2015 17:31:12 +0200 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 24a7c98..35387b4 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Requirements and Installation For basic functionality: -* Python 2.7 or 3 +* Python 2.6 or 3 To install, just run: From f7f2fbb83d40af1992d03e61c262a497a4d6c7f6 Mon Sep 17 00:00:00 2001 From: Bas ten Berge Date: Fri, 7 Aug 2015 17:52:32 +0200 Subject: [PATCH 3/6] Update basicterm.py --- choice/basicterm.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/choice/basicterm.py b/choice/basicterm.py index 41b3ff8..93ebea0 100644 --- a/choice/basicterm.py +++ b/choice/basicterm.py @@ -9,6 +9,8 @@ # Python 2.6 has a version tuple input = raw_input +from os import linesep + from choice.util import idNameList class BasicTermMenu(object): @@ -138,12 +140,12 @@ def __init__(self, prompt, default): def ask(self): if self.default is None: - prompt = '{}\n(y/n)? '.format(self.prompt) + options = '(y/n)' elif self.default == True: - prompt = '{}\n(Y/n)? '.format(self.prompt) + options = '{}\n(Y/n)' elif self.default == False: - prompt = '{}\n(y/N)? '.format(self.prompt) - resp = input(prompt).lower().strip() + options = '(y/N)' + resp = input(self.prompt + linesep + options + '? ').lower().strip() if len(resp) == 0 and self.default is not None: return self.default From 0ed612ca4cacd8d1ab4a819aa68cfd800fadc66c Mon Sep 17 00:00:00 2001 From: Bas ten Berge Date: Sat, 8 Aug 2015 00:08:00 +0200 Subject: [PATCH 4/6] Update basicterm.py Fixed an exception occuring when pressing 'b' on a Menu with only a list of choices Example classes are now working on python 2.6 as well --- choice/basicterm.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/choice/basicterm.py b/choice/basicterm.py index 93ebea0..772d4e1 100644 --- a/choice/basicterm.py +++ b/choice/basicterm.py @@ -34,16 +34,16 @@ def pick_choice(self): start = curr_page * self.PAGE_SIZE end = start + self.PAGE_SIZE for i, c in enumerate(self.choices[start:end]): - print(" {}: {}".format(i, c[1])) + print(" {0}: {1}".format(i, c[1])) if self.global_actions is not None: print() for ga in self.global_actions: if ga[0] == ga[1]: - print(" {}".format(ga[0])) + print(" {0}".format(ga[0])) else: - print(" {}: {}".format(ga[0], ga[1])) + print(" {0}: {1}".format(ga[0], ga[1])) - print("\nEnter number or name; return for next page") + print(linesep + "Enter number or name; return for next page") resp = input('? ').strip() print() if len(resp) == 0: @@ -60,8 +60,8 @@ def pick_choice(self): def pick_action(self): print("Select an action:") for i, ac in enumerate(self.actions): - print(" {}: {}".format(i, ac[1])) - print(" {}: back".format(self.BACK_CHAR)) + print(" {0}: {1}".format(i, ac[1])) + print(" {0}: back".format(self.BACK_CHAR)) resp = input('? ') print() return str(resp) @@ -77,7 +77,7 @@ def ask(self): break else: # Global action? - for ga in self.global_actions: + for ga in self.global_actions or []: if resp == ga[0]: return None, ga[0] @@ -88,7 +88,7 @@ def ask(self): break if choice is None: - print("{} is not a valid choice".format(resp)) + print("{0} is not a valid choice".format(resp)) assert choice is not None if self.actions is None or len(self.actions) == 1: @@ -113,7 +113,7 @@ def ask(self): action = ac break if action is None: - print("{} is not a valid choice".format(resp)) + print("{0} is not a valid choice".format(resp)) assert action is not None return choice[0], action[0] @@ -125,7 +125,7 @@ def __init__(self, prompt, parser): self.parser = parser def ask(self): - resp = input('{}:\n? '.format(self.prompt)) + resp = input(self.prompt + ':' + linesep + '? ') try: return self.parser(resp) except ValueError: @@ -142,7 +142,7 @@ def ask(self): if self.default is None: options = '(y/n)' elif self.default == True: - options = '{}\n(Y/n)' + options = '(Y/n)' elif self.default == False: options = '(y/N)' resp = input(self.prompt + linesep + options + '? ').lower().strip() From 872e8e8ef2c0cedcac609fa99d14947ba6146ce6 Mon Sep 17 00:00:00 2001 From: Bas ten Berge Date: Mon, 10 Aug 2015 08:26:10 +0200 Subject: [PATCH 5/6] Update setup.py Proposing a new version of the package because I need it. The intention of the c used in the version is to make sure it's considered an older version when the original author creates the real version 0.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ecb4284..cd24c8a 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup(name='choice', - version='0.1', + version='0.2c1', author='Frank Huang', author_email='me@nongraphical.com', url='https://github.com/fyhuang/choice', From 18a15b671813a54fc436d4a3f0173611d29e13ec Mon Sep 17 00:00:00 2001 From: Bas ten Berge Date: Mon, 10 Aug 2015 08:40:05 +0200 Subject: [PATCH 6/6] Update test.py Can now test on python 2.6 too --- test/test.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/test.py b/test/test.py index fd454e8..ad4c22f 100644 --- a/test/test.py +++ b/test/test.py @@ -1,20 +1,23 @@ import choice +def c(): + print("Delete confirmed") + # Get a yes or no response (default is no) confirm = choice.Binary('Are you sure you want to delete?', False).ask() if confirm: - deleteIt() + c() # Input an arbitrary value, check for correctness howmany = choice.Input('How many pies?', int).ask() -print("You ordered {} pies".format(howmany)) +print("You ordered {0} pies".format(howmany)) # Choose from a set of options entree = choice.Menu(['steak', 'potatoes', 'eggplant']).ask() -print("You choice {}".format(entree)) +print("You choice {0}".format(entree)) -posts = ['post {}'.format(num) for num in range(15)] +posts = ['post {0}'.format(num) for num in range(15)] resp = choice.Menu(posts, ['edit', 'delete', 'publish'], ['newpost', 'exit']).ask() print(resp)