def getlist(self, name, fce=uni): """Returns list of variable values for key or empty list. Arguments: fce - function which processed value, str is default. """ val = CgiFieldStorage.getlist(self, name) return map(fce, val)
def get_cgi_parameter_str(form: cgi.FieldStorage, key: str, default: str = None) -> str: """ Extracts a string parameter from a CGI form. Note: ``key`` is CASE-SENSITIVE. """ paramlist = form.getlist(key) if len(paramlist) == 0: return default return paramlist[0]
def getlist(self, key: str, default: List = None, fce: Callable = str): """Returns list of variable values for key or empty list. Arguments: key : str key name default : list List of values when key was not sent. fce : convertor (str) Function or class which processed value. """ # pylint: disable=arguments-differ if key in self: val = CgiFieldStorage.getlist(self, key) else: val = default or [] for item in val: yield fce(item)
def do_POST(self): form = FieldStorage(fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD': 'POST'}) if 'sel1' in form: items = str(form.getlist('sel1')) else: items = 'no-item' # res = form['textfield'].value res = 'Select:' + str(items) self.send_response(200) self.end_headers() html = next.format( # message='you typed: ' + res, message=res, data=form) self.wfile.write(html.encode('utf-8')) return
def _process_multipartform(environ): """ Read ``multipart/form-data`` using ``FieldStorage``, return a dictionary of form data and set ``tiddlyweb.input_files`` to a list of available files. """ posted_data = {} try: field_storage = FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=True) except ValueError as exc: raise HTTP400('Invalid post, bad form: %s' % exc) for key in field_storage.keys(): if (hasattr(field_storage[key], 'filename') and field_storage[key].filename): environ['tiddlyweb.input_files'].append( field_storage[key]) else: posted_data[key] = field_storage.getlist(key) return posted_data
def _process_multipartform(environ): """ Read ``multipart/form-data`` using ``FieldStorage``, return a dictionary of form data and set ``tiddlyweb.input_files`` to a list of available files. """ posted_data = {} try: field_storage = FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=True) except ValueError as exc: raise HTTP400('Invalid post, bad form: %s' % exc) for key in field_storage.keys(): if (hasattr(field_storage[key], 'filename') and field_storage[key].filename): environ['tiddlyweb.input_files'].append(field_storage[key]) else: posted_data[key] = field_storage.getlist(key) return posted_data
#!/usr/local/bin/python3 from cgi import FieldStorage from cgitb import enable enable() print('Content-Type: text/html') print() form_data = FieldStorage() fruit_list = form_data.getlist('fruit') fruit_dict = { 'apples': 1.59, 'bananas': 1.25, 'jujubes': 27.81, 'rambutans': 20.84 } outcome = '' try: total = 0 for fruit in fruit_list: if fruit_list.count(fruit) == 1: total += fruit_dict[fruit] if total != 0: outcome = '%.2f' % (total) else: outcome = 'Error! Please select at least one fruit' except KeyError: outcome = 'Error! That\'s not a valid option'
def get_cgi_parameter_list(form: cgi.FieldStorage, key: str) -> List[str]: """ Extracts a list of values, all with the same key, from a CGI form. """ return form.getlist(key)
from cgitb import enable enable() from cgi import FieldStorage, escape print('Content-type: text/html') print() form_data = FieldStorage() STUDY = form_data.getfirst('study') SUBSTUDY = form_data.getfirst('substudy') CA_INPUTFILE = form_data.getfirst('inputfile') SEQ_TYPE = form_data.getfirst('seq') TRIMMED = form_data.getlist('trim') ADAPTOR = form_data.getfirst('adaptor') RRNA_INDEXES_LOCATION = form_data.getfirst('genind') GENOME_INDEXES_LOCATION = form_data.getlist('genfa') RNASE_SCRIPT = form_data.getfirst('rpscr') RNASE_OFFSET = form_data.getlist('offset') CHROM_SIZES = form_data.getlist('chromsize') if len(form_data) != 0: # if SEQ_TYPE != '' AND TRIMMED != '' AND ADAPTOR != ''AND RRNA_INDEXES_LOCATION != '' AND GENOME_INDEXES_LOCATION != '' AND RNASE_SCRIPT != '' AND RNASE_OFFSET!= '' AND CHROM_SIZES != '': myfile = open('CONFIG_FILE', 'w') myfile.write('#the root directory for the study') myfile.write("\n") if SEQ_TYPE == 'Ribo': myfile.write('BASE_DIR=/home/DATA/GWIPS_viz/Ribo_seq') elif SEQ_TYPE == 'mRNA_seq':
); ''') connection.commit() except: pass form_data = FieldStorage() import sys print('Content-Type: text/html') print() rec = '' game = form_data.getfirst('game', '') game = 'fifa' platform = form_data.getfirst('platform', '') shop = form_data.getlist('shop') if platform and platform != 'any' and platform != 'None': game += ' ' + platform Any = 'checked="checked"' wii = '' ds = '' switch = '' pc = '' ps4 = '' ps3 = '' ps2 = '' ps1 = '' xboxOne = '' xbox360 = ''
if __name__ == "__main__": form = FieldStorage() row = form["row"].value col = form["col"].value val = form["val"].value agg = form["agg"].value if "fil" in form: # determine the filter and its options fil = form["fil"].value if "min" in form: filOptions = [form["min"].value, form["max"].value] elif "opt" in form: filOptions = form.getlist("opt") else: filOptions = [] rows, cols, data = parse_data("../RawData/Data.csv", row, col, val, fil, filOptions) else: # no filter rows, cols, data = parse_data("../RawData/Data.csv", row, col, val) # generate Highcharts options options = { "chart": { "type": "heatmap", "height": 250 * log(len(rows)) }, #dynamic height respect to number of rows "title": {
from io import BytesIO from PIL import Image import tempfile from nj import * from cgi import FieldStorage, escape os.environ['http_proxy']="http://4c.ucc.ie:80" os.environ['https_proxy']="http://4c.ucc.ie:80" check = "true" mosaicnum = [20,30,40,50,60] result = ["true","false"] form_data = FieldStorage() photos = int(escape(form_data.getfirst("photos","").strip())) tags = form_data.getlist("tags") premade = escape(form_data.getfirst('premade','').strip()) opacity = escape(form_data.getfirst('opacity','').strip()) if int(opacity) < 0 or int(opacity) > 10: check = "false" if photos not in mosaicnum: check = "false" if premade not in result: check = "false" cookie = SimpleCookie() http_cookie_header = environ.get("HTTP_COOKIE") if http_cookie_header: cookie.load(http_cookie_header) if "token" in cookie: token = cookie["token"].value
connection = db.connect('localhost', 'kpp1', 'mah9eiQu', '2021_kpp1') cursor = connection.cursor(db.cursors.DictCursor) output = """ <p>Reset all values to default in my database</p> <form method="get" action="reset.py"> <label for="accept">I accept so go ahead</label> <input type="checkbox" value="accept" name="reset" id="accept"/> <input type="submit" value="Reset"/> </form> """ form_data = FieldStorage() reset_input = form_data.getlist('reset') remove_input = form_data.getlist('remove') if len(form_data) != 0: if (len(reset_input) > 0): commands = [ """drop table if exists runner;""", """ create table runner ( username varchar(100) not null, pw varchar(64), high_score int, curr_balance int, armour int,