Python Programming, news on the Voidspace Python Projects and all things techie.

rest2web 0.5.1

emoticon:target rest2web 0.5.1 is now available. This is a minor feature enhancement release.

What Is rest2web?

Maintaining websites or project documentation in HTML is a pain. rest2web takes out the pain, and brings back the joy. Wink

rest2web is a simple tool that lets you build your website from a single template (or as many as you want), and keep the contents in ReStructured Text. (You can still keep pages in HTML if needed.)

It has an easy to use templating system, with embedded Python for unlimited flexibility and no new templating language to learn. It has built in functions or creating sidebars and navigation elements of a site.

What's New in 0.5.1 ?

Added some extra debugging info to syntax errors in the templates.

Fixed odict and pathutils for Python 2.5 compatibility.

Added the 'promote_headers' option to the config file.

Added the sortpages method to the sections. This sorts the pages in a section (or all sections) alphabetically. You can also pass in a custom sort function.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-12-19 18:21:31 | |

Categories: ,

More ConfigObj Fixes in Subversion

emoticon:scanner Nicola Larosa has checked in some more changes to ConfigObj.

The latest changes are to ConfigObj, validate and the docs :

The changes are :

  • Fixed validate doc to talk of boolean instead of bool; changed the is_bool function to is_boolean (Sourceforge bug #1531525). Thanks to the reporter for this one.
  • Added a missing self. in the _handle_comment method and a related test, per Sourceforge bug #1523975. Thanks to the reporter for this one too.
  • Allowed arbitrary indentation in the indent_type parameter, removed the NUM_INDENT_SPACES and MAX_INTERPOL_DEPTH (a leftover) constants, added indentation tests (including another docutils workaround, sigh), updated the documentation. Thanks for this one go to Jorge Vargas, even if I ended up not using his patch that added a new indent_size parameter.
  • Made the import of compiler conditional so that ConfigObj will run on IronPython

There are still some further changes to go in. Nicola and I are discussing how and if all the proposed features should be added.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-12-17 21:14:46 | |

Categories: , ,

New Windows Forms Tutorial Entry

emoticon:apple In celebration of the new IronPython section I've added a new entry to the Windows Forms Tutorial Series.

This is entry number eleven :

It uses a few new controls to create a slightly more complex GUI than we've seen before in this series.

A Vertical Splitter

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-12-17 20:44:39 | |

Categories: , ,

New IronPython Section

emoticon:boxing_gloves I've created a new section on Voidspace :

I've moved the Windows Forms tutorials here and setup an aggregator for IronPython related blogs.

If you spot any typos, or know of any good blogs I should add to the Planet feed then let me know.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-12-17 20:44:03 | |

Categories: ,

Selfless as a Metaclass

emoticon:speaker Having created a decorator that removes the need to explicitly declare self in methods, wouldn't it be nice to be able to apply it automatically ? Wink

An Introduction to Metaclasses is a brief tutorial that explains the basics of metaclasses. It creates a metaclass factory which produces metaclasses that decorate all the methods in a class with a function.

This is illustrated by creating a metaclass called Selfless that automatically wraps every method in classes with the selfless decorator from the previous entry. Smile

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-12-16 23:34:14 | |

Categories: ,

Selfless Python

emoticon:torch Have you ever had friends who wouldn't try Python because of the explicit declaration of self ? Well, me neither actually; but I do know at least one Polish Ruby programmer [1] who dislikes it. But if you did know people like that, your worries would be over...

To follow this frippery you'll need the Byteplay module.

Below is a decorator named selfless. It automatically adds the self argument to methods on classes, so they can be defined without it.

The Test class proves that it works. Smile

from byteplay import Code, opmap

def _transmute(opcode, arg):
    if ((opcode == opmap['LOAD_GLOBAL']) and
        (arg == 'self')):
        return opmap['LOAD_FAST'], arg
    return opcode, arg

def selfless(function):
    code = Code.from_code(function.func_code)
    code.args = tuple(['self'] + list(code.args))
    code.code = [_transmute(op, arg) for op, arg in code.code]
    function.func_code = code.to_code()
    return function

class Test(object):

    def __init__(x=None):
        self.x = x

    def getX():
        print self.x

    def setX(x):
        self.x = x

test = Test()


Because self isn't passed explicitly to the functions, the interpreter treats self as a global. selfless (and its sidekick _transmute) change the LOAD_GLOBAL op-codes into LOAD_FAST. We then tell the code object that it takes an extra argument, self. The byteplay Code automatically handles setting the correct stack-size on the new code object it creates.

In the next exciting instalment we'll (well, me actually...) create a metaclass that applies this automatically to all methods in a class.

If you're interesting in bytecodes and code objects, you may be interested in Anonymous Code Blocks in Python.

[1]Mentioning no names Andrzej...

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-12-16 21:31:14 | |

Categories: ,

Hosted by Webfaction