[Checkins] SVN: zope.i18nmessageid/branches/c-extension-less/ Removing C-extension; if there's any behavior that we want from the C-extension which is not in the Python-implementation, it's untested.
Malthe Borch
mborch at gmail.com
Fri Dec 12 06:19:55 EST 2008
Log message for revision 93938:
Removing C-extension; if there's any behavior that we want from the C-extension which is not in the Python-implementation, it's untested.
Changed:
U zope.i18nmessageid/branches/c-extension-less/CHANGES.txt
U zope.i18nmessageid/branches/c-extension-less/setup.py
D zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/_zope_i18nmessageid_message.c
U zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/message.py
-=-
Modified: zope.i18nmessageid/branches/c-extension-less/CHANGES.txt
===================================================================
--- zope.i18nmessageid/branches/c-extension-less/CHANGES.txt 2008-12-12 11:18:23 UTC (rev 93937)
+++ zope.i18nmessageid/branches/c-extension-less/CHANGES.txt 2008-12-12 11:19:55 UTC (rev 93938)
@@ -4,6 +4,8 @@
Version 3.5.0 (unreleased)
-------------------------
+- Removed C-extension.
+
- Added support to bootstrap on Jython.
Version 3.4.3 (2007/9/26)
Modified: zope.i18nmessageid/branches/c-extension-less/setup.py
===================================================================
--- zope.i18nmessageid/branches/c-extension-less/setup.py 2008-12-12 11:18:23 UTC (rev 93937)
+++ zope.i18nmessageid/branches/c-extension-less/setup.py 2008-12-12 11:19:55 UTC (rev 93938)
@@ -23,7 +23,6 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
setup(name='zope.i18nmessageid',
version = '3.5.0dev',
author='Zope Corporation and Contributors',
@@ -49,11 +48,6 @@
url='http://pypi.python.org/pypi/zope.i18nmessageid',
packages=find_packages('src'),
package_dir = {'': 'src'},
- ext_modules=[
- Extension("zope.i18nmessageid._zope_i18nmessageid_message",
- [os.path.join('src', 'zope', 'i18nmessageid',
- "_zope_i18nmessageid_message.c") ]),
- ],
namespace_packages=['zope',],
tests_require = ['zope.testing'],
install_requires=['setuptools'],
Deleted: zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/_zope_i18nmessageid_message.c
===================================================================
--- zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/_zope_i18nmessageid_message.c 2008-12-12 11:18:23 UTC (rev 93937)
+++ zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/_zope_i18nmessageid_message.c 2008-12-12 11:19:55 UTC (rev 93938)
@@ -1,266 +0,0 @@
-/*############################################################################
-#
-# Copyright (c) 2004 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.
-#
-############################################################################*/
-
-/* $Id$ */
-
-#include "Python.h"
-
-/* these macros make gc support easier; they are only available in
- Python 2.4 and borrowed from there */
-
-#ifndef Py_CLEAR
-#define Py_CLEAR(op) \
- do { \
- if (op) { \
- PyObject *tmp = (op); \
- (op) = NULL; \
- Py_DECREF(tmp); \
- } \
- } while (0)
-#endif
-
-#ifndef Py_VISIT
-#define Py_VISIT(op) \
- do { \
- if (op) { \
- int vret = visit((op), arg); \
- if (vret) \
- return vret; \
- } \
- } while (0)
-#endif
-
-/* ----------------------------------------------------- */
-
-typedef struct {
- PyUnicodeObject base;
- PyObject *domain;
- PyObject *default_;
- PyObject *mapping;
-} Message;
-
-static PyTypeObject MessageType;
-
-static PyObject *
-Message_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- static char *kwlist[] = {"value", "domain", "default", "mapping", NULL};
- PyObject *value, *domain=NULL, *default_=NULL, *mapping=NULL, *s;
- Message *self;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOO", kwlist,
- &value, &domain, &default_, &mapping))
- return NULL;
-
- args = Py_BuildValue("(O)", value);
- if (args == NULL)
- return NULL;
-
- s = PyUnicode_Type.tp_new(type, args, NULL);
- Py_DECREF(args);
- if (s == NULL)
- return NULL;
-
- if (! PyObject_TypeCheck(s, &MessageType))
- {
- PyErr_SetString(PyExc_TypeError,
- "unicode.__new__ didn't return a Message");
- Py_DECREF(s);
- return NULL;
- }
-
- self = (Message*)s;
-
- if (PyObject_TypeCheck(value, &MessageType))
- {
- self->domain = ((Message *)value)->domain;
- self->default_ = ((Message *)value)->default_;
- self->mapping = ((Message *)value)->mapping;
- }
- else
- {
- self->domain = self->default_ = self->mapping = NULL;
- }
-
- if (domain != NULL)
- self->domain = domain;
-
- if (default_ != NULL)
- self->default_ = default_;
-
- if (mapping != NULL)
- self->mapping = mapping;
-
- Py_XINCREF(self->mapping);
- Py_XINCREF(self->default_);
- Py_XINCREF(self->domain);
-
- return (PyObject *)self;
-}
-
-/* Code to access structure members by accessing attributes */
-
-#include "structmember.h"
-
-static PyMemberDef Message_members[] = {
- { "domain", T_OBJECT, offsetof(Message, domain), RO },
- { "default", T_OBJECT, offsetof(Message, default_), RO },
- { "mapping", T_OBJECT, offsetof(Message, mapping), RO },
- {NULL} /* Sentinel */
-};
-
-static int
-Message_traverse(Message *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->domain);
- Py_VISIT(self->default_);
- Py_VISIT(self->mapping);
- return 0;
-}
-
-static int
-Message_clear(Message *self)
-{
- Py_CLEAR(self->domain);
- Py_CLEAR(self->default_);
- Py_CLEAR(self->mapping);
- return 0;
-}
-
-static void
-Message_dealloc(Message *self)
-{
- Message_clear(self);
- self->base.ob_type->tp_free((PyObject*)self);
-}
-
-static PyObject *
-Message_reduce(Message *self)
-{
- PyObject *value, *result;
- value = PyObject_CallFunctionObjArgs((PyObject *)&PyUnicode_Type, self, NULL);
- if (value == NULL)
- return NULL;
- result = Py_BuildValue("(O(OOOO))", self->base.ob_type,
- value,
- self->domain ? self->domain : Py_None,
- self->default_ ? self->default_ : Py_None,
- self->mapping ? self->mapping : Py_None);
- Py_DECREF(value);
- return result;
-}
-
-static PyMethodDef Message_methods[] = {
- {"__reduce__", (PyCFunction)Message_reduce, METH_NOARGS,
- "Reduce messages to a serializable form."},
- {NULL} /* Sentinel */
-};
-
-
-static char MessageType__doc__[] =
-"Message\n"
-"\n"
-"This is a string used as a message. It has a domain attribute that is\n"
-"its source domain, and a default attribute that is its default text to\n"
-"display when there is no translation. domain may be None meaning there is\n"
-"no translation domain. default may also be None, in which case the\n"
-"message id itself implicitly serves as the default text.\n";
-
-statichere PyTypeObject
-MessageType = {
- PyObject_HEAD_INIT(NULL)
- /* ob_size */ 0,
- /* tp_name */ "zope.i18nmessageid.message."
- "Message",
- /* tp_basicsize */ sizeof(Message),
- /* tp_itemsize */ 0,
- /* tp_dealloc */ (destructor)&Message_dealloc,
- /* tp_print */ (printfunc)0,
- /* tp_getattr */ (getattrfunc)0,
- /* tp_setattr */ (setattrfunc)0,
- /* tp_compare */ (cmpfunc)0,
- /* tp_repr */ (reprfunc)0,
- /* tp_as_number */ 0,
- /* tp_as_sequence */ 0,
- /* tp_as_mapping */ 0,
- /* tp_hash */ (hashfunc)0,
- /* tp_call */ (ternaryfunc)0,
- /* tp_str */ (reprfunc)0,
- /* tp_getattro */ (getattrofunc)0,
- /* tp_setattro */ (setattrofunc)0,
- /* tp_as_buffer */ 0,
- /* tp_flags */ Py_TPFLAGS_DEFAULT
- | Py_TPFLAGS_BASETYPE
- | Py_TPFLAGS_HAVE_GC,
- /* tp_doc */ MessageType__doc__,
- /* tp_traverse */ (traverseproc)Message_traverse,
- /* tp_clear */ (inquiry)Message_clear,
- /* tp_richcompare */ (richcmpfunc)0,
- /* tp_weaklistoffset */ (long)0,
- /* tp_iter */ (getiterfunc)0,
- /* tp_iternext */ (iternextfunc)0,
- /* tp_methods */ Message_methods,
- /* tp_members */ Message_members,
- /* tp_getset */ 0,
- /* tp_base */ 0,
- /* tp_dict */ 0, /* internal use */
- /* tp_descr_get */ (descrgetfunc)0,
- /* tp_descr_set */ (descrsetfunc)0,
- /* tp_dictoffset */ 0,
- /* tp_init */ (initproc)0,
- /* tp_alloc */ (allocfunc)0,
- /* tp_new */ (newfunc)Message_new,
- /* tp_free */ 0, /* Low-level free-mem routine */
- /* tp_is_gc */ (inquiry)0, /* For PyObject_IS_GC */
-};
-
-/* End of code for Message objects */
-/* -------------------------------------------------------- */
-
-
-/* List of methods defined in the module */
-
-static struct PyMethodDef _zope_i18nmessageid_message_methods[] = {
- {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
-};
-
-
-static char _zope_i18nmessageid_message_module_documentation[] =
-"I18n Messages"
-;
-
-#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
-#define PyMODINIT_FUNC void
-#endif
-PyMODINIT_FUNC
-init_zope_i18nmessageid_message(void)
-{
- PyObject *m;
- /* Initialize types: */
- MessageType.tp_base = &PyUnicode_Type;
- if (PyType_Ready(&MessageType) < 0)
- return;
-
- /* Create the module and add the functions */
- m = Py_InitModule3("_zope_i18nmessageid_message",
- _zope_i18nmessageid_message_methods,
- _zope_i18nmessageid_message_module_documentation);
-
- if (m == NULL)
- return;
-
- /* Add types: */
- if (PyModule_AddObject(m, "Message", (PyObject *)&MessageType) < 0)
- return;
-}
Modified: zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/message.py
===================================================================
--- zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/message.py 2008-12-12 11:18:23 UTC (rev 93937)
+++ zope.i18nmessageid/branches/c-extension-less/src/zope/i18nmessageid/message.py 2008-12-12 11:19:55 UTC (rev 93938)
@@ -26,10 +26,7 @@
no translation domain. default may also be None, in which case the
message id itself implicitly serves as the default text.
- These are the doc tests from message.txt. Note that we have to create the
- message manually since MessageFactory would return the C implementation.
-
- >>> from zope.i18nmessageid.message import pyMessage as Message
+ >>> from zope.i18nmessageid.message import Message
>>> robot = Message(u"robot-message", 'futurama', u"${name} is a robot.")
>>> robot
@@ -41,10 +38,6 @@
u'${name} is a robot.'
>>> robot.mapping
- Only the python implementation has a _readonly attribute
- >>> robot._readonly
- True
-
>>> robot.domain = "planetexpress"
Traceback (most recent call last):
...
@@ -83,56 +76,16 @@
>>> args
(u'fembot', None, None, None)
- Change classes for pickle tests
- >>> import zope.i18nmessageid.message
- >>> oldMessage = zope.i18nmessageid.message.Message
- >>> zope.i18nmessageid.message.Message = Message
-
- At first check if pickling and unpicklung from pyMessage to pyMessage works
+ Verify pickling.
+
>>> from pickle import dumps, loads
>>> pystate = dumps(new_robot)
>>> pickle_bot = loads(pystate)
>>> pickle_bot, pickle_bot.domain, pickle_bot.default, pickle_bot.mapping
(u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'})
- >>> pickle_bot._readonly
+ >>> pickle_bot.__reduce__()[0] is Message
True
- >>> from zope.i18nmessageid.message import pyMessage
- >>> pickle_bot.__reduce__()[0] is pyMessage
- True
- >>> del pickle_bot
-
- At second check if cMessage is able to load the state of a pyMessage
- >>> from _zope_i18nmessageid_message import Message
- >>> zope.i18nmessageid.message.Message = Message
- >>> c_bot = loads(pystate)
- >>> c_bot, c_bot.domain, c_bot.default, c_bot.mapping
- (u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'})
- >>> c_bot._readonly
- Traceback (most recent call last):
- AttributeError: 'zope.i18nmessageid.message.Message' object has no attribute '_readonly'
- >>> from _zope_i18nmessageid_message import Message as cMessage
- >>> c_bot.__reduce__()[0] is cMessage
- True
-
- At last check if pyMessage can load a state of cMessage
- >>> cstate = dumps(c_bot)
- >>> del c_bot
- >>> from zope.i18nmessageid.message import pyMessage as Message
- >>> zope.i18nmessageid.message.Message = Message
- >>> py_bot = loads(cstate)
- >>> py_bot, py_bot.domain, py_bot.default, py_bot.mapping
- (u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'})
- >>> py_bot._readonly
- True
- >>> py_bot.__reduce__()[0] is pyMessage
- True
-
- Both pickle states should be equal
- >>> pystate == cstate
- True
-
- Finally restore classes for other unit tests
- >>> zope.i18nmessageid.message.Message = oldMessage
+
"""
__slots__ = ('domain', 'default', 'mapping', '_readonly')
@@ -144,40 +97,31 @@
default = ustr.default and ustr.default[:] or default
mapping = ustr.mapping and ustr.mapping.copy() or mapping
ustr = unicode(ustr)
- self.domain = domain
- if default is None:
- # MessageID does: self.default = ustr
- self.default = default
- else:
- self.default = unicode(default)
- self.mapping = mapping
- self._readonly = True
+
+ # make sure a non-trivial default value is a unicode string
+ if default is not None:
+ default = unicode(default)
+
+ unicode.__setattr__(self, 'domain', domain)
+ unicode.__setattr__(self, 'default', default)
+ unicode.__setattr__(self, 'mapping', mapping)
+
return self
def __setattr__(self, key, value):
- """Message is immutable
+ """Message is immutable.
It cannot be changed once the message id is created.
"""
- if getattr(self, '_readonly', False):
- raise TypeError('readonly attribute')
- else:
- return unicode.__setattr__(self, key, value)
+ raise TypeError('readonly attribute')
+
def __reduce__(self):
return self.__class__, self.__getstate__()
def __getstate__(self):
return unicode(self), self.domain, self.default, self.mapping
-# save a copy for the unit tests
-pyMessage = Message
-
-try:
- from _zope_i18nmessageid_message import Message
-except ImportError:
- pass
-
class MessageFactory(object):
"""Factory for creating i18n messages."""
More information about the Checkins
mailing list