Commit 11473bba authored by Jim Fulton's avatar Jim Fulton

remplemented the Record extension based on new-style extension classes.

parent 26fe0868
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Records
Records are used to provide compact storage for database query result rows.
They don't use instance dictionaries. Rather, they store they data in
a compact array internally. They use a record schema to map names to
positions within the array.
>>> class R(Record):
... __record_schema__ = {'a': 0, 'b': 1, 'c': 2}
>>> r = R()
>>> r.__dict__
Traceback (most recent call last):
...
AttributeError: __dict__
>>> r.a
>>> r.a = 1
>>> r.a
1
>>> r.b
>>> r.c
Records can be used as mapping objects:
>>> "%(a)s %(b)s %(c)s" % r
'1 None None'
>>> r['a']
1
>>> r['b'] = 42
And like sequences:
>>> r[0]
1
>>> r[1]
42
>>> list(r)
[1, 42, None]
$Id: __init__.py,v 1.2 2003/11/28 16:46:36 jim Exp $
"""
from _Record import Record
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
from distutils.core import setup, Extension
setup(name="_Record", version="2.0",
ext_modules=[
Extension("_Record", ["_Record.c"],
include_dirs = ['.', '../ExtensionClass'],
depends = ['../ExtensionClass/ExtensionClass.h']),
])
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Record tests
$Id: tests.py,v 1.2 2003/11/28 16:46:36 jim Exp $
"""
from Record import Record
import pickle
class P(Record):
__record_schema__ = {'a': 0, 'b': 1, 'c': 2}
def test_RecordPickling():
"""
We can create records from sequences:
>>> r = P(('x', 42, 1.23))
We can pickle them:
>>> r2 = pickle.loads(pickle.dumps(r))
>>> list(r) == list(r2)
1
>>> r.__record_schema__ == r2.__record_schema__
1
"""
import unittest
from doctest import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite('Record'),
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment