예제 #1
0
def main():
    fs = cgi.FieldStorage()
    aggr=fs.getvalue("aggr")
    chiave=fs.getvalue("key")
    confronto=fs.getvalue("comp")
    valore=fs.getvalue("value")
    if(aggr=="materne"):
        source=smaterne
    elif(aggr=="medici"):
        source=medici
    else:
        error.errhttp("404")
    if(not chiave) and (not confronto) and (not valore) and not error.testenviron(os.environ, mimexml):
        xml=os.path.splitext(source)[0]+".xml"
        file=open(xml, "r")
        print("Content-type: application/xml; charset=UTF-8\n")
        content=file.read()
        print content
        return
    """
    questa parte serve per controllare che json in questo caso sia accettato dal descrittore. tuttavia se la abilitiamo adesso, siccome il browser non accetta json non va...
    la lascio commentata finche non iniziamo con i descrittori"""
    if(error.testenviron(os.environ, mimecsv)):
        error.errhttp("406")
        return
    if(not chiave) and (not confronto) and (not valore):
        file=open(source, "r")
        print("Content-type: text/csv; charset=UTF-8\n")
        content=file.read()
        print content
    else:
        if(not chiave) or (not confronto) or (not valore):
            error.errhttp("406")
        else:
            chiave=chiave.lower().decode(uencoding)
            confronto=confronto.lower().decode(uencoding)
            valore=valore.lower().decode(uencoding)
            if(confronto=="eq"):
                filtraEQ(chiave, valore, False, source)
            elif(confronto=="neq"):
                filtraEQ(chiave,valore,True, source)
            elif(confronto=="contains"):
                filtraCONTAINS(chiave,valore, False, source)
            elif(confronto=="ncontains"):
                filtraCONTAINS(chiave,valore,True, source)
            elif(confronto=="gt"):
                filtraGT(chiave,valore,True, False, source)
            elif(confronto=="lt"):
                filtraGT(chiave,valore,False,False,source)
            elif(confronto=="ge"):
                filtraGT(chiave,valore,True,True, source)
            elif(confronto=="le"):
                filtraGT(chiave,valore,False,True, source)
            else:
                error.errcode("406")
예제 #2
0
파일: farm.py 프로젝트: ashmikuz/Techweb12
def main():
    fs = cgi.FieldStorage()
    chiave = fs.getvalue("key")
    confronto = fs.getvalue("comp")
    valore = fs.getvalue("value")
    if error.testenviron(os.environ, mimexml):
        return
    if (not chiave) and (not confronto) and (not valore):
        xml = open(farmacie, "r")
        print ("Content-type: application/xml; charset=UTF-8\n")
        content = xml.read()
        print content
    else:
        if (not chiave) or (not confronto) or (not valore):
            error.errhttp("406")
        else:
            chiave = chiave.lower().decode(uencoding)
            confronto = confronto.lower().decode(uencoding)
            valore = valore.lower().decode(uencoding)
            if confronto == "eq":
                filtraEQ(chiave, valore, False)
            elif confronto == "neq":
                filtraEQ(chiave, valore, True)
            elif confronto == "contains":
                filtraCONTAINS(chiave, valore, False)
            elif confronto == "ncontains":
                filtraCONTAINS(chiave, valore, True)
            elif confronto == "gt":
                filtraGT(chiave, valore, True, False)
            elif confronto == "lt":
                filtraGT(chiave, valore, False, False)
            elif confronto == "ge":
                filtraGT(chiave, valore, True, True)
            elif confronto == "le":
                filtraGT(chiave, valore, False, True)
            else:
                error.errhttp("406")