Archives

Inspired by this caching recipe and to continue with the previous post, I think it will be more readable, clean and reusable if we use a decorator to cache methods inside a tool:

class myTool(...):

@cachedmethod
def getMyDataFromDB(*args, **kw):

data = fetch_mydata_from_db()

return data
Decorators make magic easy.

The cachedmethod decorator would be as follow (The code is not tested):

» Read More

When I have some data to put in the cache, I do it the easiest way: I write a python script that returns the data and then from the Zope Instance Manager I make use of the caching Tab to select the type of caching.

Anton (the speaker) showed me a way of using zope caching form within my code:

from OFS.Cache import Cacheable

and then make my class (Content Type, Tool or ...) cacheable by inheriting from Cacheable.
To cache and to get cached data, we can use some thing like this:

» Read More

Today at work I needed a http server with python to test a script that outputs something to the web. I couldn't find one near by. hadn't the time nor the will to setup one, I just postponed the task to another moment. Few seconds later WSGI came to my mind. Yes, why searching for python server when there is a http server in the paste package ? All I need is two lines of code:

from paste import httpserver
httpserver.serve(my_wsgi_app, host='127.0.0.1', port='8080')

voila !

» Read More

When you have many zope instances distributed on many servers and point all to the same storage and you have many other servers at the frontend with many software for caching, load balancing, mailing, ..etc, you probably know the hell of maintaining such system. I was asked to found out a solution to centralize the logging part of this system.

Let's take just the zope part:

Zope comes with 5 types of logging handlers: logfile, syslog, win32-eventlog, http-handler and email-notifier. For the problem I want to solve the syslog handler is the best choice.

Why syslog ?



The http-handler sends the log with a http request to an URL. It will be slow and will use more system resources and some coding.
The email-notifier is not for centralizing a logging system it is just for notification.
The win32-eventlog is for windows :-)

The syslogd come pre-installed with all *nix systems and can forward logging requests to other syslogd on other server using the UDP protocol.

» Read More

Since I started developing with python I never found myself in the need of such statement. As I remember I never asked where is the switch statement in this language. I think I never asked that because of the dictionary data type in python that you can use to do the same thing as a switch statement will do. I was surprised that there are many PEPs about adding the switch statement to python.

In other languages the switch statement looks like this:

switch (var)
{
case value1: do_some_stuff1();
case value2: do_some_stuff2();
...
case valueN: do_some_stuffN();
default: do_default_stuff();
}

in python one can do the same thing with the help of a dictionary like this:

» Read More

I found this problem at The Voidspace Techie Blog:
Here is it:

>>> 3.__str__()
File "", line 1
3.__str__()
^
SyntaxError: invalid syntax

Here, python thinks that the dot is the dot of a float and not a dot for an attribute.
But the following works:

» Read More

I found the link to the "How to Design a Good API & Why it Matters" talk by Joshua Bloch on the Google's Research Publications page.

Joshua Bloch is a Java library designer. In this talk he teaches how to design good APIs, with many examples of what good and bad APIs look like. Most examples are in java of course, but they are ONLY examples. This talk is about design and the java examples are very easy to understand even if you have never written a line of java code.

» Read More

from the README file:
The ZEO RAID storage is a proxy storage that works like a RAID controller by creating a redundant array of ZEO servers. The redundancy is similar to RAID level 1 except that each ZEO server keeps a complete copy of the database.

Therefore, up to N-1 out of N ZEO servers can fail without interrupting.

It is intended that any storage can be used as a backend storage for a RAID storage, although typically a ClientStorage will be the direct backend.

[ ZEO 1 ] ... [ ZEO N ]
\ /
\ /
\ /
\ /
\ /
\ /
[ ZEO RAID ]
/ \
/ \
/ \
/ \
/ \
/ \
[ Zope 1 ] ... [ Zope M]


My use case is like this:

» Read More

Today I tried PloneOut. It is a buildout recipe to install Zope 2.10 + Plone 3.0 and some other products. It works like a charm.
The buildout tool makes the process of installing complex software as easy as a click.
Here are the steps:
$ svn co https://svn.plone.org/svn/plone/ploneout/trunk ploneout
Go and drink a cup coffee
$ cd ploneout
$ python bootstrap.py
$ bin/buildout -v
Put on your watch and your shoes, head out the door and walk 2 km. When you come back you will find your plone 3.0 ready for you. I regret I didn't so.
$./bin/instance fg
point your browser to:
http://localhost:8080/manage

add a plone site and try the edit-in-place feature.