;ς α˜@c@spdZyeWnej odZdZnXdklZlZdklZdfd„ƒYZ dgZ dS( sζFile-like objects that read from or write to a string buffer. This implements (nearly) all stdio methods. f = StringIO() # ready for writing f = StringIO(buf) # ready for reading f.close() # explicitly release resources held flag = f.isatty() # always false buf = f.read() # returns the whole file (like getvalue()) buf = f.readline() # returns one line from the list buffer list = f.readlines()# the whole list buffer f.write(buf) # write at current position f.writelines(list) # extends the list buffer with another list f.getvalue() # return whole file's contents as a string Notes: FasterStringIO is a very basic but fast implementation with lot's of limitations. I ripped of all functionality that isn't needed by TAL and replaced the rest with a very basic implementation. Limitations: * read() does return all data * no seek/truncate/tell methods are available * write is unicode aware * readlines does't guarantee lines * no len value available You need the global request patch from PlacelessTranslationService! Based on the StringIO module from python 2.3 Adapted for the PlacelessTranslationService / SpeedPack by Christian Heimes Thanks to Andreas Jung for his idea to use list.append(). ii(s UnicodeTypes StringType(s_write_ValueErrorsFasterStringIOcBs‘tZdZdd„Zd„Zd„Zd„Zd„Zdd„Zd „Z d „Z e d „Z d „Z e d „Zd„Zd„Zd„Zd„ZRS(shclass FasterStringIO([buffer]) unicode aware and restricted version of StringIO for Zope's TAL scCs/g|_|ii|ƒd|_d|_dS(Ni(sselfsbufsappendslinepossclosed(sselfsbuf((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pys__init__3s  cCs|SdS(N(sself(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pys__iter__>scCs:|io t‚n|iƒ}| o t‚n|SdS(N(sselfscloseds StopIterationsreadlinesr(sselfsr((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysnextAs     cCs+|i od|_t|_|`ndS(Ni(sselfscloseds_write_ValueErrorswritesbuf(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pyscloseIs   cCs"|iotdƒ‚ntSdS(NsI/O operation on closed file(sselfscloseds ValueErrorsFalse(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysisattyOs icCstdƒ‚dS(Ns&FasterStringIO doesn't support seeking(s RuntimeError(sselfspossmode((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysseekTscCs|iotdƒ‚ndS(Ns#FasterStringIO doesn't support tell(sselfscloseds RuntimeError(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pystellWs cCs.|iotdƒ‚ndi|iƒSdS(NsI/O operation on closed files(sselfscloseds ValueErrorsjoinsbuf(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysread[s cCsX|iotdƒ‚n|it|iƒjo!|id7_|i|iSndS(NsI/O operation on closed filei(sselfscloseds ValueErrorslineposslensbuf(sselfslength((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysreadline`s  cCs |iSdS(N(sselfsbuf(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pys readlinesgscCstdƒ‚dS(Ns)FasterStringIO doesn't support truncating(s RuntimeError(sselfssize((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pystruncatejscCsΞ|iotdƒ‚n| odSnt|tƒo€ydkl}Wn-tj o!dk l }|ƒt }n X|ƒ}y|i }|i|ƒ}WqΊtj oqΊXn|ii|ƒdS(NsI/O operation on closed file(s get_request(sapplyRequestPatch(sselfscloseds ValueErrorsss isinstances UnicodeTypesGlobalss get_requests ImportErrors PatchStringIOsapplyRequestPatchsNonesrequestsRESPONSEsresponses_encode_unicodesAttributeErrorsbufsappend(sselfsssrequestsresponses get_requestsapplyRequestPatch((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pyswritems$      cCs|ii|ƒdS(N(sselfsbufsextendslist(sselfslist((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pys writelinesŒscCs|iotdƒ‚ndS(NsI/O operation on closed file(sselfscloseds RuntimeError(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysflushs cCs|iƒSdS(N(sselfsread(sself((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysgetvalue“s(s__name__s __module__s__doc__s__init__s__iter__snextsclosesisattysseekstellsreadsNonesreadlines readlinesstruncateswrites writelinessflushsgetvalue(((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pysFasterStringIO.s              sStringION( s__doc__sTrues NameErrorsFalsestypess UnicodeTypes StringTypesTAL.TALInterpreters_write_ValueErrorsFasterStringIOs__all__(s StringTypesFalses__all__sFasterStringIOs_write_ValueErrors UnicodeTypesTrue((sj/mnt/gmirror/ports/www/zope-placelesstranslationservice/work/PlacelessTranslationService/FasterStringIO.pys?$s  h