From 1430bc824f95f387610ec46f92928339d43a9bb5 Mon Sep 17 00:00:00 2001 From: Massimo Date: Tue, 25 Sep 2012 14:50:32 -0500 Subject: [PATCH] test --- VERSION | 2 +- applications/examples/views/default/who.html | 1 + gluon/contrib/pyuca/__init__.py | 7 ++- gluon/contrib/pyuca/pyuca.py | 65 ++++++++++++-------- gluon/main.py | 10 +-- gluon/tools.py | 3 +- 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/VERSION b/VERSION index ce16d1bb..ae5a99da 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.9 (2012-09-24 22:44:12) stable +Version 2.0.9 (2012-09-25 14:34:30) stable diff --git a/applications/examples/views/default/who.html b/applications/examples/views/default/who.html index efaec76b..64eef3bf 100644 --- a/applications/examples/views/default/who.html +++ b/applications/examples/views/default/who.html @@ -157,6 +157,7 @@
  • memcache developed by Evan Martin
  • jQuery developed by John Resig
  • A syntax highlighter inspired by the code of Peter Wilkinson
  • +
  • pyUCA developed by James Tauber
  • diff --git a/gluon/contrib/pyuca/__init__.py b/gluon/contrib/pyuca/__init__.py index 0aca262b..96d06196 100644 --- a/gluon/contrib/pyuca/__init__.py +++ b/gluon/contrib/pyuca/__init__.py @@ -1,5 +1,10 @@ import os import pyuca -unicode_collator = pyuca.Collator(os.path.join(os.path.dirname(__file__), 'allkeys.txt')) +unicode_collator = None +def set_unicode_collator(file): + global unicode_collator + unicode_collator = pyuca.Collator(file) + +set_unicode_collator(os.path.join(os.path.dirname(__file__), 'allkeys.txt')) diff --git a/gluon/contrib/pyuca/pyuca.py b/gluon/contrib/pyuca/pyuca.py index 8956f4e6..ce41fde9 100644 --- a/gluon/contrib/pyuca/pyuca.py +++ b/gluon/contrib/pyuca/pyuca.py @@ -1,21 +1,21 @@ # pyuca - Unicode Collation Algorithm -# Version: 2006-02-13 +# Version: 2012-06-21 # # James Tauber # http://jtauber.com/ -# Copyright (c) 2006 James Tauber -# +# Copyright (c) 2006-2012 James Tauber and contributors +# # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,7 +28,6 @@ """ Preliminary implementation of the Unicode Collation Algorithm. - This only implements the simple parts of the algorithm but I have successfully tested it using the Default Unicode Collation Element Table (DUCET) to collate Ancient Greek correctly. @@ -48,31 +47,39 @@ but you can always subset this for just the characters you are dealing with. """ -class Trie: - +class Node: + def __init__(self): - self.root = [None, {}] + self.value = None + self.children = {} + +class Trie: + + def __init__(self): + self.root = Node() + def add(self, key, value): curr_node = self.root for part in key: - curr_node = curr_node[1].setdefault(part, [None, {}]) - curr_node[0] = value - + curr_node = curr_node.children.setdefault(part, Node()) + curr_node.value = value + def find_prefix(self, key): curr_node = self.root remainder = key for part in key: - if part not in curr_node[1]: + if part not in curr_node.children: break - curr_node = curr_node[1][part] + curr_node = curr_node.children[part] remainder = remainder[1:] - return (curr_node[0], remainder) + return (curr_node.value, remainder) class Collator: def __init__(self, filename): + self.table = Trie() self.load(filename) @@ -85,7 +92,7 @@ class Collator: line = line[:line.find("#")] + "\n" line = line[:line.find("%")] + "\n" line = line.strip() - + if line.startswith("@"): pass else: @@ -96,32 +103,36 @@ class Collator: while True: begin = x.find("[") if begin == -1: - break + break end = x[begin:].find("]") collElement = x[begin:begin+end+1] x = x[begin + 1:] - + alt = collElement[1] chars = collElement[2:-1].split(".") - + collElements.append((alt, chars)) integer_points = [int(ch, 16) for ch in charList] self.table.add(integer_points, collElements) - + def sort_key(self, string): - + collation_elements = [] - + lookup_key = [ord(ch) for ch in string] while lookup_key: value, lookup_key = self.table.find_prefix(lookup_key) if not value: - # @@@ - raise ValueError, map(hex, lookup_key) + # Calculate implicit weighting for CJK Ideographs + # contributed by David Schneider 2009-07-27 + # http://www.unicode.org/reports/tr10/#Implicit_Weights + value = [] + value.append((".", ["%X" % (0xFB40 + (lookup_key[0] >> 15)), "0020", "0002", "0001"])) + value.append((".", ["%X" % ((lookup_key[0] & 0x7FFF) | 0x8000), "0000", "0000", "0000"])) + lookup_key = lookup_key[1:] collation_elements.extend(value) - sort_key = [] - + for level in range(4): if level: sort_key.append(0) # level separator @@ -129,5 +140,5 @@ class Collator: ce_l = int(element[1][level], 16) if ce_l: sort_key.append(ce_l) - + return tuple(sort_key) diff --git a/gluon/main.py b/gluon/main.py index e02a36f9..bc67f6c3 100644 --- a/gluon/main.py +++ b/gluon/main.py @@ -325,10 +325,12 @@ def parse_get_post_vars(request, environ): dpk = dpost[key] # if en element is not a file replace it with its value else leave it alone if isinstance(dpk, list): - if not dpk[0].filename: - value = [x.value for x in dpk] - else: - value = [x for x in dpk] + value = [] + for _dpk in dpk: + if not _dpk.filename: + value.append(_dpk.value) + else: + value.append(_dpk) elif not dpk.filename: value = dpk.value else: diff --git a/gluon/tools.py b/gluon/tools.py index 9151e522..1119efe2 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -4759,7 +4759,8 @@ class Wiki(object): db.wiki_page.title.default = title_guess db.wiki_page.slug.default = slug if slug == 'wiki-menu': - db.wiki_page.body.default = '- Menu Item > @////index\n- - Submenu > http://web2py.com' + db.wiki_page.body.default = \ + '- Menu Item > @////index\n- - Submenu > http://web2py.com' else: db.wiki_page.body.default = '## %s\n\npage content' % title_guess vars = current.request.post_vars