def search(): """ Searches student """ # Connect to database conn = connect_db(database) conn.row_factory = dict_factory if request.method == "POST": print("SEARCH POST") # Get search query query = str(request.form.get("search_searchbar")) column = request.form.get("search_class") # Query databse records = search_student(conn, query, column) # Get headers from databse headers = get_headers(conn) # Number of casts showtime = ("Saturday", "Sunday") # Close database connection close_connection(conn) return render_template("index.html", session = session, headers = headers, records = records, showtime = showtime)
def get_dict(*keys, **extras): """Returns request dict of given keys.""" _keys = ('url', 'args', 'form', 'data', 'origin', 'headers', 'files', 'json', 'method') assert all(map(_keys.__contains__, keys)) data = request.data form = semiflatten(request.form) try: _json = json.loads(data.decode('utf-8')) except (ValueError, TypeError): _json = None d = dict( url=get_url(request), args=semiflatten(request.args), form=form, data=json_safe(data), origin=request.headers.get('X-Forwarded-For', request.remote_addr), headers=get_headers(), files=get_files(), json=_json, method=request.method, ) out_d = dict() for key in keys: out_d[key] = d.get(key) out_d.update(extras) return out_d
def image(): """Returns a simple image of the type suggest by the Accept header.""" headers = get_headers() if 'accept' not in headers: return image_png() # Default media type to png accept = headers['accept'].lower() if 'image/webp' in accept: return image_webp() elif 'image/svg+xml' in accept: return image_svg() elif 'image/jpeg' in accept: return image_jpeg() elif 'image/png' in accept or 'image/*' in accept: return image_png() else: return status_code(406) # Unsupported media type
def image(): """Returns a simple image of the type suggest by the Accept header.""" headers = get_headers() print headers if "accept" not in headers: return redirect('/image/png') # Default media type to png accept = headers['accept'].lower() print accept # image_type = ['image/webp', 'image/svg+xml', 'image/jpeg', 'image/png'] if 'image/webp' in accept: return redirect('/image/webp') elif 'image/svg+xml' in accept: return redirect('/image/svg') elif 'image/jpeg' in accept: return redirect('/image/jpeg') elif 'image/png' in accept: return redirect('/image/png') else: return status_code(406) # Unsupported media type
def index(): """Show overview of all students in a table""" print("INDEX GET") # Connect to database conn = connect_db(database) conn.row_factory = dict_factory # Establish number of casts and group names if not yet found in database showtime = ("Saturday", "Sunday") session["student_classes"] = ["Junior", "Oranje", "Paars", "Blauw", "PG", "Demo", "Vakklas"] # Select all student data headers = get_headers(conn) records = student_overview(conn) # If no data is present if not records: return render_template("index.html", session = session, showtime = showtime, headers = headers) # Change "None" to "-" for readability for record in records: for value in record: if record[value] == None: record[value] = "-" #Close db connection close_connection(conn) return render_template("index.html", session = session, records = records, headers = headers, showtime = showtime)
def view_useragent(): headers = get_headers() return jsonify({'user-agent': headers['user-agent']})
def view_user_agent(): '''Return User-Agent''' headers = get_headers() return jsonify({"User-Agent": headers['User-Agent']})
def view_user_agent(): """Returns User-Agent""" headers = get_headers() return jsonify({'user-agent': headers['user-agent']})
def range_request(numbytes): """Streams n random bytes generated with given seed, at given chunk size per packet.""" if numbytes <= 0 or numbytes > (100 * 1024): response = Response(headers={ 'ETag': 'range%d' % numbytes, 'Accept-Ranges': 'bytes' }) response.status_code = 404 response.data = 'number of bytes must be in the range (0, 10240]' return response params = CaseInsensitiveDict(request.args.items()) if 'chunk_size' in params: chunk_size = max(1, int(params['chunk_size'])) else: chunk_size = 10 * 1024 duration = float(params.get('duration', 0)) pause_per_byte = duration / numbytes request_headers = get_headers() first_byte_pos, last_byte_pos = get_request_range(request_headers, numbytes) if first_byte_pos > last_byte_pos or first_byte_pos not in xrange( 0, numbytes) or last_byte_pos not in xrange(0, numbytes): response = Response( headers={ 'ETag': 'range%d' % numbytes, 'Accept-Ranges': 'bytes', 'Content-Range': 'bytes */%d' % numbytes }) response.status_code = 416 return response def generate_bytes(): chunks = bytearray() for i in xrange(first_byte_pos, last_byte_pos + 1): # We don't want the resource to change across requests, so we need # to use a predictable data generation function chunks.append(ord('a') + (i % 26)) if len(chunks) == chunk_size: yield (bytes(chunks)) time.sleep(pause_per_byte * chunk_size) chunks = bytearray() if chunks: time.sleep(pause_per_byte * len(chunks)) yield (bytes(chunks)) content_range = 'bytes %d-%d/%d' % (first_byte_pos, last_byte_pos, numbytes) response_headers = { 'Content-Type': 'application/octet-stream', 'ETag': 'range%d' % numbytes, 'Accept-Ranges': 'bytes', 'Content-Range': content_range } response = Response(generate_bytes(), headers=response_headers) if (first_byte_pos == 0) and (last_byte_pos == (numbytes - 1)): response.status_code = 200 else: response.status_code = 206 return response