[Zope-CVS] SVN: zope.ucol/trunk/src/zope/ucol/ Moved the documentation out to a text file.

Jim Fulton jim at zope.com
Fri Dec 9 17:09:29 EST 2005


Log message for revision 40673:
  Moved the documentation out to a text file.
  
  Added an adapter from zope.i18n.interfaces.locale.ILocale to
  zope.i18n.interfaces.locale.ICollator. This was done without interface
  declarations to avoid a dependency on zope.i18n.
  

Changed:
  A   zope.ucol/trunk/src/zope/ucol/README.txt
  U   zope.ucol/trunk/src/zope/ucol/__init__.py
  A   zope.ucol/trunk/src/zope/ucol/localeadapter.py
  U   zope.ucol/trunk/src/zope/ucol/tests.py

-=-
Added: zope.ucol/trunk/src/zope/ucol/README.txt
===================================================================
--- zope.ucol/trunk/src/zope/ucol/README.txt	2005-12-09 21:13:42 UTC (rev 40672)
+++ zope.ucol/trunk/src/zope/ucol/README.txt	2005-12-09 22:09:28 UTC (rev 40673)
@@ -0,0 +1,53 @@
+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


Property changes on: zope.ucol/trunk/src/zope/ucol/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zope.ucol/trunk/src/zope/ucol/__init__.py
===================================================================
--- zope.ucol/trunk/src/zope/ucol/__init__.py	2005-12-09 21:13:42 UTC (rev 40672)
+++ zope.ucol/trunk/src/zope/ucol/__init__.py	2005-12-09 22:09:28 UTC (rev 40673)
@@ -13,54 +13,8 @@
 ##############################################################################
 """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.
+See README.txt in the package.
 
-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.
-
-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
-
 $Id$
 """
 

Added: zope.ucol/trunk/src/zope/ucol/localeadapter.py
===================================================================
--- zope.ucol/trunk/src/zope/ucol/localeadapter.py	2005-12-09 21:13:42 UTC (rev 40672)
+++ zope.ucol/trunk/src/zope/ucol/localeadapter.py	2005-12-09 22:09:28 UTC (rev 40673)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# 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$
+"""
+from zope.ucol import Collator
+
+def LocaleCollator(locale):
+    return Collator(locale.getLocaleID())
+    


Property changes on: zope.ucol/trunk/src/zope/ucol/localeadapter.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zope.ucol/trunk/src/zope/ucol/tests.py
===================================================================
--- zope.ucol/trunk/src/zope/ucol/tests.py	2005-12-09 21:13:42 UTC (rev 40672)
+++ zope.ucol/trunk/src/zope/ucol/tests.py	2005-12-09 22:09:28 UTC (rev 40673)
@@ -60,8 +60,9 @@
 def test_suite():
     return unittest.TestSuite((
         doctest.DocTestSuite(optionflags=doctest.NORMALIZE_WHITESPACE),
-        doctest.DocTestSuite('zope.ucol',
+        doctest.DocFileSuite('README.txt',
                              optionflags=doctest.NORMALIZE_WHITESPACE),
+        doctest.DocTestSuite('zope.ucol.localeadapter')
         ))
 
 if __name__ == '__main__':



More information about the Zope-CVS mailing list