File: testio.py

package info (click to toggle)
python-rarfile 2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 340 kB
  • ctags: 306
  • sloc: python: 1,764; makefile: 156; sh: 36
file content (35 lines) | stat: -rwxr-xr-x 755 bytes parent folder | download | duplicates (2)
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
31
32
33
34
35
#! /usr/bin/env python

import rarfile, os, os.path, time, sys

try:
    from io import BufferedReader, TextIOWrapper
except ImportError:
    print('no io module')
    sys.exit(0)
    def BufferedReader(x): return x
    def TextIOWrapper(x): return x

def test_readline(rf, fn):
    f = rf.open(fn)
    tr = TextIOWrapper(BufferedReader(f))
    while 1:
        ln = tr.readline()
        if not ln:
            break
    tr.close()

def main():
    files = ['stest1.txt', 'stest2.txt']
    arc = 'files/seektest.rar'

    rf = rarfile.RarFile(arc, crc_check=0)
    for fn in files:
        sys.stdout.write('test/readline: %s .. ' % fn)
        sys.stdout.flush()
        test_readline(rf, fn)
        print('ok')

if __name__ == '__main__':
    main()