view tests/objects.py @ 21:4f7c05630f36

tie up some factory loose ends and sweeten the API with syntactic sugar
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 06 Jun 2011 07:39:18 -0700
parents 0bea5297c156
children 362912842985
line wrap: on
line source

"""
test objects
"""

def stringsort(*strings):
    return ''.join(sorted(''.join(strings)))

class StringMunge(object):
    def __init__(self, prefix, delimeter=':', callback=None):
        self.delimeter = delimeter
        self.prefix = prefix
        self.callback = callback
    def __call__(self, string):
        if self.callback:
            string = self.callback(string)
        return self.prefix + self.delimeter + string

class Foo(object):
    def __init__(self, a, b):
        self.factor = a*100 + b
    def __call__(self, number):
        return number * self.factor