Rev 139: Implement .name (for now at least) in http://bazaar.launchpad.net/~jameinel/meliae/mem-object-collection
John Arbash Meinel
john at arbash-meinel.com
Mon Dec 28 05:23:47 GMT 2009
At http://bazaar.launchpad.net/~jameinel/meliae/mem-object-collection
------------------------------------------------------------
revno: 139
revision-id: john at arbash-meinel.com-20091228052331-rlb3yi3hdgr3kchu
parent: john at arbash-meinel.com-20091228051909-8ddq8xvm6r2eemx4
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: mem-object-collection
timestamp: Sun 2009-12-27 23:23:31 -0600
message:
Implement .name (for now at least)
-------------- next part --------------
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx 2009-12-28 05:19:09 +0000
+++ b/meliae/_loader.pyx 2009-12-28 05:23:31 +0000
@@ -141,6 +141,9 @@
# Removed for now, since it hasn't proven useful
# int length
PyObject *value
+ # TODO: I don't think I've found an object that has both a value and a
+ # name. As such, I should probably remove the redundancy, as it saves
+ # a pointer
PyObject *name
RefList *referrer_list
unsigned long total_size
@@ -201,6 +204,12 @@
self._ensure_obj()
self._obj.size = value
+ property name:
+ """Name associated with this object."""
+ def __get__(self):
+ self._ensure_obj()
+ return <object>self._obj.name
+
property value:
"""Value for this object (for strings and ints)"""
def __get__(self):
=== modified file 'meliae/tests/test__loader.py'
--- a/meliae/tests/test__loader.py 2009-12-28 05:19:09 +0000
+++ b/meliae/tests/test__loader.py 2009-12-28 05:23:31 +0000
@@ -315,6 +315,15 @@
mop.value = 'a str'
self.assertEqual('a str', mop.value)
+ def test_name(self):
+ mop = self.moc.add(1234, 'type', 256, name='the name')
+ self.assertEqual('the name', mop.name)
+ # TODO: We may remove name as a separate attribute from value, but for
+ # now, 'name' is not settable
+ def set(value):
+ mop.name = value
+ self.assertRaises(AttributeError, set, 'test')
+
def test__intern_from_cache(self):
cache = {}
addr = 1234567
More information about the bazaar-commits
mailing list