X-Git-Url: https://scm.cri.ensmp.fr/git/ZTUtils_hotfix.git/blobdiff_plain/65a58efbf6098c007eac625011cef38abeb2a9c0:/__init__.py..9bbe18b6fe9b8691ce59950a7ed9d18f6540e672:/Products/ZTUtils_hotfix/static/git-favicon.png diff --git a/__init__.py b/__init__.py deleted file mode 100644 index b9cbc1b..0000000 --- a/__init__.py +++ /dev/null @@ -1,139 +0,0 @@ -""" -This hotfix patch ZTUtils.Zope.make_query and make_hidden_input -to make a recursive marshal from a REQUEST.form data. - -pinbe 2004/09/23 -""" - -import urllib, cgi -from DateTime import DateTime - -def make_query(*args, **kwargs): - '''Construct a URL query string, with marshalling markup. - - If there are positional arguments, they must be dictionaries. - They are combined with the dictionary of keyword arguments to form - a dictionary of query names and values. - - Query names (the keys) must be strings. Values may be strings, - integers, floats, or DateTimes, and they may also be lists or - namespaces containing these types. Names and string values - should not be URL-quoted. All arguments are marshalled with - complex_marshal(). - ''' - d = {} - for arg in args: - d.update(arg) - d.update(kwargs) - - qlist = [] - uq = urllib.quote - for k, v in d.items() : - for field in recurse_marshal(k, v) : - qlist.append( '%s%s=%s' % (uq(field['k']), field['m'], uq(str(field['v']))) ) - - return '&'.join(qlist) - -def make_hidden_input(*args, **kwargs): - '''Construct a set of hidden input elements, with marshalling markup. - - If there are positional arguments, they must be dictionaries. - They are combined with the dictionary of keyword arguments to form - a dictionary of query names and values. - - Query names (the keys) must be strings. Values may be strings, - integers, floats, or DateTimes, and they may also be lists or - namespaces containing these types. All arguments are marshalled with - complex_marshal(). - ''' - - d = {} - for arg in args: - d.update(arg) - d.update(kwargs) - - hq = cgi.escape - qlist = [] - for k, v in d.items() : - for field in recurse_marshal(k, v) : - qlist.append( ('' - % (hq(field['k']), field['m'], hq(str(field['v'])))) ) - - return '\n'.join(qlist) - - -def _simple_marshal(v) : # ! It's not a simple_marshal patch, the returned value is not the same. - - if isinstance(v, bool) : - m = ':boolean' - elif isinstance(v, int) : - m = ':int' - elif isinstance(v, float) : - m = ':float' - elif isinstance(v, long) : - m = ':long' - elif isinstance(v, DateTime) : - m = ':date' - elif isinstance(v, unicode) : - m = ':utf8:ustring' - v = v.encode('utf8') - elif hasattr(v, 'items') : - m = ':record' - elif isinstance(v, list) : - if len(v) > 0 and hasattr(v[0], 'items') : - m = ':records' - else : - m = ':list' - else : - m = '' - - return m, v - - -def recurse_marshal(k, v, nested='') : - - marshalList = [] - m, v = _simple_marshal(v) - n = nested - if m == ':list' : - n = ':list' + n - for sv in v : - if isinstance(sv, list) : # only strings into sv - white_space_found = False - for ssv in sv : - if ssv.find(' ') >=0 : white_space_found = True - if white_space_found : - sv = '\n'.join(sv) - insertM = ':lines' - else : - sv = ' '.join(sv) - insertM = ':tokens' - - if isinstance(sv, unicode) : - sv = sv.encode('utf8') - insertM = ':utf8:u' + insertM[1:] - marshalList.extend(recurse_marshal(k, sv, nested=insertM + n)) - else : - marshalList.extend(recurse_marshal(k, sv, n)) - elif m == ':record' : - if n.find(':records') < 0 : - n = ':record' + n - for sk, sv in v.items() : - marshalList.extend(recurse_marshal('%s.%s' % (k, sk), sv, nested=n)) - elif m == ':records' : - n = ':records' + n - for sv in v : - for ssk, ssv in sv.items() : - marshalList.extend(recurse_marshal('%s.%s' % (k, ssk), ssv, nested=n)) - else : - marshalList.append({'k' : k, - 'm' : m + nested, - 'v' : v}) - - return marshalList - - -def initialize(context) : - import ZTUtils as ztu - ztu.make_query = ztu.Zope.make_query = make_query - ztu.make_hidden_input = ztu.Zope.make_hidden_input = make_hidden_input \ No newline at end of file