MCPcopy Index your code
hub / github.com/RustPython/RustPython / do_request_

Method do_request_

Lib/urllib/request.py:1242–1278  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

1240 request.get_method())
1241
1242 def do_request_(self, request):
1243 host = request.host
1244 if not host:
1245 raise URLError('no host given')
1246
1247 if request.data is not None: # POST
1248 data = request.data
1249 if isinstance(data, str):
1250 msg = "POST data should be bytes, an iterable of bytes, " \
1251 "or a file object. It cannot be of type str."
1252 raise TypeError(msg)
1253 if not request.has_header('Content-type'):
1254 request.add_unredirected_header(
1255 'Content-type',
1256 'application/x-www-form-urlencoded')
1257 if (not request.has_header('Content-length')
1258 and not request.has_header('Transfer-encoding')):
1259 content_length = self._get_content_length(request)
1260 if content_length is not None:
1261 request.add_unredirected_header(
1262 'Content-length', str(content_length))
1263 else:
1264 request.add_unredirected_header(
1265 'Transfer-encoding', 'chunked')
1266
1267 sel_host = host
1268 if request.has_proxy():
1269 scheme, sel = _splittype(request.selector)
1270 sel_host, sel_path = _splithost(sel)
1271 if not request.has_header('Host'):
1272 request.add_unredirected_header('Host', sel_host)
1273 for name, value in self.parent.addheaders:
1274 name = name.capitalize()
1275 if not request.has_header(name):
1276 request.add_unredirected_header(name, value)
1277
1278 return request
1279
1280 def do_open(self, http_class, req, **http_conn_args):
1281 """Return an HTTPResponse object for the request, using http_class.

Callers 9

test_httpMethod · 0.95
test_http_body_fileMethod · 0.95
test_http_body_pipeMethod · 0.95
test_http_body_arrayMethod · 0.95
test_http_doubleslashMethod · 0.95

Calls 10

_get_content_lengthMethod · 0.95
URLErrorClass · 0.90
_splittypeFunction · 0.90
_splithostFunction · 0.90
isinstanceFunction · 0.85
strFunction · 0.85
has_proxyMethod · 0.80
has_headerMethod · 0.45
capitalizeMethod · 0.45

Tested by 9

test_httpMethod · 0.76
test_http_body_fileMethod · 0.76
test_http_body_pipeMethod · 0.76
test_http_body_arrayMethod · 0.76
test_http_doubleslashMethod · 0.76