--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,9 @@
+
+syntax: regexp
+^develop-eggs$
+syntax: regexp
+^zope\.testing-3\.5\.1-py2\.4\.egg$
+syntax: regexp
+^dist$
+syntax: regexp
+^build$
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CHANGES Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,3 @@
+* '0.1'
+ - initial version created by IngeniSkel
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,281 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,14 @@
+==================
+ztfy.utils package
+==================
+
+You may find documentation in:
+
+- Global README.txt: ztfy/utils/docs/README.txt
+- General: ztfy/utils/docs
+- Technical: ztfy/utils/doctests
+
+This package is created and maintained by Thierry Florac_.
+
+.. _Thierry Florac: mailto:tflorac@ulthar.net
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/buildout Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+
+import sys
+sys.path[0:0] = [
+ '/var/local/src/ztfy/eggs/setuptools-0.6c9-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zc.buildout-1.1.1-py2.5.egg',
+ ]
+
+import zc.buildout.buildout
+
+if __name__ == '__main__':
+ zc.buildout.buildout.main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/test Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,96 @@
+#!/usr/bin/python
+
+import sys
+sys.path[0:0] = [
+ '/var/local/src/ztfy/ztfy.utils',
+ '/var/local/src/ztfy/eggs/zope.testing-3.7.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.interface-3.4.1-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/setuptools-0.6c9-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.zapi-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.interface-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.publisher-3.5.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.traversing-3.5.0a4-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.component-3.5.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.security-3.5.2-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/zodbcode-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/ZODB3-3.9.0_dev_r77011-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/zope.schema-3.5.0a1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.publisher-3.5.4-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.pagetemplate-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.location-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.i18n-3.5.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.deprecation-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.deferredimport-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.datetime-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.contenttype-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.configuration-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.publication-3.5.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.pagetemplate-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.container-3.6.1-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/zope.app.component-3.5.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.proxy-3.4.2-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/zope.i18nmessageid-3.4.3-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/zope.event-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.exceptions-3.5.2-py2.5.egg',
+ '/var/local/src/ztfy/eggs/pytz-2008h-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zdaemon-2.0.2-py2.5.egg',
+ '/var/local/src/ztfy/eggs/ZConfig-2.6.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.tal-3.5.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.tales-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.security-3.5.2-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.exception-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.error-3.5.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.applicationcontrol-3.4.3-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.http-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.error-3.5.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.size-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.dublincore-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.copypastemove-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.broken-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.filerepresentation-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.lifecycleevent-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.dottedname-3.4.2-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.cachedescriptors-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.thread-3.4-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.formlib-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.annotation-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.form-3.6.3-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.authentication-3.4.3-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.appsetup-3.8.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/RestrictedPython-3.4.2-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.testing-3.5.6-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.hookable-3.4.0-py2.5-linux-i686.egg',
+ '/var/local/src/ztfy/eggs/zope.app.principalannotation-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.zcmlfiles-3.4.3-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.basicskin-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.session-3.5.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.folder-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.dependable-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.debug-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.schema-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.wsgi-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.rotterdam-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.zopeappgenerations-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.locales-3.4.5-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.i18n-3.4.4-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.generations-3.4.1-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.content-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.modulealias-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.session-3.7.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.minmax-1.1.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.app.renderer-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/zope.structuredtext-3.4.0-py2.5.egg',
+ '/var/local/src/ztfy/eggs/docutils-0.5-py2.5.egg',
+ ]
+
+import os
+sys.argv[0] = os.path.abspath(sys.argv[0])
+os.chdir('/var/local/src/ztfy/ztfy.utils/parts/test')
+
+
+import zope.testing.testrunner
+
+if __name__ == '__main__':
+ zope.testing.testrunner.run([
+ '--test-path', '/var/local/src/ztfy/ztfy.utils',
+ ])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bootstrap.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2006 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/buildout.cfg Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,15 @@
+[buildout]
+develop = .
+parts = package test
+find-links = http://download.zope.org/distribution/
+newest = false
+eggs-directory = /var/local/src/ztfy/eggs
+
+[package]
+recipe = zc.recipe.egg
+eggs = ztfy.utils
+ zope.app.zapi
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = ztfy.utils [test]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.cfg Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,7 @@
+[egg_info]
+tag_build = dev
+tag_svn_revision = true
+
+[aliases]
+iw_upload = register sdist bdist_egg upload -r http://products.ingeniweb.com/catalog
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2008 'Thierry Florac'
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+This module contains the tool of ztfy.utils
+"""
+import os
+from setuptools import setup, find_packages
+
+version = '0.1'
+
+README = os.path.join(os.path.dirname(__file__),
+ 'ztfy',
+ 'utils', 'docs', 'README.txt')
+
+long_description = open(README).read() + '\n\n'
+
+tests_require = [
+ 'zope.testing',
+ ]
+
+setup(name='ztfy.utils',
+ version=version,
+ description="ZTFY utility functions and classes for Zope3",
+ long_description=long_description,
+ classifiers=[
+ "Programming Language :: Python",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
+ keywords='ZTFY utilities for Zope3',
+ author='Thierry Florac',
+ author_email='tflorac@ulthar.net',
+ url='',
+ license='ZPL',
+ packages=find_packages(exclude=['ez_setup']),
+ namespace_packages=['ztfy'],
+ include_package_data=True,
+ zip_safe=False,
+ # uncomment this to be able to run tests with setup.py
+ #test_suite = "ztfy.utils.tests.test_utilsdocs.test_suite",
+ tests_require=tests_require,
+ extras_require=dict(test=tests_require),
+ install_requires=[
+ 'setuptools',
+ # -*- Extra requirements: -*-
+ 'zope.app.zapi',
+ ],
+ entry_points="""
+ # -*- Entry points: -*-
+ """,
+ )
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,2 @@
+Test accentué
+Pour import dans Zope...
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/PKG-INFO Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,39 @@
+Metadata-Version: 1.0
+Name: ztfy.utils
+Version: 0.1dev
+Summary: ZTFY utility functions and classes for Zope3
+Home-page: UNKNOWN
+Author: Thierry Florac
+Author-email: tflorac@ulthar.net
+License: ZPL
+Description: ==================
+ ztfy.utils package
+ ==================
+
+ .. contents::
+
+ What is ztfy.utils ?
+ ====================
+
+ ztfy.utils is a set of classes and functions which can be used to handle many small operations.
+
+ Internal sub-packages include :
+ - date : convert dates to unicode ISO format, parse ISO datetime, convert date to datetime
+ - request : get current request, get request annotations, get and set request data via annotations
+ - security : get unproxied value of a given object ; can be applied to lists or dicts
+ - timezone : convert datetime to a given timezone
+ - traversing : get object parents until a given interface is implemented
+ - unicode : convert any text to unicode for easy storage
+
+
+ How to use ztfy.utils ?
+ =======================
+
+ A set of ztfy.utils usage are given as doctests in ztfy/utils/doctests/README.txt
+
+
+
+Keywords: ZTFY utilities for Zope3
+Platform: UNKNOWN
+Classifier: Programming Language :: Python
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/SOURCES.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,26 @@
+README.txt
+setup.cfg
+setup.py
+ztfy/__init__.py
+ztfy.utils.egg-info/PKG-INFO
+ztfy.utils.egg-info/SOURCES.txt
+ztfy.utils.egg-info/dependency_links.txt
+ztfy.utils.egg-info/entry_points.txt
+ztfy.utils.egg-info/namespace_packages.txt
+ztfy.utils.egg-info/not-zip-safe
+ztfy.utils.egg-info/paster_plugins.txt
+ztfy.utils.egg-info/requires.txt
+ztfy.utils.egg-info/top_level.txt
+ztfy/utils/__init__.py
+ztfy/utils/date.py
+ztfy/utils/file.py
+ztfy/utils/request.py
+ztfy/utils/security.py
+ztfy/utils/timezone.py
+ztfy/utils/traversing.py
+ztfy/utils/unicode.py
+ztfy/utils/docs/README.txt
+ztfy/utils/doctests/README.txt
+ztfy/utils/tests/__init__.py
+ztfy/utils/tests/test_utilsdocs.py
+ztfy/utils/tests/test_utilsdocstrings.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/dependency_links.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,1 @@
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/entry_points.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,3 @@
+
+ # -*- Entry points: -*-
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/namespace_packages.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,1 @@
+ztfy
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/not-zip-safe Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,1 @@
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/paster_plugins.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,1 @@
+PasteScript
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/requires.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,5 @@
+setuptools
+zope.app.zapi
+
+[test]
+zope.testing
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy.utils.egg-info/top_level.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,1 @@
+ztfy
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/__init__.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/__init__.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,29 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+from zope.i18nmessageid import MessageFactory
+_ = MessageFactory('ztfy.utils')
+
+
+from traversing import getParent
+from request import getRequest, getRequestPrincipal, getRequestData, setRequestData
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/configure.zcml Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,8 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="ztfy.utils">
+
+ <adapter
+ factory=".timezone.tzinfo" />
+
+</configure>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/date.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,78 @@
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+from datetime import datetime
+
+# import Zope3 interfaces
+
+# import local interfaces
+
+# import Zope3 packages
+from zope.datetime import parseDatetimetz
+
+# import local packages
+from timezone import gmtime
+
+
+def unidate(value):
+ """Get specified date converted to unicode ISO format
+
+ Dates are always assumed to be stored in GMT timezone
+
+ @param value: input date to convert to unicode
+ @type value: date or datetime
+ @return: input date converted to unicode
+ @rtype: unicode
+ """
+ if value is not None:
+ value = gmtime(value)
+ return unicode(value.isoformat('T'),'ascii')
+ return None
+
+
+def parsedate(value):
+ """Get date specified in unicode ISO format to Python datetime object
+
+ Dates are always assumed to be stored in GMT timezone
+
+ @param value: unicode date to be parsed
+ @type value: unicode
+ @return: the specified value, converted to datetime
+ @rtype: datetime
+ """
+ if value is not None:
+ return gmtime(parseDatetimetz(value))
+ return None
+
+
+def datetodatetime(value):
+ """Get datetime value converted from a date or datetime object
+
+ @param value: a date or datetime value to convert
+ @type value: date or datetime
+ @return: input value converted to datetime
+ @rtype: datetime
+ """
+ if type(value) is datetime:
+ return value
+ return datetime(value.year, value.month, value.day)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/docs/README.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,24 @@
+==================
+ztfy.utils package
+==================
+
+.. contents::
+
+What is ztfy.utils ?
+====================
+
+ztfy.utils is a set of classes and functions which can be used to handle many small operations.
+
+Internal sub-packages include :
+ - date : convert dates to unicode ISO format, parse ISO datetime, convert date to datetime
+ - request : get current request, get request annotations, get and set request data via annotations
+ - security : get unproxied value of a given object ; can be applied to lists or dicts
+ - timezone : convert datetime to a given timezone
+ - traversing : get object parents until a given interface is implemented
+ - unicode : convert any text to unicode for easy storage
+
+
+How to use ztfy.utils ?
+=======================
+
+A set of ztfy.utils usage are given as doctests in ztfy/utils/doctests/README.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/doctests/README.txt Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,103 @@
+==================
+ZTFY.utils package
+==================
+
+Introduction
+------------
+
+This package is composed of a set of utility functions, which in complement with zope.app.zapi
+package can facilite Zope management.
+
+
+Unicode functions
+-----------------
+
+While working with extended characters sets containing accentuated characters, it's necessary to
+conversing strings to UTF8 so that they can be used without any conversion problem.
+
+ >>> from ztfy.utils import unicode
+
+'translateString' is a utility function which can be used, for example, to generate an object's id
+without space and with accentuated characters converted to their unaccentuated version:
+
+ >>> sample = 'Mon titre accentué'
+ >>> unicode.translateString(sample)
+ u'mon titre accentue'
+
+Results are lower-cased by default ; this can be avoided be setting the 'forceLower' parameter
+to False:
+
+ >>> unicode.translateString(sample, forceLower=False)
+ u'Mon titre accentue'
+
+If input string can contain 'slashes' (/) or 'backslashes' (\), they are normally removed ;
+by using the 'escapeSlashes' parameter, the input string is splitted and only the last element is
+returned ; this is handy to handle filenames on Windows platform:
+
+ >>> sample = 'Autre / chaîne / accentuée'
+ >>> unicode.translateString(sample)
+ u'autre chaine accentuee'
+ >>> unicode.translateString(sample, escapeSlashes=True)
+ u'accentuee'
+ >>> sample = 'C:\\Program Files\\My Application\\test.txt'
+ >>> unicode.translateString(sample)
+ u'cprogram filesmy applicationtest.txt'
+ >>> unicode.translateString(sample, escapeSlashes=True)
+ u'test.txt'
+
+
+Dates functions
+---------------
+
+Dates functions are used to convert dates from/to string representation:
+
+ >>> from datetime import datetime
+ >>> from ztfy.utils import date
+ >>> now = datetime.fromtimestamp(1205000000)
+ >>> now
+ datetime.datetime(2008, 3, 8, 19, 13, 20)
+
+You can get an unicode representation of a date in ASCII format using 'unidate' fonction ; date is
+converted to GMT:
+
+ >>> udate = date.unidate(now)
+ >>> udate
+ u'2008-03-08T19:13:20+00:00'
+
+'parsedate' can be used to convert ASCII format into datetime:
+
+ >>> ddate = date.parsedate(udate)
+ >>> ddate
+ datetime.datetime(2008, 3, 8, 19, 13, 20, tzinfo=<StaticTzInfo 'GMT'>)
+
+'datetodatetime' can be used to convert a 'date' type to a 'datetime' value ; if a 'datetime' value
+is used as argument, it is returned 'as is':
+
+ >>> ddate.date()
+ datetime.date(2008, 3, 8)
+ >>> date.datetodatetime(ddate)
+ datetime.datetime(2008, 3, 8, 19, 13, 20, tzinfo=<StaticTzInfo 'GMT'>)
+ >>> date.datetodatetime(ddate.date())
+ datetime.datetime(2008, 3, 8, 0, 0)
+
+
+Timezones handling
+------------------
+
+Timezones handling game me headaches at first. I finally concluded that the best way (for me !) to handle
+TZ data was to store every datetime value in GMT timezone.
+As far as I know, there is no easy way to know the user's timezone from his request settings. So you can:
+- store this timezone in user's profile,
+- define a static server's timezone :-/
+
+My current default user's timezone is set to 'Europe/Paris' ; you should probably update this setting in
+'timezone.py' if you are located elsewhere.
+
+ >>> from ztfy.utils import timezone
+ >>> timezone.tztime(ddate)
+ datetime.datetime(2008, 3, 8, 20, 13, 20, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>)
+
+'gmtime' function can be used to convert a datetime to GMT:
+
+ >>> timezone.gmtime(now)
+ datetime.datetime(2008, 3, 8, 19, 13, 20, tzinfo=<StaticTzInfo 'GMT'>)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/file.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,47 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+
+# import Zope3 interfaces
+from zope.app.file.interfaces import IFile
+from zope.schema.interfaces import IBytes
+from z3c.form.interfaces import IFileWidget
+
+# import local interfaces
+
+# import Zope3 packages
+from zope import component
+from zope.app.file import File
+from zope.schema.fieldproperty import FieldProperty
+from z3c.form.converter import FileUploadDataConverter as BaseDataConverter
+
+# import local packages
+
+
+class FileUploadDataConverter(BaseDataConverter):
+
+ component.adapts(IBytes, IFileWidget)
+
+ def toWidgetValue(self, value):
+ return value or ''
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/overrides.zcml Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,8 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="ztfy.utils">
+
+ <adapter
+ factory=".file.FileUploadDataConverter" />
+
+</configure>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/request.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,74 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+
+# import Zope3 interfaces
+from zope.publisher.interfaces import IRequest
+from zope.annotation.interfaces import IAnnotations
+
+# import local interfaces
+
+# import Zope3 packages
+from zope.security.management import getInteraction
+
+# import local packages
+
+from ztfy.utils import _
+
+
+def getRequest():
+ """Extract request from current interaction"""
+ interaction = getInteraction()
+ for participation in interaction.participations:
+ if IRequest.providedBy(participation):
+ return participation
+ raise RuntimeError, _("No Request in interaction !")
+
+
+def getRequestPrincipal(request=None):
+ """Get principal from given request"""
+ if request is None:
+ request = getRequest()
+ return request.principal
+
+
+def getRequestAnnotations(request=None):
+ """Get annotations from given request"""
+ if request is None:
+ request = getRequest()
+ return IAnnotations(request)
+
+
+def getRequestData(key, request=None, default=None):
+ """Get request data, stored into request annotations"""
+ try:
+ annotations = getRequestAnnotations(request)
+ return annotations.get(key, default)
+ except:
+ return default
+
+
+def setRequestData(key, data, request=None):
+ annotations = getRequestAnnotations(request)
+ annotations[key] = data
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/security.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,47 @@
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+
+# import Zope3 interfaces
+
+# import local interfaces
+
+# import Zope3 packages
+from zope.security.proxy import removeSecurityProxy
+
+# import local packages
+
+
+def unproxied(value):
+ """Remove security proxies from given value ; if value is a list or dict, all elements are unproxied"""
+ if isinstance(value, list):
+ result = []
+ for v in value:
+ result.append(removeSecurityProxy(v))
+ elif isinstance(value, dict):
+ result = value.copy()
+ for v in value:
+ result[v] = removeSecurityProxy(value[v])
+ else:
+ result = removeSecurityProxy(value)
+ return result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/tests/__init__.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,1 @@
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/tests/test_utilsdocs.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2008 Thierry Florac
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+Generic Test case for ztfy.utils doctest
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+import doctest
+import sys
+import os
+
+from zope.testing import doctest
+
+current_dir = os.path.dirname(__file__)
+
+def doc_suite(test_dir, setUp=None, tearDown=None, globs=None):
+ """Returns a test suite, based on doctests found in /doctest."""
+ suite = []
+ if globs is None:
+ globs = globals()
+
+ flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE |
+ doctest.REPORT_ONLY_FIRST_FAILURE)
+
+ package_dir = os.path.split(test_dir)[0]
+ if package_dir not in sys.path:
+ sys.path.append(package_dir)
+
+ doctest_dir = os.path.join(package_dir, 'doctests')
+
+ # filtering files on extension
+ docs = [os.path.join(doctest_dir, doc) for doc in
+ os.listdir(doctest_dir) if doc.endswith('.txt')]
+
+ for test in docs:
+ suite.append(doctest.DocFileSuite(test, optionflags=flags,
+ globs=globs, setUp=setUp,
+ tearDown=tearDown,
+ module_relative=False))
+
+ return unittest.TestSuite(suite)
+
+def test_suite():
+ """returns the test suite"""
+ return doc_suite(current_dir)
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/tests/test_utilsdocstrings.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2008 Thierry Florac
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""
+Generic Test case for ztfy.utils doc strings
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+import doctest
+import sys
+import os
+
+from zope.testing import doctest
+
+current_dir = os.path.abspath(os.path.dirname(__file__))
+
+def doc_suite(test_dir, globs=None):
+ """Returns a test suite, based on doc tests strings found in /*.py"""
+ suite = []
+ if globs is None:
+ globs = globals()
+
+ flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE |
+ doctest.REPORT_ONLY_FIRST_FAILURE)
+
+ package_dir = os.path.split(test_dir)[0]
+ if package_dir not in sys.path:
+ sys.path.append(package_dir)
+
+ # filtering files on extension
+ docs = [doc for doc in
+ os.listdir(package_dir) if doc.endswith('.py')]
+ docs = [doc for doc in docs if not doc.startswith('__')]
+
+ for test in docs:
+ fd = open(os.path.join(package_dir, test))
+ content = fd.read()
+ fd.close()
+ if '>>> ' not in content:
+ continue
+ test = test.replace('.py', '')
+ location = 'ztfy.utils.%s' % test
+ suite.append(doctest.DocTestSuite(location, optionflags=flags,
+ globs=globs))
+
+ return unittest.TestSuite(suite)
+
+def test_suite():
+ """returns the test suite"""
+ return doc_suite(current_dir)
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/timezone.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+import pytz
+
+# import Zope3 interfaces
+from zope.interface import implementer
+from zope.interface.common.idatetime import ITZInfo
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+# import local interfaces
+
+# import Zope3 packages
+from zope import component
+
+# import local packages
+
+
+GMT = pytz.timezone('GMT')
+_tz = pytz.timezone('Europe/Paris')
+tz = _tz
+
+@implementer(ITZInfo)
+@component.adapter(IBrowserRequest)
+def tzinfo(request=None):
+ return tz
+
+
+def tztime(value):
+ if not value.tzinfo:
+ value = GMT.localize(value)
+ return value.astimezone(tz)
+
+
+def gmtime(value):
+ if not value.tzinfo:
+ value = GMT.localize(value)
+ return value.astimezone(GMT)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/traversing.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,47 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+
+# import Zope3 interfaces
+
+# import local interfaces
+
+# import Zope3 packages
+from zope.interface import Interface
+from zope.app import zapi
+
+# import local packages
+
+
+def getParent(context, interface=Interface, allow_context=True):
+ """Get first parent of the given context that implements given interface"""
+ if allow_context:
+ parent = context
+ else:
+ parent = zapi.getParent(context)
+ while parent is not None:
+ if interface.providedBy(parent):
+ return interface(parent)
+ parent = zapi.getParent(parent)
+ return None
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/unicode.py Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,168 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# 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.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__ = "$Revision: $"
+__release__ = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+import string
+import codecs
+
+# import Zope3 interfaces
+
+# import local interfaces
+
+# import Zope3 packages
+
+# import local packages
+
+
+_unicodeTransTable = {}
+def _fillUnicodeTransTable():
+ _corresp = [
+ (u"A", [0x00C0,0x00C1,0x00C2,0x00C3,0x00C4,0x00C5,0x0100,0x0102,0x0104]),
+ (u"AE", [0x00C6]),
+ (u"a", [0x00E0,0x00E1,0x00E2,0x00E3,0x00E4,0x00E5,0x0101,0x0103,0x0105]),
+ (u"ae", [0x00E6]),
+ (u"C", [0x00C7,0x0106,0x0108,0x010A,0x010C]),
+ (u"c", [0x00E7,0x0107,0x0109,0x010B,0x010D]),
+ (u"D", [0x00D0,0x010E,0x0110]),
+ (u"d", [0x00F0,0x010F,0x0111]),
+ (u"E", [0x00C8,0x00C9,0x00CA,0x00CB,0x0112,0x0114,0x0116,0x0118,0x011A]),
+ (u"e", [0x00E8,0x00E9,0x00EA,0x00EB,0x0113,0x0115,0x0117,0x0119,0x011B]),
+ (u"G", [0x011C,0x011E,0x0120,0x0122]),
+ (u"g", [0x011D,0x011F,0x0121,0x0123]),
+ (u"H", [0x0124,0x0126]),
+ (u"h", [0x0125,0x0127]),
+ (u"I", [0x00CC,0x00CD,0x00CE,0x00CF,0x0128,0x012A,0x012C,0x012E,0x0130]),
+ (u"i", [0x00EC,0x00ED,0x00EE,0x00EF,0x0129,0x012B,0x012D,0x012F,0x0131]),
+ (u"IJ", [0x0132]),
+ (u"ij", [0x0133]),
+ (u"J", [0x0134]),
+ (u"j", [0x0135]),
+ (u"K", [0x0136]),
+ (u"k", [0x0137,0x0138]),
+ (u"L", [0x0139,0x013B,0x013D,0x013F,0x0141]),
+ (u"l", [0x013A,0x013C,0x013E,0x0140,0x0142]),
+ (u"N", [0x00D1,0x0143,0x0145,0x0147,0x014A]),
+ (u"n", [0x00F1,0x0144,0x0146,0x0148,0x0149,0x014B]),
+ (u"O", [0x00D2,0x00D3,0x00D4,0x00D5,0x00D6,0x00D8,0x014C,0x014E,0x0150]),
+ (u"o", [0x00F2,0x00F3,0x00F4,0x00F5,0x00F6,0x00F8,0x014D,0x014F,0x0151]),
+ (u"OE", [0x0152]),
+ (u"oe", [0x0153]),
+ (u"R", [0x0154,0x0156,0x0158]),
+ (u"r", [0x0155,0x0157,0x0159]),
+ (u"S", [0x015A,0x015C,0x015E,0x0160]),
+ (u"s", [0x015B,0x015D,0x015F,0x01610,0x017F]),
+ (u"T", [0x0162,0x0164,0x0166]),
+ (u"t", [0x0163,0x0165,0x0167]),
+ (u"U", [0x00D9,0x00DA,0x00DB,0x00DC,0x0168,0x016A,0x016C,0x016E,0x0170,0x172]),
+ (u"u", [0x00F9,0x00FA,0x00FB,0x00FC,0x0169,0x016B,0x016D,0x016F,0x0171]),
+ (u"W", [0x0174]),
+ (u"w", [0x0175]),
+ (u"Y", [0x00DD,0x0176,0x0178]),
+ (u"y", [0x00FD,0x00FF,0x0177]),
+ (u"Z", [0x0179,0x017B,0x017D]),
+ (u"z", [0x017A,0x017C,0x017E])
+ ]
+ for char,codes in _corresp:
+ for code in codes :
+ _unicodeTransTable[code] = char
+
+_fillUnicodeTransTable()
+
+
+def translateString(s, escapeSlashes=False, forceLower=True) :
+ """Remove extended characters from string
+
+ @param s: text to be cleaned.
+ @type s: str or unicode
+ @param escapeSlashes: if True, slashes are also converted
+ @type escapeSlashes: boolean
+ @param forceLower: if True, result is automatically converted to lower case
+ @type forceLower: boolean
+ @return: text without diacritics
+ @rtype: unicode
+ """
+ if escapeSlashes:
+ s = string.replace(s, "\\", "/").split("/")[-1]
+ s = s.strip()
+ if isinstance(s,str):
+ s = unicode(s,"utf8","replace")
+ s = s.translate(_unicodeTransTable)
+ s = ''.join([a for a in s.translate(_unicodeTransTable) if a.replace(' ','-') in (string.ascii_letters + string.digits + '_-.')])
+ if forceLower:
+ s = s.lower()
+ return s
+
+
+def nvl(value, default=''):
+ """Get specified value, or an empty string if value is empty
+
+ @param value: text to be checked
+ @param default: default value
+ @return: value, or default if value is empty
+ """
+ return value or default
+
+
+def uninvl(value, default=u''):
+ """Get specified value converted to unicode, or an empty unicode string if value is empty
+
+ @param value: text to be checked
+ @type value: str or unicode
+ @param default: default value
+ @return: value, or default if value is empty
+ @rtype: unicode
+ """
+ try:
+ if isinstance(value, unicode):
+ return value
+ return codecs.decode(value or default)
+ except:
+ return codecs.decode(value or default, 'latin1')
+
+
+def unidict(value):
+ """Get specified dict with values converted to unicode
+
+ @param value: input dict of strings which may be converted to unicode
+ @type value: dict
+ @return: input dict converted to unicode
+ @rtype: dict
+ """
+ result = {}
+ for key in value:
+ result[key] = uninvl(value[key])
+ return result
+
+
+def unilist(value):
+ """Get specified list with values converted to unicode
+
+ @param value: input list of strings which may be converted to unicode
+ @type value: list
+ @return: input list converted to unicode
+ @rtype: list
+ """
+ if not isinstance(value, (list,tuple)):
+ return uninvl(value)
+ return [uninvl(v) for v in value]
+