zope.ucol-1.0.2/0000775000076400007640000000000010515001056011553 5ustar jimjimzope.ucol-1.0.2/icu/0000775000076400007640000000000010515001056012333 5ustar jimjimzope.ucol-1.0.2/icu/src/0000775000076400007640000000000010515001056013122 5ustar jimjimzope.ucol-1.0.2/icu/src/zc/0000775000076400007640000000000010515001056013536 5ustar jimjimzope.ucol-1.0.2/icu/src/zc/recipe/0000775000076400007640000000000010515001056015005 5ustar jimjimzope.ucol-1.0.2/icu/src/zc/recipe/icu/0000775000076400007640000000000010515001056015565 5ustar jimjimzope.ucol-1.0.2/icu/src/zc/recipe/icu/__init__.py0000664000076400007640000000501110514737452017712 0ustar jimjimimport os, sys, shutil, tempfile, urllib2 import setuptools.archive_util class Recipe: def __init__(self, buildout, name, options): self.name = name self.options = options self.location = os.path.join( buildout['buildout']['parts-directory'], self.name) options['location'] = self.location if sys.platform.startswith('linux'): platform = 'LinuxRedHat' elif sys.platform.startswith('darwin'): platform = 'MacOSX' elif sys.platform.startswith('win32'): platform = 'win32' else: raise SystemError("Can't guess an ICU platform") options['platform'] = platform def install(self): options = self.options dest = options['location'] if os.path.exists(dest): return dest if options['platform'] == 'win32': return self.install_win32(options, dest) here = os.getcwd() tmp = tempfile.mkdtemp() try: f = urllib2.urlopen( 'ftp://ftp.software.ibm.com/software/globalization/icu/' '%(version)s/icu-%(version)s.tgz' % dict(version=options['version']) ) open(os.path.join(tmp, 'arch'), 'w').write(f.read()) f.close() setuptools.archive_util.unpack_archive( os.path.join(tmp, 'arch'), tmp, ) os.chdir(os.path.join(tmp, 'icu', 'source')) assert os.spawnl( os.P_WAIT, os.path.join(tmp, 'icu', 'source', 'runConfigureICU'), os.path.join(tmp, 'icu', 'source', 'runConfigureICU'), options['platform'], '--prefix='+dest, ) == 0 assert os.spawnlp(os.P_WAIT, 'make', 'make', 'install') == 0 finally: os.chdir(here) shutil.rmtree(tmp) return dest def update(self): pass def install_win32(self, options, dest): tmp = tempfile.mkstemp() try: f = urllib2.urlopen( 'ftp://ftp.software.ibm.com/software/globalization/icu/' '%(version)s/icu-%(version)s-Win32-msvc7.1.zip' % dict(version=options['version']) ) open(tmp, 'w').write(f.read()) f.close() setuptools.archive_util.unpack_archive(tmp, dest) finally: shutil.rmfile(tmp) return dest zope.ucol-1.0.2/icu/src/zc/recipe/__init__.py0000664000076400007640000000007010514737452017132 0ustar jimjim__import__('pkg_resources').declare_namespace(__name__) zope.ucol-1.0.2/icu/src/zc/__init__.py0000664000076400007640000000007010514737452015663 0ustar jimjim__import__('pkg_resources').declare_namespace(__name__) zope.ucol-1.0.2/icu/README.txt0000664000076400007640000000051610514737452014052 0ustar jimjimRecipe for installing ICU into a buildout ========================================= The zc.recipe.icu recipe installs the International Component for Unicode (ICU) library into a `buildout `_. The recipe takes a single option, version:: [icu] recipe = zc.recipe.icu version = 3.2 zope.ucol-1.0.2/icu/setup.py0000664000076400007640000000177710514737452014100 0ustar jimjimimport os from setuptools import setup, find_packages def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() name = "zc.recipe.icu" setup( name = name, version = "1.0.0b1", author = "Jim Fulton", author_email = "jim@zope.com", description = ("ZC Buildout recipe for installing the ICU library" " into a buildout"), long_description= read('README.txt'), license = "ZPL 2.1", keywords = "development build internationalization", url='http://www.python.org/pypi/'+name, packages = find_packages('src'), include_package_data = True, package_dir = {'':'src'}, namespace_packages = ['zc', 'zc.recipe'], install_requires = ['setuptools'], entry_points = {'zc.buildout': ['default = %s:Recipe' % name]}, classifiers = [ 'Framework :: Buildout', 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: Zope Public License', ], ) zope.ucol-1.0.2/src/0000775000076400007640000000000010515001056012342 5ustar jimjimzope.ucol-1.0.2/src/zope/0000775000076400007640000000000010515001056013317 5ustar jimjimzope.ucol-1.0.2/src/zope/ucol/0000775000076400007640000000000010515001056014261 5ustar jimjimzope.ucol-1.0.2/src/zope/ucol/README.txt0000644000076400017500000000362010356556301015265 0ustar jimLocale-based text collation using ICU ===================================== The zope.ucol package provides a minimal Pythonic wrapper around the u_col C API of the International Components for Unicode (ICU) library. It provides locale-based text collation. To perform collation, you need to create a collator key factory for your locale. We'll use the special "root" locale in this example: >>> import zope.ucol >>> collator = zope.ucol.Collator("root") The collator has a key method for creating collation keys from unicode strings. The method can be passed as the key argument to list.sort or to the built-in sorted function. >>> sorted([u'Sam', u'sally', u'Abe', u'alice', u'Terry', u'tim', ... u'\U00023119', u'\u62d5'], key=collator.key) [u'Abe', u'alice', u'sally', u'Sam', u'Terry', u'tim', u'\u62d5', u'\U00023119'] There is a cmp method for comparing 2 unicode strings, which can also be used when sorting: >>> sorted([u'Sam', u'sally', u'Abe', u'alice', u'Terry', u'tim', ... u'\U00023119', u'\u62d5'], collator.cmp) [u'Abe', u'alice', u'sally', u'Sam', u'Terry', u'tim', u'\u62d5', u'\U00023119'] Note that it is almost always more efficient to pass the key method to sorting functions, rather than the cmp method. The cmp method is more efficient in the special case that strings are long and few and when they tend to differ at their beginnings. This is because computing the entire key can be much more expensive than comparison when the order can be determined based on analyzing a small portion of the original strings. Collator attributes ------------------- You can ask a collator for it's locale: >>> collator.locale 'root' and you can find out whether default collation information was used: >>> collator.used_default_information 0 >>> collator = zope.ucol.Collator("eek") >>> collator.used_default_information 1 zope.ucol-1.0.2/src/zope/ucol/__init__.py0000644000076400017500000000143610356556301015703 0ustar jim############################################################################## # # Copyright (c) 2004 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Locale-based text collation using ICU See README.txt in the package. $Id: __init__.py 40673 2005-12-09 22:09:28Z jim $ """ from _zope_ucol import Collator zope.ucol-1.0.2/src/zope/ucol/_zope_ucol.c0000644000076400017500000011713410357043472016100 0ustar jim/* Generated by Pyrex 0.9.3 on Wed Jan 4 17:07:13 2006 */ #include "Python.h" #include "structmember.h" #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #include "unicode/utypes.h" #include "unicode/utf.h" #include "unicode/ustring.h" #include "unicode/ucol.h" typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ static void __Pyx_AddTraceback(char *funcname); /*proto*/ static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static PyObject *__pyx_m; static PyObject *__pyx_b; static int __pyx_lineno; static char *__pyx_filename; staticforward char **__pyx_f; static char __pyx_mdoc[] = "Simple wrapper for ICU ucol API\n\n$Id$\n"; /* Declarations from _zope_ucol */ staticforward PyTypeObject __pyx_type_10_zope_ucol_UCharString; struct __pyx_obj_10_zope_ucol_UCharString { PyObject_HEAD UChar (*data); int32_t length; PyObject *base; int need_to_free; }; staticforward PyTypeObject __pyx_type_10_zope_ucol_Collator; struct __pyx_obj_10_zope_ucol_Collator { PyObject_HEAD UCollator (*collator); PyObject *locale; int used_default_information; }; static PyTypeObject *__pyx_ptype_10_zope_ucol_UCharString = 0; static PyTypeObject *__pyx_ptype_10_zope_ucol_Collator = 0; /* Implementation of _zope_ucol */ static PyObject *__pyx_n_sys; static PyObject *__pyx_n_unicode; static PyObject *__pyx_n_TypeError; static PyObject *__pyx_n_MemoryError; static PyObject *__pyx_n_ValueError; static PyObject *__pyx_k2p; static PyObject *__pyx_k3p; static char (__pyx_k2[]) = "Expected unicode string"; static char (__pyx_k3[]) = "Couldn't convert Python unicode data to ICU unicode data."; static int __pyx_f_10_zope_ucol_11UCharString___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_f_10_zope_ucol_11UCharString___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_text = 0; int32_t __pyx_v_buffsize; enum UErrorCode __pyx_v_status; Py_UNICODE (*__pyx_v_str); int __pyx_v_length; int __pyx_r; int __pyx_1; PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; PyObject *__pyx_4 = 0; static char *__pyx_argnames[] = {"text",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_text)) return -1; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_text); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":87 */ __pyx_1 = (!PyUnicode_Check(__pyx_v_text)); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":88 */ __pyx_1 = PyString_Check(__pyx_v_text); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":89 */ __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_unicode); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;} __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;} Py_INCREF(__pyx_v_text); PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_text); __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; Py_DECREF(__pyx_3); __pyx_3 = 0; Py_DECREF(__pyx_v_text); __pyx_v_text = __pyx_4; __pyx_4 = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":90 */ if (!PyUnicode_Check(__pyx_v_text)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;} } goto __pyx_L3; } /*else*/ { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":92 */ __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_TypeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} Py_INCREF(__pyx_k2p); PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k2p); __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; Py_DECREF(__pyx_3); __pyx_3 = 0; __Pyx_Raise(__pyx_4, 0, 0); Py_DECREF(__pyx_4); __pyx_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;} } __pyx_L3:; goto __pyx_L2; } __pyx_L2:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":94 */ __pyx_v_length = PyUnicode_GET_SIZE(__pyx_v_text); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":95 */ __pyx_v_str = PyUnicode_AS_UNICODE(__pyx_v_text); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":98 */ __pyx_1 = ((sizeof(Py_UNICODE )) == 2); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":99 */ ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data = __pyx_v_str; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":100 */ ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->length = __pyx_v_length; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":101 */ Py_INCREF(__pyx_v_text); Py_DECREF(((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->base); ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->base = __pyx_v_text; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":102 */ ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->need_to_free = 0; goto __pyx_L4; } /*else*/ { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":104 */ __pyx_v_buffsize = ((2 * __pyx_v_length) + 1); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":105 */ ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data = ((UChar (*))PyMem_Malloc((__pyx_v_buffsize * (sizeof(UChar ))))); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":106 */ __pyx_1 = (((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data == 0); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":107 */ __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_MemoryError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L1;} __Pyx_Raise(__pyx_2, 0, 0); Py_DECREF(__pyx_2); __pyx_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L1;} goto __pyx_L5; } __pyx_L5:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":108 */ __pyx_v_status = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":109 */ u_strFromUTF32(((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data,__pyx_v_buffsize,(&((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->length),((UChar32 (*))__pyx_v_str),__pyx_v_length,(&__pyx_v_status)); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":111 */ if (!(((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->length <= __pyx_v_buffsize)) { PyErr_SetNone(PyExc_AssertionError); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; goto __pyx_L1;} } /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":112 */ ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->need_to_free = 1; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":113 */ __pyx_1 = U_FAILURE(__pyx_v_status); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":114 */ __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;} __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;} Py_INCREF(__pyx_k3p); PyTuple_SET_ITEM(__pyx_4, 0, __pyx_k3p); __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; Py_DECREF(__pyx_4); __pyx_4 = 0; __Pyx_Raise(__pyx_2, 0, 0); Py_DECREF(__pyx_2); __pyx_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;} goto __pyx_L6; } __pyx_L6:; } __pyx_L4:; __pyx_r = 0; goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); __Pyx_AddTraceback("_zope_ucol.UCharString.__new__"); __pyx_r = -1; __pyx_L0:; Py_DECREF(__pyx_v_self); Py_DECREF(__pyx_v_text); return __pyx_r; } static void __pyx_f_10_zope_ucol_11UCharString___dealloc__(PyObject *__pyx_v_self); /*proto*/ static void __pyx_f_10_zope_ucol_11UCharString___dealloc__(PyObject *__pyx_v_self) { int __pyx_1; Py_INCREF(__pyx_v_self); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":119 */ __pyx_1 = ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->need_to_free; if (__pyx_1) { __pyx_1 = (((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data != 0); } if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":120 */ PyMem_Free(((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":121 */ ((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_self)->data = 0; goto __pyx_L2; } __pyx_L2:; goto __pyx_L0; __Pyx_AddTraceback("_zope_ucol.UCharString.__dealloc__"); __pyx_L0:; Py_DECREF(__pyx_v_self); } static PyObject *__pyx_k4p; static PyObject *__pyx_k5p; static char (__pyx_k4[]) = "String locale expected"; static char (__pyx_k5[]) = "Couldn't create a collator"; static int __pyx_f_10_zope_ucol_8Collator___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_f_10_zope_ucol_8Collator___new__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_locale = 0; UCollator (*__pyx_v_collator); enum UErrorCode __pyx_v_status; int __pyx_r; int __pyx_1; PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; PyObject *__pyx_4 = 0; static char *__pyx_argnames[] = {"locale",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_locale)) return -1; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_locale); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":136 */ __pyx_1 = (!PyString_Check(__pyx_v_locale)); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":137 */ __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_TypeError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;} __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;} Py_INCREF(__pyx_k4p); PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k4p); __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; Py_DECREF(__pyx_3); __pyx_3 = 0; __Pyx_Raise(__pyx_4, 0, 0); Py_DECREF(__pyx_4); __pyx_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; goto __pyx_L1;} goto __pyx_L2; } __pyx_L2:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":139 */ __pyx_v_status = U_ZERO_ERROR; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":140 */ __pyx_v_collator = ucol_open(PyString_AS_STRING(__pyx_v_locale),(&__pyx_v_status)); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":141 */ __pyx_1 = U_FAILURE(__pyx_v_status); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":142 */ __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;} __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;} Py_INCREF(__pyx_k5p); PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k5p); __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; Py_DECREF(__pyx_3); __pyx_3 = 0; __Pyx_Raise(__pyx_4, 0, 0); Py_DECREF(__pyx_4); __pyx_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;} goto __pyx_L3; } __pyx_L3:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":143 */ ((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->collator = __pyx_v_collator; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":144 */ Py_INCREF(__pyx_v_locale); Py_DECREF(((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->locale); ((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->locale = __pyx_v_locale; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":145 */ __pyx_1 = (__pyx_v_status == U_USING_DEFAULT_WARNING); if (!__pyx_1) { __pyx_1 = (__pyx_v_status == U_USING_FALLBACK_WARNING); } if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":148 */ __pyx_v_status = 1; goto __pyx_L4; } __pyx_L4:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":149 */ ((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->used_default_information = __pyx_v_status; __pyx_r = 0; goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); __Pyx_AddTraceback("_zope_ucol.Collator.__new__"); __pyx_r = -1; __pyx_L0:; Py_DECREF(__pyx_v_self); Py_DECREF(__pyx_v_locale); return __pyx_r; } static void __pyx_f_10_zope_ucol_8Collator___dealloc__(PyObject *__pyx_v_self); /*proto*/ static void __pyx_f_10_zope_ucol_8Collator___dealloc__(PyObject *__pyx_v_self) { int __pyx_1; Py_INCREF(__pyx_v_self); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":152 */ __pyx_1 = (((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->collator != 0); if (__pyx_1) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":153 */ ucol_close(((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->collator); goto __pyx_L2; } __pyx_L2:; goto __pyx_L0; __Pyx_AddTraceback("_zope_ucol.Collator.__dealloc__"); __pyx_L0:; Py_DECREF(__pyx_v_self); } static PyObject *__pyx_f_10_zope_ucol_8Collator_key(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_10_zope_ucol_8Collator_key[] = "Compute a collation key for the given unicode text.\n\n Of course, the key is only valid for the given locale.\n "; static PyObject *__pyx_f_10_zope_ucol_8Collator_key(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_text = 0; char (*__pyx_v_buffer); int32_t __pyx_v_bufsize; int32_t __pyx_v_size; PyObject *__pyx_v_icutext; PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; int __pyx_3; static char *__pyx_argnames[] = {"text",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_text)) return 0; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_text); __pyx_v_icutext = Py_None; Py_INCREF(__pyx_v_icutext); __pyx_v_result = Py_None; Py_INCREF(__pyx_v_result); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":164 */ __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; goto __pyx_L1;} Py_INCREF(__pyx_v_text); PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_text); __pyx_2 = PyObject_CallObject(((PyObject*)__pyx_ptype_10_zope_ucol_UCharString), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_v_icutext); __pyx_v_icutext = __pyx_2; __pyx_2 = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":165 */ __pyx_v_bufsize = ((((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length * 2) + 10); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":168 */ __pyx_v_buffer = ((char (*))PyMem_Malloc((__pyx_v_bufsize + 1))); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":169 */ __pyx_3 = (__pyx_v_buffer == 0); if (__pyx_3) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":170 */ __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_MemoryError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; goto __pyx_L1;} __Pyx_Raise(__pyx_1, 0, 0); Py_DECREF(__pyx_1); __pyx_1 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; goto __pyx_L1;} goto __pyx_L2; } __pyx_L2:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":171 */ __pyx_v_size = ucol_getSortKey(((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length,((uint8_t (*))__pyx_v_buffer),__pyx_v_bufsize); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":175 */ while (1) { __pyx_3 = (__pyx_v_size > __pyx_v_bufsize); if (!__pyx_3) break; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":176 */ __pyx_v_bufsize = __pyx_v_size; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":177 */ PyMem_Free(__pyx_v_buffer); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":178 */ __pyx_v_buffer = ((char (*))PyMem_Malloc((__pyx_v_bufsize + 1))); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":179 */ __pyx_3 = (__pyx_v_buffer == 0); if (__pyx_3) { /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":180 */ __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_MemoryError); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;} __Pyx_Raise(__pyx_2, 0, 0); Py_DECREF(__pyx_2); __pyx_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; goto __pyx_L1;} goto __pyx_L5; } __pyx_L5:; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":181 */ __pyx_v_size = ucol_getSortKey(((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_icutext)->length,((uint8_t (*))__pyx_v_buffer),__pyx_v_bufsize); } /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":186 */ __pyx_1 = PyString_FromStringAndSize(__pyx_v_buffer,__pyx_v_size); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;} Py_DECREF(__pyx_v_result); __pyx_v_result = __pyx_1; __pyx_1 = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":187 */ PyMem_Free(__pyx_v_buffer); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":188 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; __pyx_r = Py_None; Py_INCREF(__pyx_r); goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); __Pyx_AddTraceback("_zope_ucol.Collator.key"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_icutext); Py_DECREF(__pyx_v_result); Py_DECREF(__pyx_v_self); Py_DECREF(__pyx_v_text); return __pyx_r; } static PyObject *__pyx_f_10_zope_ucol_8Collator_cmp(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_10_zope_ucol_8Collator_cmp(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_o1 = 0; PyObject *__pyx_v_o2 = 0; PyObject *__pyx_v_u1; PyObject *__pyx_v_u2; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; static char *__pyx_argnames[] = {"o1","o2",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_o1, &__pyx_v_o2)) return 0; Py_INCREF(__pyx_v_self); Py_INCREF(__pyx_v_o1); Py_INCREF(__pyx_v_o2); __pyx_v_u1 = Py_None; Py_INCREF(__pyx_v_u1); __pyx_v_u2 = Py_None; Py_INCREF(__pyx_v_u2); /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":191 */ __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;} Py_INCREF(__pyx_v_o1); PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_o1); __pyx_2 = PyObject_CallObject(((PyObject*)__pyx_ptype_10_zope_ucol_UCharString), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_v_u1); __pyx_v_u1 = __pyx_2; __pyx_2 = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":192 */ __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; goto __pyx_L1;} Py_INCREF(__pyx_v_o2); PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_o2); __pyx_2 = PyObject_CallObject(((PyObject*)__pyx_ptype_10_zope_ucol_UCharString), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_v_u2); __pyx_v_u2 = __pyx_2; __pyx_2 = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":193 */ __pyx_1 = PyInt_FromLong(ucol_strcoll(((struct __pyx_obj_10_zope_ucol_Collator *)__pyx_v_self)->collator,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_u1)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_u1)->length,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_u2)->data,((struct __pyx_obj_10_zope_ucol_UCharString *)__pyx_v_u2)->length)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; goto __pyx_L1;} __pyx_r = __pyx_1; __pyx_1 = 0; goto __pyx_L0; __pyx_r = Py_None; Py_INCREF(__pyx_r); goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); __Pyx_AddTraceback("_zope_ucol.Collator.cmp"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_u1); Py_DECREF(__pyx_v_u2); Py_DECREF(__pyx_v_self); Py_DECREF(__pyx_v_o1); Py_DECREF(__pyx_v_o2); return __pyx_r; } static __Pyx_InternTabEntry __pyx_intern_tab[] = { {&__pyx_n_MemoryError, "MemoryError"}, {&__pyx_n_TypeError, "TypeError"}, {&__pyx_n_ValueError, "ValueError"}, {&__pyx_n_sys, "sys"}, {&__pyx_n_unicode, "unicode"}, {0, 0} }; static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_k2p, __pyx_k2, sizeof(__pyx_k2)}, {&__pyx_k3p, __pyx_k3, sizeof(__pyx_k3)}, {&__pyx_k4p, __pyx_k4, sizeof(__pyx_k4)}, {&__pyx_k5p, __pyx_k5, sizeof(__pyx_k5)}, {0, 0, 0} }; static PyObject *__pyx_tp_new_10_zope_ucol_UCharString(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); struct __pyx_obj_10_zope_ucol_UCharString *p = (struct __pyx_obj_10_zope_ucol_UCharString *)o; p->base = Py_None; Py_INCREF(p->base); if (__pyx_f_10_zope_ucol_11UCharString___new__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } static void __pyx_tp_dealloc_10_zope_ucol_UCharString(PyObject *o) { struct __pyx_obj_10_zope_ucol_UCharString *p = (struct __pyx_obj_10_zope_ucol_UCharString *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++o->ob_refcnt; __pyx_f_10_zope_ucol_11UCharString___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --o->ob_refcnt; PyErr_Restore(etype, eval, etb); } Py_XDECREF(p->base); (*o->ob_type->tp_free)(o); } static int __pyx_tp_traverse_10_zope_ucol_UCharString(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_10_zope_ucol_UCharString *p = (struct __pyx_obj_10_zope_ucol_UCharString *)o; if (p->base) { e = (*v)(p->base, a); if (e) return e; } return 0; } static int __pyx_tp_clear_10_zope_ucol_UCharString(PyObject *o) { struct __pyx_obj_10_zope_ucol_UCharString *p = (struct __pyx_obj_10_zope_ucol_UCharString *)o; Py_XDECREF(p->base); p->base = Py_None; Py_INCREF(p->base); return 0; } static struct PyMethodDef __pyx_methods_10_zope_ucol_UCharString[] = { {0, 0, 0, 0} }; static struct PyMemberDef __pyx_members_10_zope_ucol_UCharString[] = { {"length", T_INT, offsetof(struct __pyx_obj_10_zope_ucol_UCharString, length), READONLY, 0}, {"base", T_OBJECT, offsetof(struct __pyx_obj_10_zope_ucol_UCharString, base), READONLY, 0}, {"need_to_free", T_INT, offsetof(struct __pyx_obj_10_zope_ucol_UCharString, need_to_free), READONLY, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_UCharString = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ 0, /*nb_divide*/ 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ 0, /*nb_coerce*/ 0, /*nb_int*/ 0, /*nb_long*/ 0, /*nb_float*/ 0, /*nb_oct*/ 0, /*nb_hex*/ 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ 0, /*nb_inplace_divide*/ 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ }; static PySequenceMethods __pyx_tp_as_sequence_UCharString = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_UCharString = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_UCharString = { 0, /*bf_getreadbuffer*/ 0, /*bf_getwritebuffer*/ 0, /*bf_getsegcount*/ 0, /*bf_getcharbuffer*/ }; statichere PyTypeObject __pyx_type_10_zope_ucol_UCharString = { PyObject_HEAD_INIT(0) 0, /*ob_size*/ "_zope_ucol.UCharString", /*tp_name*/ sizeof(struct __pyx_obj_10_zope_ucol_UCharString), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_10_zope_ucol_UCharString, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ &__pyx_tp_as_number_UCharString, /*tp_as_number*/ &__pyx_tp_as_sequence_UCharString, /*tp_as_sequence*/ &__pyx_tp_as_mapping_UCharString, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_UCharString, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ "Wrapper for ICU UChar arrays\n ", /*tp_doc*/ __pyx_tp_traverse_10_zope_ucol_UCharString, /*tp_traverse*/ __pyx_tp_clear_10_zope_ucol_UCharString, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_10_zope_ucol_UCharString, /*tp_methods*/ __pyx_members_10_zope_ucol_UCharString, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_10_zope_ucol_UCharString, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ }; static PyObject *__pyx_tp_new_10_zope_ucol_Collator(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); struct __pyx_obj_10_zope_ucol_Collator *p = (struct __pyx_obj_10_zope_ucol_Collator *)o; p->locale = Py_None; Py_INCREF(p->locale); if (__pyx_f_10_zope_ucol_8Collator___new__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } static void __pyx_tp_dealloc_10_zope_ucol_Collator(PyObject *o) { struct __pyx_obj_10_zope_ucol_Collator *p = (struct __pyx_obj_10_zope_ucol_Collator *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++o->ob_refcnt; __pyx_f_10_zope_ucol_8Collator___dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --o->ob_refcnt; PyErr_Restore(etype, eval, etb); } Py_XDECREF(p->locale); (*o->ob_type->tp_free)(o); } static int __pyx_tp_traverse_10_zope_ucol_Collator(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_10_zope_ucol_Collator *p = (struct __pyx_obj_10_zope_ucol_Collator *)o; if (p->locale) { e = (*v)(p->locale, a); if (e) return e; } return 0; } static int __pyx_tp_clear_10_zope_ucol_Collator(PyObject *o) { struct __pyx_obj_10_zope_ucol_Collator *p = (struct __pyx_obj_10_zope_ucol_Collator *)o; Py_XDECREF(p->locale); p->locale = Py_None; Py_INCREF(p->locale); return 0; } static struct PyMethodDef __pyx_methods_10_zope_ucol_Collator[] = { {"key", (PyCFunction)__pyx_f_10_zope_ucol_8Collator_key, METH_VARARGS|METH_KEYWORDS, __pyx_doc_10_zope_ucol_8Collator_key}, {"cmp", (PyCFunction)__pyx_f_10_zope_ucol_8Collator_cmp, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; static struct PyMemberDef __pyx_members_10_zope_ucol_Collator[] = { {"locale", T_OBJECT, offsetof(struct __pyx_obj_10_zope_ucol_Collator, locale), READONLY, 0}, {"used_default_information", T_INT, offsetof(struct __pyx_obj_10_zope_ucol_Collator, used_default_information), READONLY, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Collator = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ 0, /*nb_divide*/ 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ 0, /*nb_coerce*/ 0, /*nb_int*/ 0, /*nb_long*/ 0, /*nb_float*/ 0, /*nb_oct*/ 0, /*nb_hex*/ 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ 0, /*nb_inplace_divide*/ 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ }; static PySequenceMethods __pyx_tp_as_sequence_Collator = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Collator = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Collator = { 0, /*bf_getreadbuffer*/ 0, /*bf_getwritebuffer*/ 0, /*bf_getsegcount*/ 0, /*bf_getcharbuffer*/ }; statichere PyTypeObject __pyx_type_10_zope_ucol_Collator = { PyObject_HEAD_INIT(0) 0, /*ob_size*/ "_zope_ucol.Collator", /*tp_name*/ sizeof(struct __pyx_obj_10_zope_ucol_Collator), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_10_zope_ucol_Collator, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ &__pyx_tp_as_number_Collator, /*tp_as_number*/ &__pyx_tp_as_sequence_Collator, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Collator, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Collator, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ "Compute a collation key for a unicode string.\n ", /*tp_doc*/ __pyx_tp_traverse_10_zope_ucol_Collator, /*tp_traverse*/ __pyx_tp_clear_10_zope_ucol_Collator, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_10_zope_ucol_Collator, /*tp_methods*/ __pyx_members_10_zope_ucol_Collator, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_10_zope_ucol_Collator, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ }; static struct PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; DL_EXPORT(void) init_zope_ucol(void); /*proto*/ DL_EXPORT(void) init_zope_ucol(void) { PyObject *__pyx_1 = 0; __pyx_m = Py_InitModule4("_zope_ucol", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION); if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; goto __pyx_L1;}; __pyx_b = PyImport_AddModule("__builtin__"); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; goto __pyx_L1;}; if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; goto __pyx_L1;}; if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; goto __pyx_L1;}; if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; goto __pyx_L1;}; __pyx_type_10_zope_ucol_UCharString.tp_free = _PyObject_GC_Del; if (PyType_Ready(&__pyx_type_10_zope_ucol_UCharString) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} if (PyObject_SetAttrString(__pyx_m, "UCharString", (PyObject *)&__pyx_type_10_zope_ucol_UCharString) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} __pyx_ptype_10_zope_ucol_UCharString = &__pyx_type_10_zope_ucol_UCharString; __pyx_type_10_zope_ucol_Collator.tp_free = _PyObject_GC_Del; if (PyType_Ready(&__pyx_type_10_zope_ucol_Collator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; goto __pyx_L1;} if (PyObject_SetAttrString(__pyx_m, "Collator", (PyObject *)&__pyx_type_10_zope_ucol_Collator) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; goto __pyx_L1;} __pyx_ptype_10_zope_ucol_Collator = &__pyx_type_10_zope_ucol_Collator; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":18 */ __pyx_1 = __Pyx_Import(__pyx_n_sys, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} if (PyObject_SetAttr(__pyx_m, __pyx_n_sys, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; /* "/home/jim/p/zope.ucol/trunk/src/zope/ucol/_zope_ucol.pyx":190 */ return; __pyx_L1:; Py_XDECREF(__pyx_1); __Pyx_AddTraceback("_zope_ucol"); } static char *__pyx_filenames[] = { "_zope_ucol.pyx", }; statichere char **__pyx_f = __pyx_filenames; /* Runtime support code */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { PyObject *__import__ = 0; PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; __import__ = PyObject_GetAttrString(__pyx_b, "__import__"); if (!__import__) goto bad; if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; module = PyObject_CallFunction(__import__, "OOOO", name, global_dict, empty_dict, list); bad: Py_XDECREF(empty_list); Py_XDECREF(__import__); Py_XDECREF(empty_dict); return module; } static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { PyObject *result; result = PyObject_GetAttr(dict, name); if (!result) PyErr_SetObject(PyExc_NameError, name); return result; } static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { Py_XINCREF(type); Py_XINCREF(value); Py_XINCREF(tb); /* First, check the traceback argument, replacing None with NULL. */ if (tb == Py_None) { Py_DECREF(tb); tb = 0; } else if (tb != NULL && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto raise_error; } /* Next, replace a missing value with None */ if (value == NULL) { value = Py_None; Py_INCREF(value); } /* Next, repeatedly, replace a tuple exception with its first item */ while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { PyObject *tmp = type; type = PyTuple_GET_ITEM(type, 0); Py_INCREF(type); Py_DECREF(tmp); } if (PyString_Check(type)) ; else if (PyClass_Check(type)) ; /*PyErr_NormalizeException(&type, &value, &tb);*/ else if (PyInstance_Check(type)) { /* Raising an instance. The value should be a dummy. */ if (value != Py_None) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto raise_error; } else { /* Normalize to raise , */ Py_DECREF(value); value = type; type = (PyObject*) ((PyInstanceObject*)type)->in_class; Py_INCREF(type); } } else { /* Not something you can raise. You get an exception anyway, just not what you specified :-) */ PyErr_Format(PyExc_TypeError, "exceptions must be strings, classes, or " "instances, not %s", type->ob_type->tp_name); goto raise_error; } PyErr_Restore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { while (t->p) { *t->p = PyString_InternFromString(t->s); if (!*t->p) return -1; ++t; } return 0; } static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); if (!*t->p) return -1; ++t; } return 0; } #include "compile.h" #include "frameobject.h" #include "traceback.h" static void __Pyx_AddTraceback(char *funcname) { PyObject *py_srcfile = 0; PyObject *py_funcname = 0; PyObject *py_globals = 0; PyObject *empty_tuple = 0; PyObject *empty_string = 0; PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; py_srcfile = PyString_FromString(__pyx_filename); if (!py_srcfile) goto bad; py_funcname = PyString_FromString(funcname); if (!py_funcname) goto bad; py_globals = PyModule_GetDict(__pyx_m); if (!py_globals) goto bad; empty_tuple = PyTuple_New(0); if (!empty_tuple) goto bad; empty_string = PyString_FromString(""); if (!empty_string) goto bad; py_code = PyCode_New( 0, /*int argcount,*/ 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ empty_string, /*PyObject *code,*/ empty_tuple, /*PyObject *consts,*/ empty_tuple, /*PyObject *names,*/ empty_tuple, /*PyObject *varnames,*/ empty_tuple, /*PyObject *freevars,*/ empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ __pyx_lineno, /*int firstlineno,*/ empty_string /*PyObject *lnotab*/ ); if (!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_Get(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = __pyx_lineno; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); Py_XDECREF(empty_tuple); Py_XDECREF(empty_string); Py_XDECREF(py_code); Py_XDECREF(py_frame); } zope.ucol-1.0.2/src/zope/ucol/_zope_ucol.pyx0000644000076400017500000001423710357043234016472 0ustar jim############################################################################## # # Copyright (c) 2004 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Simple wrapper for ICU ucol API $Id$ """ import sys cdef extern from "unicode/utypes.h": cdef enum UErrorCode: U_USING_DEFAULT_WARNING = -127 U_USING_FALLBACK_WARNING = -128 ctypedef int int32_t ctypedef char uint8_t int U_FAILURE(UErrorCode status) UErrorCode U_ZERO_ERROR cdef extern from "unicode/utf.h": ctypedef int UChar ctypedef int UChar32 cdef extern from "unicode/ustring.h": UChar *u_strFromUTF32(UChar *dest, int32_t destCapacity, int32_t *pDestLength, UChar32 *src, int32_t srcLength, UErrorCode *status) cdef extern from "unicode/ucol.h": ctypedef struct UCollator: pass UCollator *ucol_open(char *locale, UErrorCode *status) void ucol_close(UCollator *collator) int32_t ucol_getSortKey(UCollator *coll, UChar *source, int32_t sourceLength, uint8_t *result, int32_t resultLength ) int ucol_strcoll(UCollator *coll, UChar *source, int32_t sourceLength, UChar *target, int32_t targetLength) cdef extern from "Python.h": int PyUnicode_Check(ob) int PyString_Check(ob) ctypedef int Py_UNICODE Py_UNICODE *PyUnicode_AS_UNICODE(ob) int PyUnicode_GET_SIZE(ob) char *PyString_AS_STRING(ob) void *PyMem_Malloc(int size) void PyMem_Free(void *p) object PyString_FromStringAndSize(char *v, int l) cdef class UCharString: """Wrapper for ICU UChar arrays """ cdef UChar *data cdef readonly int32_t length cdef readonly object base cdef readonly int need_to_free def __new__(self, text): cdef int32_t buffsize cdef UErrorCode status cdef Py_UNICODE *str cdef int length if not PyUnicode_Check(text): if PyString_Check(text): text = unicode(text) assert PyUnicode_Check(text) else: raise TypeError("Expected unicode string") length = PyUnicode_GET_SIZE(text) str = PyUnicode_AS_UNICODE(text) if sizeof(Py_UNICODE) == 2: self.data = str self.length = length self.base = text self.need_to_free = 0 else: buffsize = 2*length + 1 self.data = PyMem_Malloc(buffsize*sizeof(UChar)) if self.data == NULL: raise MemoryError status = 0 u_strFromUTF32(self.data, buffsize, &(self.length), str, length, &status) assert self.length <= buffsize self.need_to_free = 1 if U_FAILURE(status): raise ValueError( "Couldn't convert Python unicode data to ICU unicode data." ) def __dealloc__(self): if self.need_to_free and self.data != NULL: PyMem_Free(self.data) self.data = NULL cdef class Collator: """Compute a collation key for a unicode string. """ cdef UCollator *collator cdef readonly object locale cdef readonly int used_default_information def __new__(self, locale): cdef UCollator *collator cdef UErrorCode status if not PyString_Check(locale): raise TypeError("String locale expected") status = U_ZERO_ERROR collator = ucol_open(PyString_AS_STRING(locale), &status) if U_FAILURE(status): raise ValueError("Couldn't create a collator") self.collator = collator self.locale = locale if (status == U_USING_DEFAULT_WARNING or status == U_USING_FALLBACK_WARNING): status = 1 self.used_default_information = status def __dealloc__(self): if self.collator != NULL: ucol_close(self.collator) def key(self, text): """Compute a collation key for the given unicode text. Of course, the key is only valid for the given locale. """ cdef char *buffer cdef int32_t bufsize cdef int32_t size icutext = UCharString(text) bufsize = (icutext).length*2+10 # the +1 below is needed to avoid an apprent buffer overflow bug in ICU buffer = PyMem_Malloc(bufsize +1) if buffer == NULL: raise MemoryError size = ucol_getSortKey(self.collator, (icutext).data, (icutext).length, buffer, bufsize) while size > bufsize: bufsize = size PyMem_Free(buffer) buffer = PyMem_Malloc(bufsize +1) # See above +1 if buffer == NULL: raise MemoryError size = ucol_getSortKey(self.collator, (icutext).data, (icutext).length, buffer, bufsize) result = PyString_FromStringAndSize(buffer, size) PyMem_Free(buffer) return result def cmp(self, o1, o2): u1 = UCharString(o1) u2 = UCharString(o2) return ucol_strcoll( self.collator, (u1).data, (u1).length, (u2).data, (u2).length, ) zope.ucol-1.0.2/src/zope/ucol/localeadapter.py0000664000076400007640000000260010514737452017450 0ustar jimjim############################################################################## # # Copyright (c) 2004 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Trivial adapter that adapts a zope.i18n locale to a collator This adapter takes an object that has a getLocaleID method that returns a locale string. It returns a Collator for the given locale: >>> class Locale: ... def __init__(self, id): ... self.id = id ... def getLocaleID(self): ... return self.id >>> collator = LocaleCollator(Locale('da_DK')) >>> collator.__class__.__name__ 'Collator' >>> collator.locale 'da_DK' Note that we're not declaring any interfaces so as to avoid creating a dependency on zope.i18n.locales. $Id: localeadapter.py 67613 2006-04-26 08:21:40Z dobe $ """ from zope.ucol import Collator def LocaleCollator(locale): return Collator(str(locale.getLocaleID())) zope.ucol-1.0.2/src/zope/ucol/tests.py0000644000076400017500000000400710356556301015303 0ustar jim############################################################################## # # Copyright (c) 2004 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """XXX short summary goes here. $Id: tests.py 40673 2005-12-09 22:09:28Z jim $ """ import unittest from zope.testing import doctest def type_errors(): """ You can pass unicode strings, or strings: >>> from zope.ucol import Collator >>> c = Collator('root') >>> c.key(u"Hello") == c.key("Hello") True >>> c.cmp(u"Hello", "Hello") 0 As long as the strings can be decoded as ASCII: >>> c.key("Hello\xfa") Traceback (most recent call last): ... UnicodeDecodeError: 'ascii' codec can't decode byte 0xfa in position 5: ordinal not in range(128) >>> c.cmp(u"Hello", "Hello\xfa") Traceback (most recent call last): ... UnicodeDecodeError: 'ascii' codec can't decode byte 0xfa in position 5: ordinal not in range(128) And you can't pass a non-string: >>> c.key(0) Traceback (most recent call last): ... TypeError: Expected unicode string >>> c.cmp(u"Hello", 0) Traceback (most recent call last): ... TypeError: Expected unicode string """ def test_suite(): return unittest.TestSuite(( doctest.DocTestSuite(optionflags=doctest.NORMALIZE_WHITESPACE), doctest.DocFileSuite('README.txt', optionflags=doctest.NORMALIZE_WHITESPACE), doctest.DocTestSuite('zope.ucol.localeadapter') )) if __name__ == '__main__': unittest.main(defaultTest='test_suite') zope.ucol-1.0.2/src/zope/__init__.py0000644000076400017500000000011310345603657014735 0ustar jimfrom pkgutil import extend_path __path__ = extend_path(__path__, __name__) zope.ucol-1.0.2/src/zope.ucol.egg-info/0000775000076400007640000000000010515001056015752 5ustar jimjimzope.ucol-1.0.2/src/zope.ucol.egg-info/PKG-INFO0000664000076400007640000001065510515001056017056 0ustar jimjimMetadata-Version: 1.0 Name: zope.ucol Version: 1.0.2 Summary: Python access to ICU text collation Home-page: http://www.python.org/pypi/zope.ucol Author: Jim Fulton Author-email: jim@zope.com License: ZPL 2.1 Description: ************************************* Locale-based text collation using ICU ************************************* This package provides a Python interface to the `International Component for Unicode (ICU) `_. .. contents:: Change History ************** 1.0.2 (2006-10-16) ================== Fixed setup file problems. 1.0.1 (2006-10-16) ================== Added missing import to setup.py. 1.0 (2006-10-16) ================ Initial version. Installation ************ zope.ucol is installed via setup.py in the usual way. You must have ICU installed. If ICU isn't installed in the usual places for include files and libraries on your system, you can provide command-line options to setup.py when building the extensions, as in:: python2.4 setup.py build_ext \ -I/home/jim/p/z4i/jim-icu/var/opt/icu/include \ -L/home/jim/p/z4i/jim-icu/var/opt/icu/lib \ -R/home/jim/p/z4i/jim-icu/var/opt/icu/lib python2.4 setup.py install Note that if the libraries are in an unusual place, you will want to specify their location using the -R option so you don't have to specify it at run-time. Detailed Documentation ********************** Locale-based text collation using ICU ===================================== The zope.ucol package provides a minimal Pythonic wrapper around the u_col C API of the International Components for Unicode (ICU) library. It provides locale-based text collation. To perform collation, you need to create a collator key factory for your locale. We'll use the special "root" locale in this example: >>> import zope.ucol >>> collator = zope.ucol.Collator("root") The collator has a key method for creating collation keys from unicode strings. The method can be passed as the key argument to list.sort or to the built-in sorted function. >>> sorted([u'Sam', u'sally', u'Abe', u'alice', u'Terry', u'tim', ... u'\U00023119', u'\u62d5'], key=collator.key) [u'Abe', u'alice', u'sally', u'Sam', u'Terry', u'tim', u'\u62d5', u'\U00023119'] There is a cmp method for comparing 2 unicode strings, which can also be used when sorting: >>> sorted([u'Sam', u'sally', u'Abe', u'alice', u'Terry', u'tim', ... u'\U00023119', u'\u62d5'], collator.cmp) [u'Abe', u'alice', u'sally', u'Sam', u'Terry', u'tim', u'\u62d5', u'\U00023119'] Note that it is almost always more efficient to pass the key method to sorting functions, rather than the cmp method. The cmp method is more efficient in the special case that strings are long and few and when they tend to differ at their beginnings. This is because computing the entire key can be much more expensive than comparison when the order can be determined based on analyzing a small portion of the original strings. Collator attributes ------------------- You can ask a collator for it's locale: >>> collator.locale 'root' and you can find out whether default collation information was used: >>> collator.used_default_information 0 >>> collator = zope.ucol.Collator("eek") >>> collator.used_default_information 1 Download ********************** Keywords: internationalization Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Internationalization zope.ucol-1.0.2/src/zope.ucol.egg-info/SOURCES.txt0000664000076400007640000000102610515001056017635 0ustar jimjimINSTALL.txt README.txt buildout.cfg setup.py test.py icu/README.txt icu/setup.py icu/src/zc/__init__.py icu/src/zc/recipe/__init__.py icu/src/zc/recipe/icu/__init__.py src/zope/__init__.py src/zope.ucol.egg-info/PKG-INFO src/zope.ucol.egg-info/SOURCES.txt src/zope.ucol.egg-info/dependency_links.txt src/zope.ucol.egg-info/not-zip-safe src/zope.ucol.egg-info/top_level.txt src/zope/ucol/README.txt src/zope/ucol/__init__.py src/zope/ucol/_zope_ucol.c src/zope/ucol/_zope_ucol.pyx src/zope/ucol/localeadapter.py src/zope/ucol/tests.py zope.ucol-1.0.2/src/zope.ucol.egg-info/dependency_links.txt0000664000076400007640000000000110515001056022020 0ustar jimjim zope.ucol-1.0.2/src/zope.ucol.egg-info/not-zip-safe0000664000076400007640000000000110514740144020207 0ustar jimjim zope.ucol-1.0.2/src/zope.ucol.egg-info/top_level.txt0000664000076400007640000000000510515001056020477 0ustar jimjimzope zope.ucol-1.0.2/INSTALL.txt0000664000076400007640000000121510514737452013440 0ustar jimjimInstallation ************ zope.ucol is installed via setup.py in the usual way. You must have ICU installed. If ICU isn't installed in the usual places for include files and libraries on your system, you can provide command-line options to setup.py when building the extensions, as in:: python2.4 setup.py build_ext \ -I/home/jim/p/z4i/jim-icu/var/opt/icu/include \ -L/home/jim/p/z4i/jim-icu/var/opt/icu/lib \ -R/home/jim/p/z4i/jim-icu/var/opt/icu/lib python2.4 setup.py install Note that if the libraries are in an unusual place, you will want to specify their location using the -R option so you don't have to specify it at run-time. zope.ucol-1.0.2/README.txt0000664000076400007640000000077710515000704013263 0ustar jimjim************************************* Locale-based text collation using ICU ************************************* This package provides a Python interface to the `International Component for Unicode (ICU) `_. .. contents:: Change History ************** 1.0.2 (2006-10-16) ================== Fixed setup file problems. 1.0.1 (2006-10-16) ================== Added missing import to setup.py. 1.0 (2006-10-16) ================ Initial version. zope.ucol-1.0.2/buildout.cfg0000664000076400007640000000155310514737452014106 0ustar jimjim# This is a bit awkward. We can't build zope.ucol as a develop egg as # we normally would becase: # # 1. We need to build icu first # # 2. We need to pass build_ext options. # # We don't have the machinery we need to automate this yet. :( # For now, we need to manually create an sdist and build zope.ucol # with the custom recipe. It would help a lot of setup develop # accepted build_ext options. # # Maybe we should just write a special recipe that build zope.ucol # manually. [buildout] develop = icu parts = icu zope.ucol test [icu] recipe = zc.recipe.icu version = 3.2 [zope.ucol] find-links = dist index = dist recipe = zc.recipe.egg:custom egg = zope.ucol include-dirs = ${buildout:directory}/parts/icu/include library-dirs = ${buildout:directory}/parts/icu/lib rpath = ${buildout:directory}/parts/icu/lib [test] recipe = zc.recipe.testrunner eggs = zope.ucol zope.ucol-1.0.2/setup.py0000664000076400007640000000461610515000626013276 0ustar jimjim############################################################################## # # Copyright (c) 2004 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Setup for zope.ucol package $Id: setup.py 70722 2006-10-16 17:20:28Z jim $ """ import os, sys from distutils.core import setup, Extension try: from setuptools import setup, Extension except: setuptools_options = {} else: setuptools_options = dict( zip_safe = False, include_package_data = True, ) def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() if sys.platform.startswith('win'): libraries = ['icuin', 'icuuc', 'icudt'] else: libraries=['icui18n', 'icuuc', 'icudata'] name = 'zope.ucol' setup(name=name, version='1.0.2', author = "Jim Fulton", author_email = "jim@zope.com", description = "Python access to ICU text collation", long_description=( read('README.txt') + '\n' + read('INSTALL.txt') + '\n' + 'Detailed Documentation\n' '**********************\n' + '\n' + read('src', 'zope', 'ucol', 'README.txt') + '\n' + 'Download\n' '**********************\n' ), license = "ZPL 2.1", keywords = "internationalization", url = 'http://www.python.org/pypi/zope.ucol', ext_modules=[ Extension('zope.ucol._zope_ucol', ['src/zope/ucol/_zope_ucol.c'], libraries=libraries, ) ], packages=["zope", "zope.ucol"], package_dir = {'': 'src'}, classifiers = [ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: Zope Public License', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Internationalization', ], **setuptools_options) zope.ucol-1.0.2/test.py0000644000076400017500000000167510345603657012427 0ustar jim#!/home/jim/p/z4i/jim-icu/var/opt/python/bin/python -u ############################################################################## # # Copyright (c) 2004 Zope Corporation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Run tests in a Zope instance home. $Id: test.py 40612 2005-12-06 20:52:16Z jim $ """ import sys sys.path.insert(0, 'src') from zope.testing import testrunner defaults = '--test-path src -szope.ucol'.split() status = testrunner.run(defaults) sys.exit(status) zope.ucol-1.0.2/PKG-INFO0000664000076400007640000001065510515001056012657 0ustar jimjimMetadata-Version: 1.0 Name: zope.ucol Version: 1.0.2 Summary: Python access to ICU text collation Home-page: http://www.python.org/pypi/zope.ucol Author: Jim Fulton Author-email: jim@zope.com License: ZPL 2.1 Description: ************************************* Locale-based text collation using ICU ************************************* This package provides a Python interface to the `International Component for Unicode (ICU) `_. .. contents:: Change History ************** 1.0.2 (2006-10-16) ================== Fixed setup file problems. 1.0.1 (2006-10-16) ================== Added missing import to setup.py. 1.0 (2006-10-16) ================ Initial version. Installation ************ zope.ucol is installed via setup.py in the usual way. You must have ICU installed. If ICU isn't installed in the usual places for include files and libraries on your system, you can provide command-line options to setup.py when building the extensions, as in:: python2.4 setup.py build_ext \ -I/home/jim/p/z4i/jim-icu/var/opt/icu/include \ -L/home/jim/p/z4i/jim-icu/var/opt/icu/lib \ -R/home/jim/p/z4i/jim-icu/var/opt/icu/lib python2.4 setup.py install Note that if the libraries are in an unusual place, you will want to specify their location using the -R option so you don't have to specify it at run-time. Detailed Documentation ********************** Locale-based text collation using ICU ===================================== The zope.ucol package provides a minimal Pythonic wrapper around the u_col C API of the International Components for Unicode (ICU) library. It provides locale-based text collation. To perform collation, you need to create a collator key factory for your locale. We'll use the special "root" locale in this example: >>> import zope.ucol >>> collator = zope.ucol.Collator("root") The collator has a key method for creating collation keys from unicode strings. The method can be passed as the key argument to list.sort or to the built-in sorted function. >>> sorted([u'Sam', u'sally', u'Abe', u'alice', u'Terry', u'tim', ... u'\U00023119', u'\u62d5'], key=collator.key) [u'Abe', u'alice', u'sally', u'Sam', u'Terry', u'tim', u'\u62d5', u'\U00023119'] There is a cmp method for comparing 2 unicode strings, which can also be used when sorting: >>> sorted([u'Sam', u'sally', u'Abe', u'alice', u'Terry', u'tim', ... u'\U00023119', u'\u62d5'], collator.cmp) [u'Abe', u'alice', u'sally', u'Sam', u'Terry', u'tim', u'\u62d5', u'\U00023119'] Note that it is almost always more efficient to pass the key method to sorting functions, rather than the cmp method. The cmp method is more efficient in the special case that strings are long and few and when they tend to differ at their beginnings. This is because computing the entire key can be much more expensive than comparison when the order can be determined based on analyzing a small portion of the original strings. Collator attributes ------------------- You can ask a collator for it's locale: >>> collator.locale 'root' and you can find out whether default collation information was used: >>> collator.used_default_information 0 >>> collator = zope.ucol.Collator("eek") >>> collator.used_default_information 1 Download ********************** Keywords: internationalization Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Internationalization zope.ucol-1.0.2/setup.cfg0000664000076400007640000000007310515001056013374 0ustar jimjim[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0