1 import cgi
2 import cherrypy
3
4
14
16 """Internal: read lines until EOF."""
17 while 1:
18 line = self.fp.readline(1<<16)
19 if not line:
20 self.done = -1
21 break
22 self.__write(line)
23
25 """Internal: read lines until outerboundary."""
26 next = "--" + self.outerboundary
27 last = next + "--"
28 delim = ""
29 last_line_lfend = True
30 while 1:
31 line = self.fp.readline(1<<16)
32 if not line:
33 self.done = -1
34 break
35 if line[:2] == "--" and last_line_lfend:
36 strippedline = line.strip()
37 if strippedline == next:
38 break
39 if strippedline == last:
40 self.done = 1
41 break
42 odelim = delim
43 if line[-2:] == "\r\n":
44 delim = "\r\n"
45 line = line[:-2]
46 last_line_lfend = True
47 elif line[-1] == "\n":
48 delim = "\n"
49 line = line[:-1]
50 last_line_lfend = True
51 else:
52 delim = ""
53 last_line_lfend = False
54 self.__write(odelim + line)
55
57 """Internal: skip lines until outer boundary if defined."""
58 if not self.outerboundary or self.done:
59 return
60 next = "--" + self.outerboundary
61 last = next + "--"
62 last_line_lfend = True
63 while 1:
64 line = self.fp.readline(1<<16)
65 if not line:
66 self.done = -1
67 break
68 if line[:2] == "--" and last_line_lfend:
69 strippedline = line.strip()
70 if strippedline == next:
71 break
72 if strippedline == last:
73 self.done = 1
74 break
75 if line.endswith('\n'):
76 last_line_lfend = True
77 else:
78 last_line_lfend = False
79