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):
36 def __init__(me, strictp = False, laxp = False, semip = False):
46 def encode(me, object name, object value):
47 """UE.encode(NAME, VALUE): encode a key/value pair"""
48 url_enc(&me.ctx, &me.d, TEXT_PTR(name), TEXT_PTR(value))
52 """UE.result -> STR: the encoded string"""
53 return TEXT_FROMSTRLEN(me.d.buf, me.d.len)
56 """UE.strictp -> BOOL: strictly escape non-alphanumerics?"""
57 return <bint>(me.ctx.f&URLF_STRICT)
61 me.ctx.f |= URLF_STRICT
63 me.ctx.f &= ~URLF_STRICT
66 """UE.laxp -> BOOL: only escape obviously unsafe characters?"""
67 return <bint>(me.ctx.f&URLF_LAX)
76 """UE.semip -> BOOL: separate key/value pairs with semicolons?"""
77 return <bint>(me.ctx.f&URLF_SEMI)
83 me.ctx.f &= ~URLF_SEMI
86 """URLDecode(STR, [semip = False]): iterator over (KEY, VALUE) pairs"""
90 def __cinit__(me, *hunoz, **hukairz):
92 url_initdec(&me.ctx, me.p)
95 def __init__(me, object string, semip = False):
101 me.p = xstrdup(TEXT_PTR(string))
114 anyp = url_dec(&me.ctx, &n, &v)
116 nn = TEXT_FROMSTRLEN(n.buf, n.len)
117 vv = TEXT_FROMSTRLEN(v.buf, v.len)
125 """UE.semip -> BOOL: separate key/value pairs with semicolons?"""
126 return <bint>(me.ctx.f&URLF_SEMI)
130 me.ctx.f |= URLF_SEMI
132 me.ctx.f &= ~URLF_SEMI
134 ###----- That's all, folks --------------------------------------------------