Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(168208)

Side by Side Diff: Lib/http/server.py

Issue 11352: Update cgi module doc
Patch Set: Created 7 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« Doc/make.bat ('K') | « Doc/make.bat ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """HTTP server classes. 1 """HTTP server classes.
2 2
3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see 3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see
4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, 4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST,
5 and CGIHTTPRequestHandler for CGI scripts. 5 and CGIHTTPRequestHandler for CGI scripts.
6 6
7 It does, however, optionally implement HTTP/1.1 persistent connections, 7 It does, however, optionally implement HTTP/1.1 persistent connections,
8 as of version 0.3. 8 as of version 0.3.
9 9
10 Notes on CGIHTTPRequestHandler 10 Notes on CGIHTTPRequestHandler
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 # On Windows, use python.exe, not pythonw.exe 1130 # On Windows, use python.exe, not pythonw.exe
1131 interp = interp[:-5] + interp[-4:] 1131 interp = interp[:-5] + interp[-4:]
1132 cmdline = [interp, '-u'] + cmdline 1132 cmdline = [interp, '-u'] + cmdline
1133 if '=' not in query: 1133 if '=' not in query:
1134 cmdline.append(query) 1134 cmdline.append(query)
1135 self.log_message("command: %s", subprocess.list2cmdline(cmdline)) 1135 self.log_message("command: %s", subprocess.list2cmdline(cmdline))
1136 try: 1136 try:
1137 nbytes = int(length) 1137 nbytes = int(length)
1138 except (TypeError, ValueError): 1138 except (TypeError, ValueError):
1139 nbytes = 0 1139 nbytes = 0
1140 stdin = subprocess.PIPE
1141 data = None
1142 if self.command.lower() == "post" and nbytes > 0:
1143 # try to read all bytes in one read
1144 data = self.rfile.read(nbytes)
1145 if len(data)<nbytes:
1146 # store data in temporary file
1147 import tempfile
1148 rfile = tempfile.TemporaryFile("wb+")
1149 rfile.write(data)
1150 bufsize = 2 << 16
1151 while True:
1152 buf = self.rfile.read(bufsize)
1153 if not buf:
1154 break
1155 rfile.write(buf)
1156 if rfile.tell()==nbytes:
1157 break
1158 rfile.seek(0)
1159 # set stdin to the temporary file
1160 stdin = rfile
1161 data = None
1162 # throw away additional data [see bug #427345]
1163 while select.select([self.rfile._sock], [], [], 0)[0]:
1164 if not self.rfile._sock.recv(1):
1165 break
1140 p = subprocess.Popen(cmdline, 1166 p = subprocess.Popen(cmdline,
1141 stdin=subprocess.PIPE, 1167 stdin=stdin,
Jim.J.Jewett 2014/03/20 20:37:33 This change is not just documentation, and should
1142 stdout=subprocess.PIPE, 1168 stdout=subprocess.PIPE,
1143 stderr=subprocess.PIPE, 1169 stderr=subprocess.PIPE,
1144 env = env 1170 env = env
1145 ) 1171 )
1146 if self.command.lower() == "post" and nbytes > 0:
1147 data = self.rfile.read(nbytes)
1148 else:
1149 data = None
1150 # throw away additional data [see bug #427345]
1151 while select.select([self.rfile._sock], [], [], 0)[0]:
1152 if not self.rfile._sock.recv(1):
1153 break
1154 stdout, stderr = p.communicate(data) 1172 stdout, stderr = p.communicate(data)
1155 self.wfile.write(stdout) 1173 self.wfile.write(stdout)
1156 if stderr: 1174 if stderr:
1157 self.log_error('%s', stderr) 1175 self.log_error('%s', stderr)
1158 p.stderr.close() 1176 p.stderr.close()
1159 p.stdout.close() 1177 p.stdout.close()
1160 status = p.returncode 1178 status = p.returncode
1161 if status: 1179 if status:
1162 self.log_error("CGI script exit status %#x", status) 1180 self.log_error("CGI script exit status %#x", status)
1163 else: 1181 else:
(...skipping 22 matching lines...) Expand all
1186 print("Serving HTTP on", sa[0], "port", sa[1], "...") 1204 print("Serving HTTP on", sa[0], "port", sa[1], "...")
1187 try: 1205 try:
1188 httpd.serve_forever() 1206 httpd.serve_forever()
1189 except KeyboardInterrupt: 1207 except KeyboardInterrupt:
1190 print("\nKeyboard interrupt received, exiting.") 1208 print("\nKeyboard interrupt received, exiting.")
1191 httpd.server_close() 1209 httpd.server_close()
1192 sys.exit(0) 1210 sys.exit(0)
1193 1211
1194 if __name__ == '__main__': 1212 if __name__ == '__main__':
1195 test(HandlerClass=SimpleHTTPRequestHandler) 1213 test(HandlerClass=SimpleHTTPRequestHandler)
OLDNEW
« Doc/make.bat ('K') | « Doc/make.bat ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+