From 076684110d70efb83c4bc19175effd3beeac191c Mon Sep 17 00:00:00 2001 From: garni Date: Sun, 5 Oct 2014 10:52:06 +0330 Subject: [PATCH 1/5] needed change 2to3 python --- post.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/post.py b/post.py index c836148..44ea5f5 100644 --- a/post.py +++ b/post.py @@ -42,7 +42,7 @@ def get_posts(self, limit, skip, tag=None, search=None): 'tags': post['tags'], 'author': post['author'], 'comments': post['comments']}) - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Posts not found..' @@ -53,7 +53,7 @@ def get_post_by_permalink(self, permalink): try: self.response['data'] = self.collection.find_one( {'permalink': permalink}) - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Post not found..' @@ -72,7 +72,7 @@ def get_post_by_id(self, post_id): self.response['data']['tags']) if 'preview' not in self.response['data']: self.response['data']['preview'] = '' - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Post not found..' @@ -105,7 +105,7 @@ def get_tags(self): else: self.response['data'] = [] - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Get tags error..' @@ -115,7 +115,7 @@ def create_new_post(self, post_data): self.response['error'] = None try: self.response['data'] = self.collection.insert(post_data) - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Adding post error..' @@ -130,7 +130,7 @@ def edit_post(self, post_id, post_data): self.collection.update( {'_id': ObjectId(post_id)}, {"$set": post_data}, upsert=False) self.response['data'] = True - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Post update error..' @@ -143,7 +143,7 @@ def delete_post(self, post_id): self.response['data'] = True else: self.response['data'] = False - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Deleting post error..' @@ -179,7 +179,7 @@ def print_debug_info(msg, show=False): 'line': sys.exc_info()[2].tb_lineno, 'details': str(msg)} - print error_color - print '\n\n---\nError type: %s in file: %s on line: %s\nError details: %s\n---\n\n'\ - % (error['type'], error['file'], error['line'], error['details']) - print error_end + print(error_color) + print('\n\n---\nError type: %s in file: %s on line: %s\nError details: %s\n---\n\n'\ + % (error['type'], error['file'], error['line'], error['details'])) + print(error_end) From 4e1140800a79cf2150a595752c4210e392f7a448 Mon Sep 17 00:00:00 2001 From: garni Date: Sun, 5 Oct 2014 10:57:48 +0330 Subject: [PATCH 2/5] change think in urlparse in python3.3 --- helper_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper_functions.py b/helper_functions.py index 1f33768..23a2223 100644 --- a/helper_functions.py +++ b/helper_functions.py @@ -1,7 +1,7 @@ import re import string import random -from urlparse import urljoin +from urllib.parse import urljoin from flask import request, url_for, session, flash, redirect from functools import wraps From a90d44c0844ed285e3239ce01d967df1dbeafb5f Mon Sep 17 00:00:00 2001 From: garni Date: Sun, 5 Oct 2014 10:59:42 +0330 Subject: [PATCH 3/5] 2to3 for user.py --- user.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/user.py b/user.py index 9cf3001..5db3c2e 100644 --- a/user.py +++ b/user.py @@ -1,4 +1,4 @@ -import urllib +import urllib.request, urllib.parse, urllib.error import hashlib import re import datetime @@ -29,7 +29,7 @@ def login(self, username, password): else: self.response['error'] = 'User not found..' - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'System error..' @@ -60,7 +60,7 @@ def get_users(self): self.response['data'].append({'id': user['_id'], 'email': user['email'], 'date': user['date']}) - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Users not found..' return self.response @@ -72,7 +72,7 @@ def get_user(self, user_id): gravatar_url = self.get_gravatar_link(user.get('email', '')) self.response['data'] = user self.response['data']['gravatar_url'] = gravatar_url - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'User not found..' return self.response @@ -81,7 +81,7 @@ def get_user(self, user_id): def get_gravatar_link(email=''): gravatar_url = "http://www.gravatar.com/avatar/" + \ hashlib.md5(email.lower()).hexdigest() + "?" - gravatar_url += urllib.urlencode({'d': 'retro'}) + gravatar_url += urllib.parse.urlencode({'d': 'retro'}) return gravatar_url def delete_user(self, user_id): @@ -89,7 +89,7 @@ def delete_user(self, user_id): try: self.collection.remove({'_id': user_id}) self.response['data'] = True - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Delete user error..' return self.response @@ -115,7 +115,7 @@ def save_user(self, user_data): self.collection.update( {'_id': user_data['_id']}, {'$set': record}, upsert=False, multi=False) self.response['data'] = True - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response[ 'error'] = 'Update user error..' @@ -132,7 +132,7 @@ def save_user(self, user_data): self.collection.update( {'_id': user_data['_id']}, {'$set': {'email': user_data['email']}}, upsert=False, multi=False) self.response['data'] = True - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Update user error..' else: @@ -151,7 +151,7 @@ def save_user(self, user_data): try: self.collection.insert(record, safe=True) self.response['data'] = True - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Create user user error..' else: @@ -176,7 +176,7 @@ def print_debug_info(msg, show=False): 'line': sys.exc_info()[2].tb_lineno, 'details': str(msg)} - print error_color - print '\n\n---\nError type: %s in file: %s on line: %s\nError details: %s\n---\n\n'\ - % (error['type'], error['file'], error['line'], error['details']) - print error_end + print(error_color) + print('\n\n---\nError type: %s in file: %s on line: %s\nError details: %s\n---\n\n'\ + % (error['type'], error['file'], error['line'], error['details'])) + print(error_end) From b10fe8d3ec7474eb4cce83aa380c22bacd1abab4 Mon Sep 17 00:00:00 2001 From: garni Date: Sun, 5 Oct 2014 11:01:02 +0330 Subject: [PATCH 4/5] 2to3 think for settings.py --- settings.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/settings.py b/settings.py index 1a76d69..953c550 100644 --- a/settings.py +++ b/settings.py @@ -28,7 +28,7 @@ def get_config(self): self.config['BLOG_DESCRIPTION'] = cursor.get( 'description', self.config['BLOG_DESCRIPTION']) return self.config - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'System error..' @@ -84,7 +84,7 @@ def install(self, blog_data, user_data): self.config['USERS_COLLECTION'].drop() self.collection.drop() return self.response - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Installation error..' @@ -96,7 +96,7 @@ def update_settings(self, data): {'_id': cursor['_id']}, {'$set': data}, upsert=False, multi=False) self.response['data'] = True return self.response - except Exception, e: + except Exception as e: self.print_debug_info(e, self.debug_mode) self.response['error'] = 'Settings update error..' @@ -114,7 +114,7 @@ def print_debug_info(msg, show=False): 'line': sys.exc_info()[2].tb_lineno, 'details': str(msg)} - print error_color - print '\n\n---\nError type: %s in file: %s on line: %s\nError details: %s\n---\n\n'\ - % (error['type'], error['file'], error['line'], error['details']) - print error_end + print(error_color) + print('\n\n---\nError type: %s in file: %s on line: %s\nError details: %s\n---\n\n'\ + % (error['type'], error['file'], error['line'], error['details'])) + print(error_end) From 65ad32cf335ac0967b25e2b98bc77a0b9cedf800 Mon Sep 17 00:00:00 2001 From: garni Date: Sun, 5 Oct 2014 13:26:18 +0330 Subject: [PATCH 5/5] change in readme for python3 user --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6c8128b..00ca059 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,10 @@ pass:demo `cd flask-blog` +for python3 user + +`git checkout python3.3` + `virtualenv --no-site-packages ./env` `source ./env/bin/activate`