Module Expr Str Import alias Import alias ClassDef bases body FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr Num decorator_list FunctionDef arguments args NameParam defaults body If UnaryOpNot AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr Num Delete AttributeDel NameLoad attr AttributeDel NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body If AttributeLoad NameLoad attr body Raise NameLoad Str Return Num decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Num body If AttributeLoad NameLoad attr body Raise NameLoad Str If CompareEq NameLoad Num body Assign NameStore BinOpAdd NameLoad AttributeLoad NameLoad attr orelse If CompareEq NameLoad Num body Assign NameStore BinOpAdd NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call NameLoad Num NameLoad decorator_list FunctionDef arguments args NameParam defaults body If AttributeLoad NameLoad attr body Raise NameLoad Str Return AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults Num body If AttributeLoad NameLoad attr body Raise NameLoad Str If CompareLt NameLoad Num body Assign NameStore AttributeLoad NameLoad attr orelse Assign NameStore Call NameLoad BinOpAdd AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr Assign NameStore BinOpSub NameLoad AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr keyword NameLoad keyword AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad Return NameLoad decorator_list Assign NameStore Str FunctionDef arguments args NameParam NameParam defaults NameLoad body If AttributeLoad NameLoad attr body Raise NameLoad Str If CompareIs NameLoad NameLoad body Assign NameStore AttributeLoad NameLoad attr orelse If CompareLt NameLoad Num body Raise Call NameLoad AttributeLoad NameLoad attr Str orelse If CompareLt NameLoad AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str keyword AttributeLoad NameLoad attr keyword BinOpSub AttributeLoad NameLoad attr NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body If AttributeLoad NameLoad attr body Raise NameLoad Str If UnaryOpNot NameLoad body Return If CompareGt AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpMult Str BinOpSub AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr AttributeLoad NameLoad attr Assign NameStore BinOpAdd AttributeLoad NameLoad attr Call NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr NameLoad keyword AttributeLoad NameLoad attr keyword Call NameLoad NameLoad keyword AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body If AttributeLoad NameLoad attr body Raise NameLoad Str decorator_list decorator_list Expr Str
N/A N/A 
File-like objects that read from or write to a bsddb record.

This implements (nearly) all stdio methods.

f = DBRecIO(db, key, txn=None)
f.close()           # explicitly release resources held
flag = f.isatty()   # always false
pos = f.tell()      # get current position
f.seek(pos)         # set current position
f.seek(pos, mode)   # mode 0: absolute; 1: relative; 2: relative to EOF
buf = f.read()      # read until EOF
buf = f.read(n)     # read up to n bytes
f.truncate([size])  # truncate file at to at most size (default: current pos)
f.write(buf)        # write at current position
f.writelines(list)  # for line in list: f.write(line)

Notes:
- fileno() is left unimplemented so that code which uses it triggers
  an exception early.
- There's a simple test set (see end of this file) - not yet updated
  for DBRecIO.
- readline() is not implemented yet.


From:
    Itamar Shtull-Trauring <itamar@maxnm.com>
 N/A errno N/A string DBRecIO N/A N/A __init__ N/A N/A self db key txn N/A None N/A N/A N/A self db db N/A N/A self key key N/A N/A self txn txn N/A N/A self len None N/A N/A self pos 0 N/A N/A self closed 0 N/A N/A self softspace 0 N/A close N/A N/A self N/A N/A N/A N/A N/A self closed N/A N/A N/A self closed 1 N/A N/A self db N/A self txn N/A isatty N/A N/A self N/A N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A 0 N/A seek N/A N/A self pos mode N/A 0 N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A N/A mode 1 N/A N/A pos N/A pos N/A self pos N/A N/A N/A mode 2 N/A N/A pos N/A pos N/A self len N/A N/A self pos N/A max 0 pos N/A tell N/A N/A self N/A N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A N/A self pos N/A read N/A N/A self n N/A -1 N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A N/A n 0 N/A N/A newpos N/A self len N/A N/A newpos N/A min N/A N/A self pos n N/A self len N/A dlen N/A newpos N/A self pos N/A r N/A N/A N/A self db get N/A self key txn N/A self txn dlen dlen doff N/A self pos N/A N/A self pos newpos N/A r N/A N/A __fixme 
    def readline(self, length=None):
        if self.closed:
            raise ValueError, "I/O operation on closed file"
        if self.buflist:
            self.buf = self.buf + string.joinfields(self.buflist, '')
            self.buflist = []
        i = string.find(self.buf, '
', self.pos)
        if i < 0:
            newpos = self.len
        else:
            newpos = i+1
        if length is not None:
            if self.pos + length < newpos:
                newpos = self.pos + length
        r = self.buf[self.pos:newpos]
        self.pos = newpos
        return r

    def readlines(self, sizehint = 0):
        total = 0
        lines = []
        line = self.readline()
        while line:
            lines.append(line)
            total += len(line)
            if 0 < sizehint <= total:
                break
            line = self.readline()
        return lines
     truncate N/A N/A self size N/A None N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A N/A size None N/A N/A size N/A self pos N/A N/A N/A size 0 N/A N/A N/A IOError N/A errno EINVAL Negative size not allowed N/A N/A N/A size N/A self pos N/A N/A N/A self pos size N/A N/A N/A N/A self db put N/A self key txn N/A self txn dlen N/A N/A self len size doff size N/A write N/A N/A self s N/A N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A N/A s N/A N/A N/A N/A N/A self pos N/A self len N/A N/A N/A N/A N/A self buflist append N/A N/A N/A self pos N/A self len N/A N/A self len N/A self pos N/A newpos N/A N/A self pos N/A len s N/A N/A N/A N/A self db put N/A self key s txn N/A self txn dlen N/A len s doff N/A self pos N/A N/A self pos newpos N/A writelines N/A N/A self list N/A N/A N/A N/A N/A self write N/A N/A string joinfields list N/A flush N/A N/A self N/A N/A N/A N/A self closed N/A N/A ValueError I/O operation on closed file N/A N/A N/A 
# A little test suite

def _test():
    import sys
    if sys.argv[1:]:
        file = sys.argv[1]
    else:
        file = '/etc/passwd'
    lines = open(file, 'r').readlines()
    text = open(file, 'r').read()
    f = StringIO()
    for line in lines[:-2]:
        f.write(line)
    f.writelines(lines[-2:])
    if f.getvalue() != text:
        raise RuntimeError, 'write failed'
    length = f.tell()
    print 'File length =', length
    f.seek(len(lines[0]))
    f.write(lines[1])
    f.seek(0)
    print 'First line =', repr(f.readline())
    here = f.tell()
    line = f.readline()
    print 'Second line =', repr(line)
    f.seek(-len(line), 1)
    line2 = f.read(len(line))
    if line != line2:
        raise RuntimeError, 'bad result after seek back'
    f.seek(len(line2), 1)
    list = f.readlines()
    line = list[-1]
    f.seek(f.tell() - len(line))
    line2 = f.read()
    if line != line2:
        raise RuntimeError, 'bad result after seek back from EOF'
    print 'Read', len(list), 'more lines'
    print 'File length =', f.tell()
    if f.tell() != length:
        raise RuntimeError, 'bad length'
    f.close()

if __name__ == '__main__':
    _test()
