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://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 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 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> </ul>
+6 -1
View File
@@ -1,5 +1,10 @@
import os import os
import pyuca 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'))
+23 -12
View File
@@ -1,10 +1,10 @@
# pyuca - Unicode Collation Algorithm # pyuca - Unicode Collation Algorithm
# Version: 2006-02-13 # Version: 2012-06-21
# #
# James Tauber # James Tauber
# http://jtauber.com/ # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,6 @@
""" """
Preliminary implementation of the Unicode Collation Algorithm. Preliminary implementation of the Unicode Collation Algorithm.
This only implements the simple parts of the algorithm but I have successfully 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 tested it using the Default Unicode Collation Element Table (DUCET) to collate
Ancient Greek correctly. Ancient Greek correctly.
@@ -48,31 +47,39 @@ but you can always subset this for just the characters you are dealing with.
""" """
class Node:
def __init__(self):
self.value = None
self.children = {}
class Trie: class Trie:
def __init__(self): def __init__(self):
self.root = [None, {}] self.root = Node()
def add(self, key, value): def add(self, key, value):
curr_node = self.root curr_node = self.root
for part in key: for part in key:
curr_node = curr_node[1].setdefault(part, [None, {}]) curr_node = curr_node.children.setdefault(part, Node())
curr_node[0] = value curr_node.value = value
def find_prefix(self, key): def find_prefix(self, key):
curr_node = self.root curr_node = self.root
remainder = key remainder = key
for part in key: for part in key:
if part not in curr_node[1]: if part not in curr_node.children:
break break
curr_node = curr_node[1][part] curr_node = curr_node.children[part]
remainder = remainder[1:] remainder = remainder[1:]
return (curr_node[0], remainder) return (curr_node.value, remainder)
class Collator: class Collator:
def __init__(self, filename): def __init__(self, filename):
self.table = Trie() self.table = Trie()
self.load(filename) self.load(filename)
@@ -116,10 +123,14 @@ class Collator:
while lookup_key: while lookup_key:
value, lookup_key = self.table.find_prefix(lookup_key) value, lookup_key = self.table.find_prefix(lookup_key)
if not value: if not value:
# @@@ # Calculate implicit weighting for CJK Ideographs
raise ValueError, map(hex, lookup_key) # 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) collation_elements.extend(value)
sort_key = [] sort_key = []
for level in range(4): for level in range(4):
+6 -4
View File
@@ -325,10 +325,12 @@ def parse_get_post_vars(request, environ):
dpk = dpost[key] dpk = dpost[key]
# if en element is not a file replace it with its value else leave it alone # if en element is not a file replace it with its value else leave it alone
if isinstance(dpk, list): if isinstance(dpk, list):
if not dpk[0].filename: value = []
value = [x.value for x in dpk] for _dpk in dpk:
else: if not _dpk.filename:
value = [x for x in dpk] value.append(_dpk.value)
else:
value.append(_dpk)
elif not dpk.filename: elif not dpk.filename:
value = dpk.value value = dpk.value
else: else:
+2 -1
View File
@@ -4759,7 +4759,8 @@ class Wiki(object):
db.wiki_page.title.default = title_guess db.wiki_page.title.default = title_guess
db.wiki_page.slug.default = slug db.wiki_page.slug.default = slug
if slug == 'wiki-menu': 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: else:
db.wiki_page.body.default = '## %s\n\npage content' % title_guess db.wiki_page.body.default = '## %s\n\npage content' % title_guess
vars = current.request.post_vars vars = current.request.post_vars