#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from flask import Flask
from timeseries import timeseriesAPI
from upload import uploadAPI
import sys


app = Flask(__name__)
app.config["MAX_CONTENT_LENGTH"] = 120 * 1024 * 1024 # 120 MB
app.debug = False

app.register_blueprint(timeseriesAPI, url_prefix="/timeseries")
app.register_blueprint(uploadAPI, url_prefix="/upload")


if __name__ == "__main__":
	acceptAllHosts = False
	for arg in sys.argv:
		if arg == "--acceptAllHosts":
			acceptAllHosts = True
			break
	
	app.run(host="0.0.0.0" if acceptAllHosts else "127.0.0.1", port=3336, threaded=True, use_debugger=False, use_reloader=False)
Пример #2
0
import os
import StringIO
from PIL import Image
from werkzeug import secure_filename
from scipy.misc import imread, imresize
from caption_generator import generate_captions
from flask import Flask, request, render_template


UPLOAD_FOLDER = "/tmp/"
ALLOWED_IMAGE_EXTENSIONS = {"png", "bmp", "jpg", "jpe", "jpeg", "gif"}


app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
app.config["MAX_CONTENT_LENGTH"] = 3 * 1024 * 1024
app.config["SESSION_TYPE"] = "filesystem"
app.secret_key = "super_secret_key"


def allowed_file(filename):
    return "." in filename and filename.rsplit(".", 1)[1] in ALLOWED_IMAGE_EXTENSIONS


@app.route("/", methods=["GET", "POST"])
def index():
    try:
        if request.method == "POST":
            file = request.files["file"]
            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
Пример #3
0
import os
import config
from predict import predict
from flask import Flask, request, redirect, url_for
from werkzeug import secure_filename

try:
    from flask_debugtoolbar import DebugToolbarExtension
except:
    pass


app = Flask(__name__)
app.debug = True
app.config["MAX_CONTENT_LENGTH"] = config.max_content_length * 1024 * 1024
app.config["UPLOAD_FOLDER"] = config.upload_folder
app.config["SECRET_KEY"] = "test."
app.config["DEBUG_TB_PANELS"] = (
    "flask_debugtoolbar.panels.headers.HeaderDebugPanel",
    "flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel",
)
try:
    toolbar = DebugToolbarExtension(app)
except:
    pass


ALLOWED_EXTENSIONS = set(config.allowed_extensions)

Пример #4
0
from flask import Flask, session
from spm.blueprints import blueprints
from settings import *

app = Flask(__name__, static_folder=STATIC_FOLDER,
            template_folder=TEMPLATES_FOLDER)
app.secret_key = SECRET_KEY
app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH

@app.before_request
def before_request():
  app.jinja_env.globals["current_user_key"] = session.get("key", None)
  app.jinja_env.globals["current_user"] = session.get("email", None)

for blueprint, meta in blueprints:
  app.register_blueprint(blueprint, **meta)
Пример #5
0
import util, json
from flask import request, Flask, render_template, url_for, redirect, request, session
from werkzeug import secure_filename
import os

app = Flask(__name__)
app.secret_key = "vikingsrock"
app.config["MAX_CONTENT_LENGTH"] = 24 * 1024 * 1024  # max filesize 10mb
app.config["UPLOAD_FOLDER"] = "./static/uploads"
global ALLOWED_EXTENSIONS
ALLOWED_EXTENSIONS = set(["png", "jpg", "jpeg", "gif"])


@app.route("/addPic")
def addPic():
    return json.dumps(util.addPic(session["user"]))


@app.route("/checkPic")
def checkPic():
    return json.dumps(util.checkPic(session["user"]))


@app.route("/checkPic2")
def checkPic2():
    otherUser = request.args.get("otherUser", "")
    otherUser.strip()
    print otherUser
    return json.dumps(util.checkPic(otherUser))

Пример #6
0
        f.provide_automatic_options = False
        return update_wrapper(wrapped_function, f)

    return decorator


FILE_EXTS = ["jpeg", "jpg", "png", "gif", "webp", "webm"]
THUMBNAILABLE = ["jpeg", "jpg", "png", "gif"]
UPLOAD_FOLDER = "static/img/"
THUMBNAIL_FOLDER = "static/thumbnail/"

THUMBNAIL_MAX_AXIS_SIZE = 250

app = Flask(__name__)
app.config["MAX_CONTENT_LENGTH"] = 16777216

db = redis.StrictRedis(host="localhost", port=6379, db=0)


def is_valid_file(fn):
    return "." in fn and fn.split(".")[-1] in FILE_EXTS


def file_extension(fn):
    return fn.split(".")[-1]


def img(ifn):
    return url_for("static", filename="img/" + ifn)
Пример #7
0
    return json_data


# Upload new file
@app.route("/upload", methods=["GET", "POST"])
def upload_file():
    if request.method == "POST":
        file_ = request.files["file"]
        author = request.headers.get("x-webauth-ldap-cn")
        common_name = request.form.get("common_name")
        description = request.form.get("description")
        if file_:
            print(file_.__dict__)
            filename = secure_filename(file_.filename)
            filepath = os.path.join(json_config["upload_folder"], filename)
            file_hash = None
            if not os.path.exists(filepath):
                file_.save(filepath)
                file_hash = hash_file(filepath)
                return jsonify(add_file(file_hash, filename, common_name, description, author))
            else:
                return "ERROR FILE EXISTS!!!!", 409


with open(sys.argv[1]) as json_file:
    json_config = json.load(json_file)

