Intégration de la branche release-3.0.0

This commit is contained in:
Jephté Clain 2015-12-24 15:39:53 +04:00
commit 4080daa0b8
7 changed files with 77 additions and 12 deletions

View File

@ -1,3 +1,7 @@
## Version 3.0.0 du 24/12/2015-15:39
4b1c30b nouvelles fonctions pour le module cgi. cgilsxml, cgiupload et cgiparams sont rassemblés dans le module cgisupport
## Version 2.26.0 du 24/12/2015-12:17 ## Version 2.26.0 du 24/12/2015-12:17
d5a2cce cgilsxml.py: rajouter la variable env/query_vars d5a2cce cgilsxml.py: rajouter la variable env/query_vars

View File

@ -1 +1 @@
2.26.0 3.0.0

View File

@ -1 +1 @@
009011000 010000000

View File

@ -32,6 +32,13 @@ function nocache_header() {
echo "Expires: Thu, 01 Jan 1970 00:00:00 GMT" echo "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
} }
function cgiredirect() {
# Rediriger le client vers une autre page
echo "Status: 302 Found"
echo "Location: $1"
echo ""
}
function cgicontent() { function cgicontent() {
# Générer les en-têtes nécessaire avant de servir le contenu. # Générer les en-têtes nécessaire avant de servir le contenu.
# $1(=text/html) est le type de contenu. S'il faut servir le contenu avec # $1(=text/html) est le type de contenu. S'il faut servir le contenu avec
@ -71,3 +78,9 @@ function cgicontent_nocache() {
echo "" echo ""
[ -f "$contentfile" ] && cat "$contentfile" [ -f "$contentfile" ] && cat "$contentfile"
} }
function cgierror() {
# Afficher un message d'erreur
cgicontent_nocache text/plain
echo "ERROR: $*"
}

View File

@ -1,8 +0,0 @@
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
## Fonction de support pour cgilsxml
##@cooked nocomments
##@require ulib
uprovide cgilsxml
urequire ulib
function cgilsxml() { "$ULIBDIR/support/cgilsxml.py" "$@"; }

View File

@ -1,8 +1,10 @@
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 ##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
## Fonction de support pour cgiupload ## Fonction de support pour faire des scripts CGI
##@cooked nocomments ##@cooked nocomments
##@require ulib ##@require ulib
uprovide cgiupload uprovide cgisupport
urequire ulib urequire ulib
function cgiparams() { "$ULIBDIR/support/cgiparams.py" "$@"; }
function cgilsxml() { "$ULIBDIR/support/cgilsxml.py" "$@"; }
function cgiupload() { "$ULIBDIR/support/cgiupload.py" "$@"; } function cgiupload() { "$ULIBDIR/support/cgiupload.py" "$@"; }

54
lib/ulib/support/cgiparams.py Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
u"""Ce script est prévu pour être utilisé dans un script CGI.
Il permet de lister les paramètres du formulaire et d'y accéder depuis un script bash
"""
import re, cgi
RE_NAME_VALUE = re.compile(r'([a-zA-Z0-9_-]+)(?:=(.*))?$')
def quote(value, q=False):
if value or q:
value = "'%s'" % value.replace("'", "'\\''")
value = re.sub(r"(?<!\\)''", "", value)
return value
else: return ""
def print_scalar(name, value):
print "%s=%s" % (name, quote(value))
def print_array(name, values):
print "%s=(" % name
for value in values:
print quote(value, True)
print ")"
def run_cgiparams():
from optparse import OptionParser
OP = OptionParser(usage=u"\n\t%prog [options] params...", description=__doc__)
o, args = OP.parse_args()
form = cgi.FieldStorage(keep_blank_values=True)
if args:
for nv in args:
mo = RE_NAME_VALUE.match(nv)
if mo is None: continue
fname, defvalue = mo.group(1), mo.group(2)
if defvalue is None: defvalue = ''
vname = fname.replace('-', '_')
values = form.getlist(fname)
if len(values) == 0: print_scalar(vname, defvalue)
elif len(values) == 1: print_scalar(vname, values[0])
else: print_array(vname, values)
else:
for fname in form.keys():
vname = fname.replace('-', '_')
values = form.getlist(fname)
if len(values) == 1: print_scalar(vname, values[0])
else: print_array(vname, values)
if __name__ == '__main__':
run_cgiparams()