Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python_3 #11

Open
wants to merge 5 commits into
base: python_3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion helper_functions.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 11 additions & 11 deletions post.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..'

Expand All @@ -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..'

Expand All @@ -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..'

Expand Down Expand Up @@ -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..'

Expand All @@ -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..'

Expand All @@ -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..'

Expand All @@ -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..'

Expand Down Expand Up @@ -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)
14 changes: 7 additions & 7 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..'

Expand Down Expand Up @@ -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..'

Expand All @@ -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..'

Expand All @@ -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)
26 changes: 13 additions & 13 deletions user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib
import urllib.request, urllib.parse, urllib.error
import hashlib
import re
import datetime
Expand Down Expand Up @@ -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..'

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -81,15 +81,15 @@ 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):
self.response['error'] = None
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
Expand All @@ -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..'
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)