app.config["UPLOAD_FOLDER"] = json_config["upload_folder"]
app.config["MAX_CONTENT_LENGTH"] = 10 * 1024 * 1024  # 10 Megabytes
app.run(debug=json_config["debug"], port=json_config["port"])
Пример #8
0
        Stop the running Containernet instance regardless of data transmitted
        """
        list(GK.dcs.values())[0].net.stop()


def initialize_GK():
    global GK
    GK = Gatekeeper()


# create a single, global GK object
GK = None
initialize_GK()
# setup Flask
app = Flask(__name__)
app.config["MAX_CONTENT_LENGTH"] = 512 * 1024 * 1024  # 512 MB max upload
api = fr.Api(app)
# define endpoints
api.add_resource(Packages, "/packages")
api.add_resource(Instantiations, "/instantiations")
api.add_resource(Exit, "/emulator/exit")


# def initialize_GK():
#    global GK
#    GK = Gatekeeper()


def start_rest_api(host, port, datacenters=dict()):
    GK.dcs = datacenters
    # start the Flask server (not the best performance but ok for our use case)
Пример #9
0
    api.SetOutputName("outputName");
    api.Init(".","eng",tesseract.OEM_DEFAULT)
    api.SetPageSegMode(tesseract.PSM_AUTO)
    mImgFile = "./output/trialone.png"
    api.SetRectangle(100,100,700,100)
    result = tesseract.ProcessPagesFileStream(mImgFile,api)
    print "result(ProcessPagesFileStream)=",result 
    """


UPLOAD_FOLDER = "./uploads"
ALLOWED_EXTENSIONS = set(["png", "jpg", "jpeg"])

app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
app.config["MAX_CONTENT_LENGTH"] = 6 * 1224 * 1632


def allowed_file(filename):
    return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route("/processsubmitted", methods=["GET", "POST"])
def upload_file():
    print "upload method called"
    if request.method == "POST":
        print "upload method POST"
        file = request.files["file"]
        if file and allowed_file(file.filename):
            print "upload method", file.filename
            filename = file.filename  # secure_filename(file.filename)
Пример #10
0
import os
from flask import Flask, request, redirect, url_for
from werkzeug.utils import secure_filename
from werkzeug.wsgi import SharedDataMiddleware
from retask.queue import Queue
from retask.task import Task


UPLOAD_FOLDER = "./uploads"
ALLOWED_EXTENSIONS = set(["log", "txt"])

APP = Flask(__name__)
APP.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
APP.add_url_rule("/uploads/<filename>", "uploaded_file", build_only=True)
APP.wsgi_app = SharedDataMiddleware(APP.wsgi_app, {"/uploads": APP.config["UPLOAD_FOLDER"]})
APP.config["MAX_CONTENT_LENGTH"] = 4 * 1024 * 1024


def allowed_file(filename):
    return "." in filename and filename.rsplit(".", 1)[1] in ALLOWED_EXTENSIONS


@APP.route("/", methods=["GET", "POST"])
def upload_file():
    if request.method == "POST":
        file = request.files["file"]
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(APP.config["UPLOAD_FOLDER"], filename))
            # Now add the information in the queue for processing
            t = Task({"filename": filename})
Пример #11
0
from redis import Redis

from fileutils import *
from converter import RegexConverter
from template import render
from constants import *

# Global Variables
MB_UPLOAD_LIMIT = 512
count = 0

# Flask Configuration
app = Flask(__name__)
app.url_map.converters["regex"] = RegexConverter
app.config["UPLOAD_FOLDER"] = PATH_DATASTORE
app.config["MAX_CONTENT_LENGTH"] = MB_UPLOAD_LIMIT * 1024 * 1024
app.secret_key = "8s9fs9fs09dfi9324s"

r_server = Redis("localhost")

# Routes ------------------------------------------------------------------
@app.route("/")
def route_root():
    files = []
    update_reset_time()

    # set uuid in session
    if not "session_id" in session:
        session["session_id"] = str(uuid.uuid1())

    id = session.get("session_id")
Пример #12
0
# Amazon AWS library
import boto

# Python Image Library
import StringIO


# --------- Config ----------------------------------------------------

app = Flask(__name__)  # create our flask app
app.debug = True
app.secret_key = os.environ.get(
    "SECRET_KEY"
)  # put SECRET_KEY variable inside .env file with a random string of alphanumeric characters
app.config["CSRF_ENABLED"] = False
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024  # 16 megabyte file upload

# Flask BCrypt will be used to salt the user password
flask_bcrypt = Bcrypt(app)

# --------- Database Connection ----------------------------------------------------


# MongoDB connection to MongoLab's database
# uses .env file to get connection string
# using a remote db get connection string from heroku config
# 	using a local mongodb put this in .env
#   MONGOLAB_URI=mongodb://localhost:27017/dwdfall2012
mongoengine.connect("userdemo", host=os.environ.get("MONGOLAB_URI"))
app.logger.debug("Connecting to MongoLabs")
Пример #13
0
"""
shared.py
~~~~~~

Shared contains the variables that are shared with many modules.

:copyright: (c) 2012 by Leonardo Zizzamia
:license: BSD (See LICENSE for details)
"""
# Imports outside Bombolone
from flask import Flask
from pymongo import Connection

# Imports inside Bombolone
from config import PORT_DATABASE, DATABASE

# Create application and configuration
app = Flask(__name__)
app.config.from_pyfile("config.py")
app.config.from_envvar("FLASKR_SETTINGS", silent=True)
app.config["MAX_CONTENT_LENGTH"] = 10 * 1024 * 1024  # 10 Mb Max Upload

# Create db - The first step when working with PyMongo is to create
# a Connection to the running mongod instance.
if PORT_DATABASE:
    connection = Connection(port=PORT_DATABASE)
else:
    connection = Connection()
db = connection[DATABASE]
app.test_request_context().push()