Pitfall of building python from source on Ubuntu

Zope 3.3 doesn't work well with the python 2.4.4 that comes with Ubuntu Edgy. Something about a readline change somewhere in the python standard library. So I had to build python 2.4.3 from source. Being an impatient being, I haven't give it much thought and just unpacked the python tarball, hit ./configure and make install. I ended up with python installed in /usr/local/bin/python, which would be really really cool if Ubuntu wouldn't depend on python and wouldn't place /usr/local/bin at the beginning of $PATH. [...]

Catching and printing python exceptions

>>> import traceback, sys >>> try: ... 1/0 ... except: ... traceback.print_exc(sys.exc_info()) ... Traceback (most recent call last): File "<stdin>", line 2, in ? ZeroDivisionError: integer division or modulo by zero >>> [...]

How to define a new skin in Zope 3

Lifted from zope.app.rotterdam Create a new browser skin layerfrom zope.publisher.interfaces.browser import IBrowserRequest from zope.publisher.interfaces.browser import IDefaultBrowserLayer class rotterdam(IBrowserRequest): """Layer for registering Rotterdam-specific macros.""" class Rotterdam(rotterdam, IDefaultBrowserLayer): """The ``Rotterdam`` skin. It is available via ``++skin++Rotterdam``. """ Register the skin in configure.zcml<interface interface="zope.app.rotterdam.Rotterdam" type="zope.publisher.interfaces.browser.IBrowserSkinType" name="Rotterdam" /> Declaring a resource and a page for the skin <browser:resource name="zope3.css" file="zope3.css" layer="zope.app.rotterdam.rotterdam" /> <browser:page for="*" name="standard_macros" permission="zope.View" class=".standardmacros.StandardMacros" layer="zope.app.rotterdam.rotterdam" allowed_interface="zope.interface.common.mapping.IItemMapping" /> [...]

Bulk modifying AT content fields under restricted python scripts

I'm working on a project that mostly extends an older, legacy based Plone 2.0 project. This project has a CMFFormController form with about 20 fields and based on that input needs to create new AT content items, which is done in the action script of the controller chain. To achieve this, I have the following code: First, I have a field_mapping that maps the fields from the form to the AT field names. [...]

Deliverence - serving semi-static content out of a live site

Deliverance is a lightweight, semi-static system for content delivery of CMS resources. It runs in mod_python, generating branded pages and navigation elements, giving high-performance throughput to anonymous visitors. Sounds interesting, especially in light of my contact with owners of bigger sites and editorial staff. This product can be downloaded from http://codespeak.net/svn/z3/deliverance/ [...]

Custom traversing with Five and ITraversable

This blog already contains a technique on how to customize the traversal to return any object, using __bobo_traverse__ A more simple, modern and elegant way of doing achieving this is detailed in the newly released ImageRepository. Basically, it uses an adapter to change the implementation for ITraversable when the traversal is done on an object implementing a marker interface. I've lifted the relevant code and pasted it below, but the original sources should be consulted for reference. [...]

Easy access to the zope namespace and modules

Sometimes I just want to test a package under the zope namespace (installed usually in /opt/Zope2.9/lib/python or /usr/local/Zope3.2/lib/python), like for example the zope.testbrowser the other day. The easiest way to achieve this, without messing around with PYTHONHOME environment variables, or appending paths to sys.path is to change directory to the lib/python folder and start the python interpretor there. Because python will look in the current folder for modules and packages, they will be available in the interpretor. [...]

Testing file uploads fields with zope.testbrowser

For some reason, the set_file method is not available for ListControls file upload objects inside the Browser object. To be able to fill in the file field, one needs to do myfilecontrol.mech_control.set_file(filestream, mimetype, filename). The problem gets weirder as set_file() is the method indicated by the README.txt doctest of zope.testbrowser package as the way to upload a file stream in a file upload widget, and I presume the README.txt test doesn't fail. [...]

Adding an overrides.zcml

According to this discussion on #zope3-dev, one must do the following to get overrides to take effect: add an product-overrides.zcml in which to include <include package="foo" file="overrides.zcml" />the *-overrides.zcml slugs needs to be loaded with includeOverrides [...]

AdvancedQuery and other portal_catalog tricks

The normal ZCatalog queries and indexes are extremely limited. For example, I had a need to check for a "Value not in KeywordIndex" expression, which is impossible to do with the normal catalog. AdvancedQuery comes to the rescue, but things aren't too obvious there either. AQ has a In() expression that can be used in building queries, but it does the reverse thing: check something like "IndexedValue not in ListOfValues". [...]