-
Notifications
You must be signed in to change notification settings - Fork 6
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
Moving to Python3 #247
Moving to Python3 #247
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.6" | ||
# command to install dependencies | ||
install: | ||
- npm i npm@latest -g | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from PIL import Image | ||
import os | ||
from werkzeug import FileStorage, secure_filename | ||
from StringIO import StringIO | ||
from io import BytesIO | ||
from flask import current_app | ||
from flask_uploads import (UploadSet, configure_uploads, | ||
IMAGES, UploadNotAllowed) | ||
|
@@ -25,17 +25,16 @@ def return_werkzeug_filestorage(request, filename): | |
if extension not in current_app.config['ALLOWED_EXTENSIONS']: | ||
raise UploadNotAllowed("Unsupported file format") | ||
new_filename = secure_filename(filename + '.' + extension) | ||
try: | ||
tempfile = StringIO(buf=request.content) | ||
except AttributeError: | ||
if hasattr(request.stream, 'getvalue'): | ||
tempfile = StringIO(buf=request.stream.getvalue()) | ||
elif hasattr(request.stream, 'read'): | ||
tempfile = StringIO(buf=request.stream.read()) | ||
if hasattr(request, 'content'): | ||
tempfile = BytesIO(request.content) | ||
elif hasattr(request, 'read'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this entire block could be better. We shouldn't be doing guesswork here. |
||
tempfile = BytesIO(request.read()) | ||
tempfile.name = new_filename | ||
filestorage = FileStorage(tempfile, | ||
filestorage = FileStorage( | ||
tempfile, | ||
filename=new_filename, | ||
content_type=request.headers['content-type']) | ||
content_type=request.headers['content-type'] | ||
) | ||
return filestorage | ||
|
||
|
||
|
@@ -49,7 +48,7 @@ def resize_image(requestfile, maxsize=(320, 240)): | |
img.thumbnail(maxsize, Image.ANTIALIAS) | ||
boximg = Image.new('RGBA', (img.size[0], img.size[1]), (255, 255, 255, 0)) | ||
boximg.paste(img, (0, 0)) | ||
savefile = StringIO() | ||
savefile = BytesIO() | ||
if fileext in ['jpg', 'jpeg']: | ||
savefile.name = secure_filename(".".join(requestfile.filename.split('.')[:-1]) + ".png") | ||
boximg.save(savefile, format="PNG") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ def channel_edit(channel): | |
if channel.userid == current_auth.user.userid: | ||
form.type.choices = [(1, CHANNEL_TYPE[1])] | ||
else: | ||
choices = CHANNEL_TYPE.items() | ||
choices = list(CHANNEL_TYPE.items()) # requires list() | ||
choices.pop(0) | ||
choices.pop(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment explaining why the first two items are being popped? |
||
form.type.choices = choices | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump to 3.7