#!/usr/bin/env python """ string.py - Pluvo String Datatype Author: Sean B. Palmer, inamidst.com """ class String(object): def __init__(self, *args): # This mess is because normally we get (self, chars), but when called as # @String in a Pluvo program we get (self, env, chars), where chars is a # String itself, not a str # self.chars = str(args[-1]) def __repr__(self): return 'S%r' % self.chars def __str__(self): return self.chars def __hash__(self): return hash(self.chars) def __eq__(self, other): # Cf. http://mail.python.org/pipermail/python-list/2006-May/339729.html try: otherChars = other.chars except AttributeError: return self.chars == other return self.chars == otherChars def __getattr__(self, attr): return getattr(self.chars, attr) def trim(string): return string.strip(' \t\r\n') if __name__ == '__main__': print trim(__doc__)