#!/usr/bin/env python """ uri.py - Pluvo URI Datatype Author: Sean B. Palmer, inamidst.com """ import urllib import cStringIO as StringIO from string import String doc = StringIO.StringIO("""\ 1. pqrst 2. something 3. Swhack! """) doc.seek(0) tdoc = StringIO.StringIO("""\ 1. pqrst """) tdoc.seek(0) words = StringIO.StringIO("""\ 1. Arduarauenatone 2. Bemuddlefraught 3. Chrononhotonthologos 4. Dhghemon 5. Ealsegate 6. Feaxede 7. Geremumble 8. Honorificabilitudinitatibus 9. Inquisiturient (@@) 10. Jiggajoggy (@@) 11. Karekomoontes 12. Lanthorne 13. Mucilaginous (@@) 14. Nightingale (@@) 15. Orichalcum 16. Ptarmigan (@@) 17. Quothquan 18. Regenwahrscheinlichkeit (@@) 19. Snulbug 20. Thesmophoriazousae 21. Utchy 22. Vyaedick 23. Wirrikow (@@) 24. Xiphophorus 25. Ywrygeliche 26. Zatenfare (@@) """) words.seek(0) # Ablewhackets # Agreeeth # Cyllowre # Esquivalience # Forlecgan # Forleigremanslihte # Frenigerent # Highwaywoman # Jumpling # Nihtgenga # Platypussery # Tatterdemallian # Uidemarsdendownloads # Xiphiplastron # Yclepement class URI(object): def __init__(self, uri): self.uri = uri def __repr__(self): return "URI(%r)" % self.uri def __iter__(self): if self.uri == 'pluvo://doc': for line in doc: yield String(line) elif self.uri == 'tag:pluvo.org,2006:doc': for line in tdoc: yield String(line) elif self.uri == 'tag:pluvo.org,2006:words': for line in words: yield String(line) else: f = urllib.urlopen(self.uri) for line in f: yield String(line) f.close() def trim(string): return string.strip(' \t\r\n') if __name__ == '__main__': print trim(__doc__)