Skip to content

Commit

Permalink
PEP8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Brandoff committed Nov 13, 2014
1 parent 048a524 commit f9f91c4
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions webcore/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def close_connection(exception):
get_webcore().cloud.close()


#Upload post method to save files into directory
@app.route("/api/upload",methods=['POST'])
# Upload post method to save files into directory
@app.route("/api/upload", methods=['POST'])
def upload():
"""Upload a file using cloud manager.
Expand All @@ -57,28 +57,32 @@ def upload():
"""
# Save the uploaded file into a temporary location.
token = request.form.get('token', None)
file = request.files['file']
filename = secure_filename(file.filename)
temp_name = os.path.join(app.config['TEMP_FOLDER'], filename)
token = request.form.get('token', None)
file = request.files['file']
filename = secure_filename(file.filename)
temp_name = os.path.join(app.config['TEMP_FOLDER'], filename)
file.save(temp_name)

try:
receipt = get_webcore().charge_upload(token, temp_name)
if receipt is None:
response = make_response(jsonify(error='balance-insufficient'), 402)
response = make_response(
jsonify(error='balance-insufficient'), 402)
else:
key = file_encryptor.convergence.encrypt_file_inline(temp_name, None)
key = file_encryptor.convergence.encrypt_file_inline(
temp_name, None)
result = get_webcore().cloud.upload(temp_name)

if not result:
# Should we issue a refund?
# get_webcore().refund(receipt)
response = make_response(jsonify(error='upload-error'), 500)
else:
response = make_response(jsonify(filehash=result, key=codecs.encode(key, 'hex_codec')), 201)
response = make_response(
jsonify(filehash=result, key=codecs.encode(key, 'hex_codec')), 201)

response.headers['Access-Control-Allow-Origin'] = 'http://localhost:8000'
response.headers[
'Access-Control-Allow-Origin'] = 'http://localhost:8000'
response.headers['Access-Control-Allow-Credentials'] = 'true'

return response
Expand All @@ -87,7 +91,7 @@ def upload():
os.remove(temp_name)


@app.route("/api/download/<filehash>",methods=['GET'])
@app.route("/api/download/<filehash>", methods=['GET'])
def download(filehash):
"""Download a file from cloud manager.
Expand All @@ -99,7 +103,7 @@ def download(filehash):
"""
cm = get_webcore().cloud

key = request.args.get('key', None)
key = request.args.get('key', None)
token = request.args.get('token', None)

if not cm.exists(filehash):
Expand All @@ -117,15 +121,15 @@ def download(filehash):

if key is None:
return send_file(full_path,
attachment_filename=os.path.basename(full_path),
as_attachment=True)
attachment_filename=os.path.basename(full_path),
as_attachment=True)
else:
decoded = codecs.decode(key, 'hex_codec')
return Response(
stream_with_context(
file_encryptor.convergence.decrypt_generator(full_path, decoded)),
mimetype="application/octet-stream",
headers={"Content-Disposition":"attachment;filename=" + os.path.basename(full_path) })
headers={"Content-Disposition": "attachment;filename=" + os.path.basename(full_path)})


@app.route("/api/find/<filehash>", methods=['GET'])
Expand All @@ -148,41 +152,41 @@ def status():
synchronization status and florincoin status.
"""
cm = get_webcore().cloud
cm = get_webcore().cloud
coin = get_webcore().coin

return jsonify({
"bandwidth": {
"total": {
"incoming": cm.total_incoming(),
"outgoing": cm.total_outgoing()
},
},
"current": {
"incoming": cm.current_incoming(),
"outgoing": cm.current_outgoing()
},
},
"limits": {
"incoming": settings.TRANSFER_MAX_INCOMING,
"outgoing": settings.TRANSFER_MAX_OUTGOING
}
},
}
},

"storage": {
"capacity": cm.capacity(),
"used": cm.used_space(),
"max_file_size": settings.STORAGE_FILE
},
},

"sync": {
"cloud_queue": cm.upload_queue_info(),
"blockchain_queue": cm.blockchain_queue_info()
},
},

"florincoin": {
"balance": coin.balance(),
"address": coin.address("incoming"),
"block": cm.last_known_block()
}
})
}
})

## Main
# Main

0 comments on commit f9f91c4

Please sign in to comment.