This commit is contained in:
Massimo
2012-09-25 14:50:32 -05:00
parent 722b16e620
commit 1430bc824f
6 changed files with 54 additions and 34 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.0.9 (2012-09-24 22:44:12) stable
Version 2.0.9 (2012-09-25 14:34:30) stable
@@ -157,6 +157,7 @@
<li><a href="http://www.danga.com/memcached/">memcache</a> developed by Evan Martin</li>
<li><a href="http://jquery.com/">jQuery</a> developed by John Resig</li>
<li>A syntax highlighter inspired by the code of <a href="http://www.petersblog.org/node/763">Peter Wilkinson</a></li>
<li><a href="https://github.com/jtauber/pyuca">pyUCA</a> developed by <a href="http://jtauber.com/blog/2006/01/27/python_unicode_collation_algorithm/">James Tauber</a></li>
</ul>
+6 -1
View File
@@ -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'))
+38 -27
View File
@@ -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)
+6 -4
View File
@@ -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:
+2 -1
View File
@@ -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