blob: be8aea0483096bf3ebc4e5c4cdd079095c07315a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import logging, os
from cStringIO import StringIO
# Handle efficient operations on a non-fixed length buffer like appending,
# replacing, reading chunks, etc
class ChunkBufferStringIO:
def __init__( self, data = '' ):
logging.debug( "Creating chunkbuffer: %s" % data )
self.io = StringIO();
self.len = 0
self.append( data )
def append( self, s ):
self.len += len( s )
self.io.write( s )
def replace( self, buf, start, end ):
self.io.seek( start )
self.io.write( buf[ end - start: ] )
self.io.seek( 0, os.SEEK_END )
def length( self ):
return self.len
def truncate( self, l ):
self.len = l
self.io.truncate( l )
def string(self):
return self.io.getvalue()
|