3 ### Form-urlencoding functions
5 ### (c) 2006 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 """URLEncode([strictp = False], [laxp = False], [semip = False])"""
31 def __cinit__(me, *hunoz, **hukairz):
34 def __init__(me, strictp = False, laxp = False, semip = False):
44 def encode(me, char *name, char *value):
45 """UE.encode(NAME, VALUE): encode a key/value pair"""
46 url_enc(&me.ctx, &me.d, name, value)
49 """UE.result -> STR: the encoded string"""
51 return PyString_FromStringAndSize(me.d.buf, me.d.len)
53 """UE.strictp -> BOOL: strictly escape non-alphanumerics?"""
55 return _tobool(me.ctx.f & URLF_STRICT)
58 me.ctx.f = me.ctx.f | URLF_STRICT
60 me.ctx.f = me.ctx.f & ~URLF_STRICT
62 """UE.laxp -> BOOL: only escape obviously unsafe characters?"""
64 return _tobool(me.ctx.f & URLF_LAX)
67 me.ctx.f = me.ctx.f | URLF_LAX
69 me.ctx.f = me.ctx.f & ~URLF_LAX
71 """UE.semip -> BOOL: separate key/value pairs with semicolons?"""
73 return _tobool(me.ctx.f & URLF_SEMI)
76 me.ctx.f = me.ctx.f | URLF_SEMI
78 me.ctx.f = me.ctx.f & ~URLF_SEMI
83 """URLDecode(STR, [semip = False]): iterator over (KEY, VALUE) pairs"""
87 def __cinit__(me, *hunoz, **hukairz):
89 url_initdec(&me.ctx, me.p)
90 def __init__(me, char *string, semip = False):
96 me.p = xstrdup(string)
109 anyp = url_dec(&me.ctx, &n, &v)
111 nn = PyString_FromStringAndSize(n.buf, n.len)
112 vv = PyString_FromStringAndSize(v.buf, v.len)
119 """UD.semip -> BOOL: key/value pairs separated with semicolons?"""
121 return _tobool(me.ctx.f & URLF_SEMI)
122 def __set__(me, val):
124 me.ctx.f = me.ctx.f | URLF_SEMI
126 me.ctx.f = me.ctx.f & ~URLF_SEMI
130 ###----- That's all, folks --------------------------------------------------