[Checkins] SVN: zc.mappingobject/trunk/ Tiny utility that I'm tired of writing over and over.
Jim Fulton
jim at zope.com
Wed Dec 21 11:43:01 UTC 2011
Log message for revision 123851:
Tiny utility that I'm tired of writing over and over.
Changed:
D zc.mappingobject/trunk/README.txt
U zc.mappingobject/trunk/buildout.cfg
U zc.mappingobject/trunk/setup.py
A zc.mappingobject/trunk/src/zc/mappingobject.py
-=-
Deleted: zc.mappingobject/trunk/README.txt
===================================================================
--- zc.mappingobject/trunk/README.txt 2011-12-21 11:41:58 UTC (rev 123850)
+++ zc.mappingobject/trunk/README.txt 2011-12-21 11:43:00 UTC (rev 123851)
@@ -1,14 +0,0 @@
-Title Here
-**********
-
-
-To learn more, see
-
-
-Changes
-*******
-
-0.1.0 (yyyy-mm-dd)
-==================
-
-Initial release
Modified: zc.mappingobject/trunk/buildout.cfg
===================================================================
--- zc.mappingobject/trunk/buildout.cfg 2011-12-21 11:41:58 UTC (rev 123850)
+++ zc.mappingobject/trunk/buildout.cfg 2011-12-21 11:43:00 UTC (rev 123851)
@@ -1,12 +1,8 @@
[buildout]
develop = .
-parts = test py
+parts = py
-[test]
-recipe = zc.recipe.testrunner
-eggs =
-
[py]
recipe = zc.recipe.egg
-eggs = ${test:eggs}
+eggs = zc.mappingobject
interpreter = py
Modified: zc.mappingobject/trunk/setup.py
===================================================================
--- zc.mappingobject/trunk/setup.py 2011-12-21 11:41:58 UTC (rev 123850)
+++ zc.mappingobject/trunk/setup.py 2011-12-21 11:43:00 UTC (rev 123851)
@@ -11,32 +11,29 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-name, version = 'zc.', '0'
+name, version = 'zc.mappingobject', '0'
install_requires = ['setuptools']
-extras_require = dict(test=['zope.testing'])
-entry_points = """
-"""
-
from setuptools import setup
+import os
+doc = open(
+ os.path.join(os.path.dirname(__file__), 'src', *name.split('.'))+'.py'
+ ).read().split('"""')[1]
+
setup(
author = 'Jim Fulton',
author_email = 'jim at zope.com',
license = 'ZPL 2.1',
name = name, version = version,
- long_description=open('README.txt').read(),
- description = open('README.txt').read().strip().split('\n')[0],
- packages = [name.split('.')[0], name],
+ long_description=doc,
+ description = doc.split('\n')[0],
+ packages = [name.split('.')[0]],
namespace_packages = [name.split('.')[0]],
package_dir = {'': 'src'},
install_requires = install_requires,
zip_safe = False,
- entry_points=entry_points,
- package_data = {name: ['*.txt', '*.test', '*.html']},
- extras_require = extras_require,
- tests_require = extras_require['test'],
- test_suite = name+'.tests.test_suite',
+ test_suite = name+'.test_suite',
)
Added: zc.mappingobject/trunk/src/zc/mappingobject.py
===================================================================
--- zc.mappingobject/trunk/src/zc/mappingobject.py (rev 0)
+++ zc.mappingobject/trunk/src/zc/mappingobject.py 2011-12-21 11:43:00 UTC (rev 123851)
@@ -0,0 +1,101 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation 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.
+#
+##############################################################################
+
+__all__ = ['mappingobject']
+
+class mappingobject(object):
+ """\
+ Sometimes, you want to use a mapping object like a regular object.
+
+ ``zc.mappingobject`` provides a wrapper for a mapping objects that
+ provides both attribute and item access.
+
+ >>> import zc.mappingobject
+ >>> mapping = dict(a=1)
+ >>> ob = zc.mappingobject.mappingobject(mapping)
+
+ >>> ob.a
+ 1
+ >>> ob.a = 2
+ >>> ob.a
+ 2
+ >>> mapping
+ {'a': 2}
+
+ >>> list(ob)
+ ['a']
+
+ >>> len(ob)
+ 1
+
+ >>> ob['a'] = 3
+ >>> ob.a
+ 3
+ >>> mapping
+ {'a': 3}
+
+ >>> del ob.a
+ >>> mapping
+ {}
+ >>> ob.a
+ Traceback (most recent call last):
+ ...
+ AttributeError: a
+
+ >>> ob.b = 1
+ >>> mapping
+ {'b': 1}
+
+ >>> del ob['b']
+ >>> mapping
+ {}
+ """
+ __slots__ = '_mappingobject__data',
+
+ def __init__(self, data):
+ super(mappingobject, self).__setattr__('_mappingobject__data', data)
+
+ def __getattr__(self, name):
+ try:
+ return self.__data[name]
+ except KeyError:
+ raise AttributeError(name)
+
+ def __delattr__(self, name):
+ try:
+ del self.__data[name]
+ except KeyError:
+ raise AttributeError(name)
+
+ def __setattr__(self, name, value):
+ self.__data[name] = value
+
+ def __getitem__(self, name):
+ return self.__data[name]
+
+ def __delitem__(self, name):
+ del self.__data[name]
+
+ __setitem__ = __setattr__
+
+ def __len__(self):
+ return len(self.__data)
+
+ def __iter__(self):
+ return iter(self.__data)
+
+
+def test_suite():
+ import doctest
+ return doctest.DocTestSuite()
Property changes on: zc.mappingobject/trunk/src/zc/mappingobject.py
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
More information about the checkins
mailing list