def analyse_chaine_affectation(self,chaine): champs=[] valeurs=[] lastchamp='' lastvalue='' lastvaluenum='' flagvalue=False openvalue=False for c in chaine: if flagvalue: if c in '0123456789.': lastvaluenum+=c if not openvalue: if c=='"' or c=="'": openvalue=c lastvalue+=c if c==',': v=lastvalue.strip() if v=='': valeurs.append(lastvaluenum) else: valeurs.append(v) lastvalue='' lastvaluenum='' flagvalue=False else: lastvalue+=c if openvalue==c: openvalue=False else: if c=='=': champs.append(lastchamp.strip()) lastchamp='' flagvalue=True else: lastchamp+=c v=lastvalue.strip() if v=='': valeurs.append(lastvaluenum) else: valeurs.append(v) """ self.log.debug("DEBUG analyse-chaine-affect") self.log.debug(chaine) self.log.debug(champs) self.log.debug(valeurs) self.log.debug("DEBUG FIN analyse-chaine-affect") """ val2=[] for v in valeurs: if type(v)==type(''): v=stou(v) val2.append(v) return (champs,val2)
def edit_page_form(self): _=self.datas._ if not check_edit(self.datas,self.socket): return inputslang=u'' name=name_from_path(self.path) urllangdefault=name for code in self.config.langues: l=tablangtrad[code][self.datas.my_session.langue] inputslang+=u"<br /><br />%s %s : <br />" % (_('Information en '),l) if self.id!=0: try: urllang=self.glob.objets[self.id]['names'][code] except: urllang='' inputslang+=u"""<div class="label">%s</div> : <input type="text" name="urlpage_%s" value="%s"/> <br />""" % (_('Identifiant pour url '), code, urllang ) textnav=self.get_propriete('textnav_%s' % code,'') if type(textnav)==type(''): textnav=stou(textnav) inputslang+=u"""<div class="label">%s</div> : <input type="text" name="textnav_%s" value="%s"/> <br />""" % (_('Text Navigation'),code,textnav ) titre=stou(self.get_propriete('titre_%s' % code,'')) inputslang+=u""" <div class="label">%s</div> : <input type="text" name="titrepage_%s" value="%s"/><br /> """ % ( _('Titre'),code,titre) template=u""" %s : <form action="%s/edit_page" method="POST" id="panneauform" > %s <div id="div_valid" class="invisible"> <input type="button" value="%s" onClick="document.forms.panneauform.submit();"> </div> </form> """ % (_('Editer les proprietes de la page'), self.path,inputslang,_('Valider')) self.socket.send_datas(template)
def requete(self,pool,commande,parametres): commande = py_to_apisql(commande) new_params=[] if type(parametres)==(type(())) or type(parametres)==(type([])): pass else: parametres = to_tuple(parametres) for p in parametres: if type(p)==type(""): new_params.append(stou(p)) else: new_params.append(p) parametres = to_tuple(new_params) queue=pool[0] queue.get() semaphores=pool[1] nb=len(semaphores) id_connection=self.check_free(semaphores,nb) semaphore=pool[1][id_connection] acces=pool[2][id_connection] connection=acces[0] cursor=acces[1] res=[] try: #self.log.debug('execute : %s /// %s' % (commande,parametres)) for row in cursor.execute(commande,parametres): res.append(row) #self.log.debug(res) # no commit with apsw ? #if not commande.upper().strip().startswith("SELECT"): # connection.commit() except Exception, err: err="""Requete : %s / Params : %s / Type : %s / Err : %s""" % ( commande,parametres,str(Exception),str(err)) self.log.traceback() self.log.err(err)
def niv_arbo_mov(glob,datas,niv,id,decal): page=glob.objets[id] lang=datas.my_session.langue url=page['path'].get(lang,'') pages=page['sous_pages'][lang] pathin=False if datas.objet_actu.path.find(url)!=-1: pathin=True tpl='' if niv>0: tpl+='<div class="arbo_move_indic">' if len(pages)==0 and pathin: tpl+='<div class="arbo_move_indic1">' if len(pages)>0 and pathin: tpl+='<div class="arbo_move_indic2">' if len(pages)==0 and not pathin: tpl+='<div class="arbo_move_indic3">' if len(pages)>0 and not pathin: tpl+='<div class="arbo_move_indic4">' tpl+='<div class="arbo_indic_over" onmouseover="arbo_ouvre_page(event);">' tpl+='<img src=/includes/images/interface/util/pixel.gif" width="20px" heigh="20px" />' tpl+='</div>' if pathin: inv='' else: inv=' invisible' tpl+='<div class="arbo_move_niv%s" id="arbo_menu__%s__%s">' % (inv,url.replace('/','__'),id) max=len(pages)+decal positionelem=0 for (idsub,textsub,pathsub,namesub) in pages: max2=0 tpl2='' if datas.objet_actu.path==pathsub: tpl+=u"""<div class="arbo_move_elem actu" id="arbo_move_elem_actu" onclick="javascript:go_move_page(event)" ><div class="arbo_move_elem_titre">%s</div></div>""" % stou(textsub) else: mouseover=' onmouseover="arbo_move_page(event,%s);" ' % positionelem if datas.objet_actu.path.find(pathsub)!=-1: tpl+='<div class="arbo_move_elem actif">' else: tpl+='<div class="arbo_move_elem inactif">' tpl+='<div class="arbo_move_over" %s >' % mouseover tpl+='<div class="arbo_move_elem_titre">%s</div>' % textsub tpl+='</div>' (max2,tpl2)=niv_arbo_mov(glob,datas,niv+1,idsub,decal) positionelem+=1 if max2>max: max=max2 tpl+=tpl2 tpl+='</div>' decal+=1 tpl+='</div>' if niv>0: tpl+='</div>' tpl+='</div>' return (max,tpl)
def handle(self): """ Handle a single HTTP request. GET et POST seulement """ self.command = None # recuperation de la ligne de requete. try: line = self.rfile.readline() except: self.err("error get requestline ") self.http_error(400,'No requestline') return False (ok,values)=split_requestline_http(line,self.protocol_version) if not ok: self.err(values[1]) self.http_error(values[0],values[1]) return False (self.command, self.path, self.request_version, self.keep_alive) = values #get headers with mimetools.Message RFC 2822 self.headers = mimetools.Message(self.rfile, 0) #check Connection keep-alive if self.keep_alive: conntype = self.headers.get('Connection', "") if conntype.lower() != 'keep-alive': self.keep_alive=False #get form if self.command=="POST": storage = cgi.FieldStorage( fp=self.rfile, headers=self.headers, environ={'REQUEST_METHOD':'POST', 'CONTENT_TYPE': self.headers['Content-Type'], } ) self.form = storage elif self.command=="GET": self.form = None #get path / query_string if self.path.find('?') != -1: self.path, self.query_string = self.path.split('?', 1) else: self.query_string = '' #unquote path try: self.path=urllib.unquote(self.path) except: self.dbg('error unquote path %s ' % self.path) self.path=format_path(self.path) #get args query_string self.args = dict(cgi.parse_qsl(self.query_string)) for k in self.args.keys(): self.args[k] = stou(self.args[k]) #get cookies self.cookies=None if 'cookie' in self.headers.keys() or 'Cookie' in self.headers.keys() : self.cookies=Cookie.SimpleCookie() self.cookies.load(self.headers['Cookie']) if not self.check_url(): self.err("error get requestline ") self.http_error(400,'URL incorrecte %s ' % self.path) return False return True
def affiche_niveau(self,styles,id_obj=0,niv=1,text='',path='',pere_actif=True): if type(text)==type(""): text=stou(text) if len(styles)<niv: print 'niveau trop grand' return lang=self.datas.my_session.langue infos=self.glob.objets[id_obj]['sous_pages'][lang] actif="" new_pere_actif=False if (self.datas.objet_actu.path+'/').find(self.glob.get_path_by_id(id_obj,lang=lang)+'/')!=-1: actif=" actif" new_pere_actif=True my_style=styles[niv-1] if type(my_style)==type(()): if pere_actif: my_style=my_style[0] else: my_style=my_style[1] if my_style=='popup': my_style='element' sub_style=None if len(styles)>niv and len(infos)>0: sub_style=styles[niv] if type(sub_style)==type(()): if new_pere_actif: sub_style=sub_style[0] else: sub_style=sub_style[1] if my_style==None: #cas impossible ? ne sert plus ? if actif!='': if sub_style: for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) return if my_style.find('conteneur')!=-1: #conteneur premier niveau. cl_c='class="nav_conteneur_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas('<ul %s>' % (cl_c)) if sub_style: for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) self.socket.send_datas('</ul>') return path_j=path.replace('/','_') if my_style=='element': cl_e='class="nav_element_%s_%s%s"' % (self.name,niv,actif) js_e="""onclick="document.location.href='%s';" """ % (path) self.socket.send_datas('<li %s %s>' % (cl_e,js_e)) if sub_style and sub_style=='popup': cl_p='class="nav_popup_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas("""<div %s>""" % cl_p ) self.socket.send_datas("""<ul>""") for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) self.socket.send_datas("""</ul>""") self.socket.send_datas(text) if sub_style: if sub_style=='popup': self.socket.send_datas("""</div>""") else: cl_c='class="nav_conteneur_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas("""<ul %s>""" % cl_c ) for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) self.socket.send_datas("""</ul>""") self.socket.send_datas('</li>') if my_style=='element-list': cl_e='class="nav_element_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas('<li %s >' % cl_e) if sub_style and sub_style=='popup': cl_p='class="nav_popup_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas("""<div %s>""" % cl_p ) self.socket.send_datas("""<ul>""") for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) self.socket.send_datas("""</ul>""") self.socket.send_datas("""</div>""") js_e="""onclick="document.location.href='%s';" """% (path) self.socket.send_datas(u"""<div class="link" %s>%s</div>""" % (js_e,text)) self.socket.send_datas('</li>') if sub_style and sub_style!='popup': for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) if my_style=='element-open': cl_e='class="nav_element_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas('<li %s>' % cl_e) idul='nav_contoleur_opener__'+path.replace('/','_') if new_pere_actif==True: v="visible" else: v="invisible" button="""<a href="javascript:swapvisu('%s')" class="boutton_nav_%s %s" ><img src="/includes/images/interface/util/pixel.gif" height="18px" width="18px" /></a><img src="/includes/images/interface/util/pixel.gif" height="18px" width="3px" class="pixdec" />""" % (idul,niv,actif) self.socket.send_datas(u'%s<a href="%s" %s>%s</a>' % (button,path,cl_e,text)) if sub_style and len(infos)>0: cl_c='class="nav_conteneur_%s_%s%s %s" id="%s"' % (self.name,niv,actif,v,idul) self.socket.send_datas("""<ul %s>""" % cl_c ) for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) self.socket.send_datas("""</ul>""") self.socket.send_datas('</li>') if my_style=='element-puce': cl_e='class="nav_element_%s_%s%s"' % (self.name,niv,actif) self.socket.send_datas('<li %s>' % cl_e) button="""<a class="boutton_nav_%s %s" ><img src="/includes/images/interface/util/pixel.gif" height="18px" width="30px" /></a><img src="/includes/images/interface/util/pixel.gif" height="18px" width="1px" class="pixdec" />""" % (niv,actif) self.socket.send_datas(u'%s<a href="%s" %s>%s</a>' % (button,path,cl_e,text)) if sub_style and len(infos)>0: cl_c='class="nav_conteneur_%s_%s%s %s" id="%s"' % (self.name,niv,actif,v,idul) self.socket.send_datas("""<ul %s>""" % cl_c ) for (idsub,textnav,newpath,nom) in infos: self.affiche_niveau(styles,idsub,niv+1,textnav,newpath,new_pere_actif) self.socket.send_datas("""</ul>""") self.socket.send_datas('</li>')