zope.size-3.5.0/0000775000177100020040000000000011665222317014600 5ustar menesismenesis00000000000000zope.size-3.5.0/setup.py0000664000177100020040000000365711665222130016316 0ustar menesismenesis00000000000000############################################################################## # # Copyright (c) 2006, 2011 Zope Foundation 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. # ############################################################################## # This package is developed by the Zope Toolkit project, documented here: # http://docs.zope.org/zopetoolkit # When developing and releasing this package, please follow the documented # Zope Toolkit policies as described by this documentation. ############################################################################## """Setup for zope.size package """ from setuptools import setup, find_packages setup(name='zope.size', version='3.5.0', url='http://pypi.python.org/pypi/zope.size', license='ZPL 2.1', description=\ 'Interfaces and simple adapter that give the size of an object', author='Zope Foundation and Contributors', author_email='zope-dev@zope.org', long_description=\ open('README.txt').read() + \ '\n\n' + \ open('CHANGES.txt').read(), packages=find_packages('src'), package_dir = {'': 'src'}, namespace_packages=['zope'], tests_require = [], extras_require=dict( zcml=[ 'zope.component[zcml]', 'zope.configuration', 'zope.security[zcml]', ]), install_requires=['setuptools', 'zope.interface', 'zope.i18nmessageid'], include_package_data = True, zip_safe = False, ) zope.size-3.5.0/CHANGES.txt0000664000177100020040000000074511665222130016410 0ustar menesismenesis00000000000000======= CHANGES ======= 3.5.0 (2011-11-29) ------------------ - Include zcml dependencies in configure.zcml, require the necessary packages via a zcml extra, added tests for zcml. 3.4.1 (2009-09-10) ------------------ - Added support to bootstrap on Jython. - Added docstrings - Beautify package's README and include CHANGES into the description. - Changed package's url to PyPI instead of Subversion. 3.4.0 (2006-09-29) ------------------ - First release as a separate egg zope.size-3.5.0/PKG-INFO0000664000177100020040000000257011665222317015701 0ustar menesismenesis00000000000000Metadata-Version: 1.0 Name: zope.size Version: 3.5.0 Summary: Interfaces and simple adapter that give the size of an object Home-page: http://pypi.python.org/pypi/zope.size Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: This package provides a definition of simple interface that allows to retrieve the size of the object for displaying and for sorting. The default adapter is also provided. It expects objects to have the ``getSize`` method that returns size in bytes, however, it won't crash if an object doesn't have one and will show size as ``not available`` instead. ======= CHANGES ======= 3.5.0 (2011-11-29) ------------------ - Include zcml dependencies in configure.zcml, require the necessary packages via a zcml extra, added tests for zcml. 3.4.1 (2009-09-10) ------------------ - Added support to bootstrap on Jython. - Added docstrings - Beautify package's README and include CHANGES into the description. - Changed package's url to PyPI instead of Subversion. 3.4.0 (2006-09-29) ------------------ - First release as a separate egg Platform: UNKNOWN zope.size-3.5.0/bootstrap.py0000664000177100020040000000416111665222130017162 0ustar menesismenesis00000000000000############################################################################## # # Copyright (c) 2006 Zope Foundation 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. """ 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 is_jython = sys.platform.startswith('java') if is_jython: import subprocess 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 if is_jython: assert subprocess.Popen( [sys.executable] + ['-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout'], env = dict(os.environ, PYTHONPATH = ws.find(pkg_resources.Requirement.parse('setuptools')).location ), ).wait() == 0 else: 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) zope.size-3.5.0/COPYRIGHT.txt0000664000177100020040000000004011665222130016674 0ustar menesismenesis00000000000000Zope Foundation and Contributorszope.size-3.5.0/src/0000775000177100020040000000000011665222317015367 5ustar menesismenesis00000000000000zope.size-3.5.0/src/zope.size.egg-info/0000775000177100020040000000000011665222317021007 5ustar menesismenesis00000000000000zope.size-3.5.0/src/zope.size.egg-info/PKG-INFO0000664000177100020040000000257011665222205022104 0ustar menesismenesis00000000000000Metadata-Version: 1.0 Name: zope.size Version: 3.5.0 Summary: Interfaces and simple adapter that give the size of an object Home-page: http://pypi.python.org/pypi/zope.size Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: This package provides a definition of simple interface that allows to retrieve the size of the object for displaying and for sorting. The default adapter is also provided. It expects objects to have the ``getSize`` method that returns size in bytes, however, it won't crash if an object doesn't have one and will show size as ``not available`` instead. ======= CHANGES ======= 3.5.0 (2011-11-29) ------------------ - Include zcml dependencies in configure.zcml, require the necessary packages via a zcml extra, added tests for zcml. 3.4.1 (2009-09-10) ------------------ - Added support to bootstrap on Jython. - Added docstrings - Beautify package's README and include CHANGES into the description. - Changed package's url to PyPI instead of Subversion. 3.4.0 (2006-09-29) ------------------ - First release as a separate egg Platform: UNKNOWN zope.size-3.5.0/src/zope.size.egg-info/dependency_links.txt0000664000177100020040000000000111665222205025051 0ustar menesismenesis00000000000000 zope.size-3.5.0/src/zope.size.egg-info/namespace_packages.txt0000664000177100020040000000000511665222205025331 0ustar menesismenesis00000000000000zope zope.size-3.5.0/src/zope.size.egg-info/not-zip-safe0000664000177100020040000000000111665222131023227 0ustar menesismenesis00000000000000 zope.size-3.5.0/src/zope.size.egg-info/top_level.txt0000664000177100020040000000000511665222205023530 0ustar menesismenesis00000000000000zope zope.size-3.5.0/src/zope.size.egg-info/requires.txt0000664000177100020040000000016011665222205023400 0ustar menesismenesis00000000000000setuptools zope.interface zope.i18nmessageid [zcml] zope.component[zcml] zope.configuration zope.security[zcml]zope.size-3.5.0/src/zope.size.egg-info/SOURCES.txt0000664000177100020040000000073411665222205022673 0ustar menesismenesis00000000000000CHANGES.txt COPYRIGHT.txt LICENSE.txt README.txt bootstrap.py buildout.cfg setup.py src/zope/__init__.py src/zope.size.egg-info/PKG-INFO src/zope.size.egg-info/SOURCES.txt src/zope.size.egg-info/dependency_links.txt src/zope.size.egg-info/namespace_packages.txt src/zope.size.egg-info/not-zip-safe src/zope.size.egg-info/requires.txt src/zope.size.egg-info/top_level.txt src/zope/size/__init__.py src/zope/size/configure.zcml src/zope/size/interfaces.py src/zope/size/tests.pyzope.size-3.5.0/src/zope/0000775000177100020040000000000011665222317016344 5ustar menesismenesis00000000000000zope.size-3.5.0/src/zope/size/0000775000177100020040000000000011665222317017316 5ustar menesismenesis00000000000000zope.size-3.5.0/src/zope/size/configure.zcml0000664000177100020040000000060411665222130022157 0ustar menesismenesis00000000000000 zope.size-3.5.0/src/zope/size/tests.py0000664000177100020040000001030111665222130021016 0ustar menesismenesis00000000000000############################################################################## # # Copyright (c) 2001, 2002, 2011 Zope Foundation 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. # ############################################################################## """Test ISized Adapter """ import unittest from zope.size.interfaces import ISized import zope.component import zope.configuration.xmlconfig import zope.size class ZCMLTest(unittest.TestCase): def test_configure_zcml_should_be_loadable(self): try: zope.configuration.xmlconfig.XMLConfig( 'configure.zcml', zope.size)() except Exception, e: self.fail(e) def test_configure_should_register_n_components(self): gsm = zope.component.getGlobalSiteManager() u_count = len(list(gsm.registeredUtilities())) a_count = len(list(gsm.registeredAdapters())) s_count = len(list(gsm.registeredSubscriptionAdapters())) h_count = len(list(gsm.registeredHandlers())) zope.configuration.xmlconfig.XMLConfig( 'configure.zcml', zope.size)() self.assertEqual(u_count + 8, len(list(gsm.registeredUtilities()))) self.assertEqual(a_count + 1, len(list(gsm.registeredAdapters()))) self.assertEqual( s_count, len(list(gsm.registeredSubscriptionAdapters()))) self.assertEqual(h_count, len(list(gsm.registeredHandlers()))) class DummyObject(object): def __init__(self, size): self._size = size def getSize(self): return self._size class Test(unittest.TestCase): def testImplementsISized(self): from zope.size import DefaultSized sized = DefaultSized(object()) self.assert_(ISized.providedBy(sized)) def testSizeWithBytes(self): from zope.size import DefaultSized obj = DummyObject(1023) sized = DefaultSized(obj) self.assertEqual(sized.sizeForSorting(), ('byte', 1023)) self.assertEqual(sized.sizeForDisplay(), u'1 KB') def testSizeWithNone(self): from zope.size import DefaultSized obj = DummyObject(None) sized = DefaultSized(obj) self.assertEqual(sized.sizeForSorting(), (None, None)) self.assertEqual(sized.sizeForDisplay(), u'not-available') def testSizeNotAvailable(self): from zope.size import DefaultSized sized = DefaultSized(object()) self.assertEqual(sized.sizeForSorting(), (None, None)) self.assertEqual(sized.sizeForDisplay(), u'not-available') def testVariousSizes(self): from zope.size import DefaultSized sized = DefaultSized(DummyObject(0)) self.assertEqual(sized.sizeForSorting(), ('byte', 0)) self.assertEqual(sized.sizeForDisplay(), u'0 KB') sized = DefaultSized(DummyObject(1)) self.assertEqual(sized.sizeForSorting(), ('byte', 1)) self.assertEqual(sized.sizeForDisplay(), u'1 KB') sized = DefaultSized(DummyObject(2048)) self.assertEqual(sized.sizeForSorting(), ('byte', 2048)) self.assertEqual(sized.sizeForDisplay(), u'${size} KB') self.assertEqual(sized.sizeForDisplay().mapping, {'size': '2'}) sized = DefaultSized(DummyObject(2000000)) self.assertEqual(sized.sizeForSorting(), ('byte', 2000000)) self.assertEqual(sized.sizeForDisplay(), u'${size} MB') self.assertEqual(sized.sizeForDisplay().mapping, {'size': '1.91'}) def test_byteDisplay(self): from zope.size import byteDisplay self.assertEqual(byteDisplay(0), u'0 KB') self.assertEqual(byteDisplay(1), u'1 KB') self.assertEqual(byteDisplay(2048), u'${size} KB') self.assertEqual(byteDisplay(2048).mapping, {'size': '2'}) self.assertEqual(byteDisplay(2000000), u'${size} MB') self.assertEqual(byteDisplay(2000000).mapping, {'size': '1.91'}) zope.size-3.5.0/src/zope/size/__init__.py0000664000177100020040000000355011665222130021423 0ustar menesismenesis00000000000000############################################################################## # # Copyright (c) 2002 Zope Foundation 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. # ############################################################################## """Adapters that give the size of an object. """ from zope.interface import implements from zope.size.interfaces import ISized from zope.i18nmessageid import MessageFactory _ = MessageFactory('zope') class DefaultSized(object): """ A default ISized adapter """ implements(ISized) def __init__(self, obj): try: size = int(obj.getSize()) except (AttributeError, ValueError, TypeError): self._sortingSize = None, None else: self._sortingSize = 'byte', size def sizeForSorting(self): """See ISized""" return self._sortingSize def sizeForDisplay(self): """See ISized""" units, size = self._sortingSize if units == 'byte': return byteDisplay(size) return _('not-available', 'n/a') def byteDisplay(size): """ Returns a size with the correct unit (KB, MB), given the size in bytes. The output should be given to zope.i18n.translate() """ if size == 0: return _('0 KB') if size <= 1024: return _('1 KB') if size > 1048576: return _('${size} MB', mapping={'size': '%0.02f' % (size / 1048576.0)}) return _('${size} KB', mapping={'size': '%d' % (size / 1024.0)}) zope.size-3.5.0/src/zope/size/interfaces.py0000664000177100020040000000255211665222130022010 0ustar menesismenesis00000000000000############################################################################## # # Copyright (c) 2002 Zope Foundation 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. # ############################################################################## """Interfaces that give the size of an object. """ from zope.interface import Interface # basic units: # 'byte' # 'item' for example, number of subobjects for a folder # None for unsized things # 'line' for source-code like things class ISized(Interface): def sizeForSorting(): """Returns a tuple (basic_unit, amount) Used for sorting among different kinds of sized objects. 'amount' need only be sortable among things that share the same basic unit.""" def sizeForDisplay(): """Returns a string giving the size. The output string may be a zope.i18nmessageid.message.Message with an embedded mapping, so it should be translated with zope.i18n.translate() """ zope.size-3.5.0/src/zope/__init__.py0000664000177100020040000000007011665222130020443 0ustar menesismenesis00000000000000__import__('pkg_resources').declare_namespace(__name__) zope.size-3.5.0/buildout.cfg0000664000177100020040000000014111665222130017075 0ustar menesismenesis00000000000000[buildout] develop = . parts = test [test] recipe = zc.recipe.testrunner eggs = zope.size[zcml] zope.size-3.5.0/README.txt0000664000177100020040000000054211665222130016270 0ustar menesismenesis00000000000000This package provides a definition of simple interface that allows to retrieve the size of the object for displaying and for sorting. The default adapter is also provided. It expects objects to have the ``getSize`` method that returns size in bytes, however, it won't crash if an object doesn't have one and will show size as ``not available`` instead. zope.size-3.5.0/setup.cfg0000664000177100020040000000007311665222317016421 0ustar menesismenesis00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 zope.size-3.5.0/LICENSE.txt0000664000177100020040000000402611665222130016416 0ustar menesismenesis00000000000000Zope Public License (ZPL) Version 2.1 A copyright notice accompanies this license document that identifies the copyright holders. This license has been certified as open source. It has also been designated as GPL compatible by the Free Software Foundation (FSF). Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions in source code must retain the accompanying copyright notice, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the accompanying copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Names of the copyright holders must not be used to endorse or promote products derived from this software without prior written permission from the copyright holders. 4. The right to distribute this software or to use it for any purpose does not give you the right to use Servicemarks (sm) or Trademarks (tm) of the copyright holders. Use of them is covered by separate agreement with the copyright holders. 5. If any files are modified, you must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. Disclaimer THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.