annotate Lib/dos-8x3/stringio.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents b41019557b6e
children da3c7d47f210
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3784
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # class StringIO implements file-like objects that read/write a
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 # string buffer (a.k.a. "memory files").
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # This implements (nearly) all stdio methods.
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # f = StringIO() # ready for writing
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # f = StringIO(buf) # ready for reading
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # f.close() # explicitly release resources held
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # flag = f.isatty() # always false
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 # pos = f.tell() # get current position
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 # f.seek(pos) # set current position
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 # f.seek(pos, mode) # mode 0: absolute; 1: relative; 2: relative to EOF
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # buf = f.read() # read until EOF
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 # buf = f.read(n) # read up to n bytes
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 # buf = f.readline() # read until end of line ('\n') or EOF
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 # list = f.readlines()# list of f.readline() results until EOF
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 # f.write(buf) # write at current position
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 # f.writelines(list) # for line in list: f.write(line)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 # f.getvalue() # return whole file's contents as a string
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 #
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 # Notes:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 # - Using a real file is often faster (but less convenient).
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 # - fileno() is left unimplemented so that code which uses it triggers
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 # an exception early.
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 # - Seeking far beyond EOF and then writing will insert real null
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 # bytes that occupy space in the buffer.
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 # - There's a simple test set (see end of this file).
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 import string
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 class StringIO:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 def __init__(self, buf = ''):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 self.buf = buf
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 self.len = len(buf)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 self.buflist = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 self.pos = 0
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 self.closed = 0
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 self.softspace = 0
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 def close(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 if not self.closed:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 self.closed = 1
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 del self.buf, self.pos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 def isatty(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 return 0
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 def seek(self, pos, mode = 0):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 if self.buflist:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 self.buf = self.buf + string.joinfields(self.buflist, '')
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 self.buflist = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 if mode == 1:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 pos = pos + self.pos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 elif mode == 2:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 pos = pos + self.len
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 self.pos = max(0, pos)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 def tell(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 return self.pos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 def read(self, n = -1):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 if self.buflist:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 self.buf = self.buf + string.joinfields(self.buflist, '')
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 self.buflist = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 if n < 0:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 newpos = self.len
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 else:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 newpos = min(self.pos+n, self.len)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 r = self.buf[self.pos:newpos]
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 self.pos = newpos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 return r
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 def readline(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 if self.buflist:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 self.buf = self.buf + string.joinfields(self.buflist, '')
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 self.buflist = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 i = string.find(self.buf, '\n', self.pos)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 if i < 0:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 newpos = self.len
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 else:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 newpos = i+1
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 r = self.buf[self.pos:newpos]
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 self.pos = newpos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 return r
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 def readlines(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 lines = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 line = self.readline()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 while line:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 lines.append(line)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 line = self.readline()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 return lines
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 def write(self, s):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 if not s: return
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 if self.pos > self.len:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 self.buflist.append('\0'*(self.pos - self.len))
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 self.len = self.pos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 newpos = self.pos + len(s)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 if self.pos < self.len:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 if self.buflist:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 self.buf = self.buf + string.joinfields(self.buflist, '')
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 self.buflist = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 self.buflist = [self.buf[:self.pos], s, self.buf[newpos:]]
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 self.buf = ''
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 else:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 self.buflist.append(s)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 self.len = newpos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 self.pos = newpos
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 def writelines(self, list):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 self.write(string.joinfields(list, ''))
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 def flush(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 pass
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 def getvalue(self):
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 if self.buflist:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 self.buf = self.buf + string.joinfields(self.buflist, '')
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 self.buflist = []
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 return self.buf
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 # A little test suite
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 def test():
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 import sys
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 if sys.argv[1:]:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 file = sys.argv[1]
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 else:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 file = '/etc/passwd'
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 lines = open(file, 'r').readlines()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 text = open(file, 'r').read()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 f = StringIO()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 for line in lines[:-2]:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 f.write(line)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 f.writelines(lines[-2:])
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 if f.getvalue() != text:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 raise RuntimeError, 'write failed'
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 length = f.tell()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 print 'File length =', length
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 f.seek(len(lines[0]))
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 f.write(lines[1])
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 f.seek(0)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 print 'First line =', `f.readline()`
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 here = f.tell()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 line = f.readline()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 print 'Second line =', `line`
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 f.seek(-len(line), 1)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 line2 = f.read(len(line))
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 if line != line2:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 raise RuntimeError, 'bad result after seek back'
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 f.seek(len(line2), 1)
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 list = f.readlines()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 line = list[-1]
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 f.seek(f.tell() - len(line))
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 line2 = f.read()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 if line != line2:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 raise RuntimeError, 'bad result after seek back from EOF'
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 print 'Read', len(list), 'more lines'
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 print 'File length =', f.tell()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 if f.tell() != length:
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 raise RuntimeError, 'bad length'
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 f.close()
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 if __name__ == '__main__':
b41019557b6e Fuck. For PC support, this must be in the distribution.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 test()