Exemplo n.º 1
0
def upload_post_processing():
	file = request.files.data.filename
	# validate file is image format
	if mimetypes.guess_type(file)[0].split('/')[0] != 'image':
		# delete non-image file types
		BlobInfo.gql("WHERE filename = :fname", fname=file).get().delete()
		return template('upload_error.html')
	
	response.set_cookie('img', file, path='/')
	redirect('/upload_success')
Exemplo n.º 2
0
def get_image(image):
	"""
	set header content type. 
	query blobstore, filter on filename, and execute query -> get BlobInfo
	open BlobReader with BlobInfo keyand read data -> return raw data
	"""
	#TODO: consider some kind of validation of file type and content?
	blob_info = BlobInfo.gql("WHERE filename = :fname", fname=image).get()
	response.content_type = blob_info.content_type
	return blobstore.BlobReader(blob_info).read()
Exemplo n.º 3
0
def filter(filename, chrm, start, end, filters):
    out = []

    indexname = "%s.index.%s.json" % (filename, chrm)
    log("attempting to load from m cache")
    index = memcache.get(indexname)
    if index is None:
        log("mcache loading failed, loading from blobstore")
        blob = BlobInfo.gql("where filename = '%s'" % (indexname)).get()
        if not blob is None:
            log("mcache loading failed, parseing from json")
            index = json.load(blob.open())
            log("adding to memcache")
            try:
                if not memcache.add(indexname, index):
                    logging.error("Memcache set failed.")
            except ValueError:
                logging.info("Memcache value error.")

    if not index is None:
        leftbound = bisect_left(index, start)
        rightbound = bisect_right(index, end)
        for edge in index[leftbound:rightbound]:
            #if edge < start:
            #	continue
            #if edge["Pos1"] > end:
            #	break

            includeme = False
            if filters != False:
                for filter in filters:
                    if edge["Type"] == filter["type"] and int(
                            edge["Score"]) >= int(filter["minscore"]):
                        includeme = True
                        break
            else:
                includeme = True
            if includeme == True:
                out.append(edge)
    return out
Exemplo n.º 4
0
def filter(filename, chrm, start, end, filters):
    out = []

    indexname = "%s.index.%s.json" % (filename, chrm)
    log("attempting to load from m cache")
    index = memcache.get(indexname)
    if index is None:
        log("mcache loading failed, loading from blobstore")
        blob = BlobInfo.gql("where filename = '%s'" % (indexname)).get()
        if not blob is None:
            log("mcache loading failed, parseing from json")
            index = json.load(blob.open())
            log("adding to memcache")
            try:
                if not memcache.add(indexname, index):
                    logging.error("Memcache set failed.")
            except ValueError:
                logging.info("Memcache value error.")

    if not index is None:
        leftbound = bisect_left(index, start)
        rightbound = bisect_right(index, end)
        for edge in index[leftbound:rightbound]:
            # if edge < start:
            # 	continue
            # if edge["Pos1"] > end:
            # 	break

            includeme = False
            if filters != False:
                for filter in filters:
                    if edge["Type"] == filter["type"] and int(edge["Score"]) >= int(filter["minscore"]):
                        includeme = True
                        break
            else:
                includeme = True
            if includeme == True:
                out.append(edge)
    return out