From cee218b17a8da409a077e4db0d0c7b7fe6c8b784 Mon Sep 17 00:00:00 2001 From: Asger Graarup Overby Date: Thu, 21 Jan 2016 14:36:44 +0100 Subject: [PATCH 1/5] Add support for Python 3 --- lib/LoginLibrary.py | 2 +- sut/login.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/LoginLibrary.py b/lib/LoginLibrary.py index 27ec0a2..1560887 100644 --- a/lib/LoginLibrary.py +++ b/lib/LoginLibrary.py @@ -26,6 +26,6 @@ def status_should_be(self, expected_status): def _run_command(self, command, *args): command = [sys.executable, self._sut_path, command] + list(args) - process = subprocess.Popen(command, stdout=subprocess.PIPE, + process = subprocess.Popen(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) self._status = process.communicate()[0].strip() diff --git a/sut/login.py b/sut/login.py index ef2003b..d74a188 100755 --- a/sut/login.py +++ b/sut/login.py @@ -27,7 +27,7 @@ def _read_users(self, path): def create_user(self, username, password): try: user = User(username, password) - except ValueError, err: + except ValueError as err: return 'Creating user failed: %s' % err self.users[user.username] = user return 'SUCCESS' @@ -47,14 +47,14 @@ def change_password(self, username, old_pwd, new_pwd): if not self._is_valid_user(username, old_pwd): raise ValueError('Access Denied') self.users[username].password = new_pwd - except ValueError, err: + except ValueError as err: return 'Changing password failed: %s' % err else: return 'SUCCESS' def save(self): with open(self.db_file, 'w') as file: - for user in self.users.values(): + for user in list(self.users.values()): file.write('%s\t%s\t%s\n' % (user.username, user.password, user.status)) @@ -104,22 +104,22 @@ def _validate_password_chars(self, password): def login(username, password): with UserDataBase() as db: - print db.login(username, password) + print(db.login(username, password)) def create_user(username, password): with UserDataBase() as db: - print db.create_user(username, password) + print(db.create_user(username, password)) def change_password(username, old_pwd, new_pwd): with UserDataBase() as db: - print db.change_password(username, old_pwd, new_pwd) + print(db.change_password(username, old_pwd, new_pwd)) def help(): - print ('Usage: %s { create | login | change-password | help }' - % os.path.basename(sys.argv[0])) + print(('Usage: %s { create | login | change-password | help }' + % os.path.basename(sys.argv[0]))) if __name__ == '__main__': From baa2d80eca808a30d5ceceab9d6114a94b508f49 Mon Sep 17 00:00:00 2001 From: Asger Graarup Overby Date: Fri, 22 Jan 2016 19:51:42 +0100 Subject: [PATCH 2/5] ADD from __future__ import print_function --- sut/login.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sut/login.py b/sut/login.py index d74a188..169b98b 100755 --- a/sut/login.py +++ b/sut/login.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + import os.path import sys import tempfile From 36bcf32111fcc8c8b63c1a66ab0a7016456a4145 Mon Sep 17 00:00:00 2001 From: Asger Graarup Overby Date: Fri, 22 Jan 2016 19:54:26 +0100 Subject: [PATCH 3/5] DEL unneeded list() --- sut/login.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sut/login.py b/sut/login.py index 169b98b..149de2a 100755 --- a/sut/login.py +++ b/sut/login.py @@ -56,7 +56,7 @@ def change_password(self, username, old_pwd, new_pwd): def save(self): with open(self.db_file, 'w') as file: - for user in list(self.users.values()): + for user in self.users.values(): file.write('%s\t%s\t%s\n' % (user.username, user.password, user.status)) From cbd0505577a51c5eb6ad4e40ef1206a4fa12d8c5 Mon Sep 17 00:00:00 2001 From: Asger Graarup Overby Date: Fri, 22 Jan 2016 19:55:56 +0100 Subject: [PATCH 4/5] DEL unneeded parentheses. --- sut/login.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sut/login.py b/sut/login.py index 149de2a..2936bae 100755 --- a/sut/login.py +++ b/sut/login.py @@ -120,8 +120,8 @@ def change_password(username, old_pwd, new_pwd): def help(): - print(('Usage: %s { create | login | change-password | help }' - % os.path.basename(sys.argv[0]))) + print('Usage: %s { create | login | change-password | help }' + % os.path.basename(sys.argv[0])) if __name__ == '__main__': From c23ad1874ce396eb40d3e2e87df1acf44513aae1 Mon Sep 17 00:00:00 2001 From: Asger Graarup Overby Date: Fri, 22 Jan 2016 20:23:29 +0100 Subject: [PATCH 5/5] Updated README.rst and QuickStart.rst with respect to support for Python 3. --- QuickStart.rst | 7 +++---- README.rst | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/QuickStart.rst b/QuickStart.rst index f90bc30..16e8027 100644 --- a/QuickStart.rst +++ b/QuickStart.rst @@ -129,10 +129,9 @@ installing additional docutils__ module:: pip install docutils -Notice that at the time of this writing Python 3 is not yet officially -supported. See the aforementioned `installation instructions`_ for information -about an unofficial Python 3 port and the latest status of Python 3 support in -general. +Notice that Robot Framework 3.0 is the first Robot Framework version to support +Python 3. See the aforementioned `installation instructions`_ for information +about Python 2 vs Python 3. .. _`Robot Framework installation instructions`: https://github.com/robotframework/robotframework/blob/master/INSTALL.rst diff --git a/README.rst b/README.rst index ea89610..2d5738b 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,8 @@ through it and look at the examples, but you can also use the guide as an executable demo. The guide itself is in ``_ file. It replaces the old version -still available on the `old project pages`__. +still available on the `old project pages`__. Robot Framework 3.0 introduced +python 3 support. This guide executes under Python 2.7, 3.3, and newer. Copyright © Nokia Solutions and Networks. Licensed under the `Creative Commons Attribution 3.0 Unported`__ license.