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

Method begin

Lib/http/client.py:329–399  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

327 return version, status, reason
328
329 def begin(self):
330 if self.headers is not None:
331 # we've already started reading the response
332 return
333
334 # read until we get a non-100 response
335 while True:
336 version, status, reason = self._read_status()
337 if status != CONTINUE:
338 break
339 # skip the header from the 100 response
340 skipped_headers = _read_headers(self.fp)
341 if self.debuglevel > 0:
342 print("headers:", skipped_headers)
343 del skipped_headers
344
345 self.code = self.status = status
346 self.reason = reason.strip()
347 if version in ("HTTP/1.0", "HTTP/0.9"):
348 # Some servers might still return "0.9", treat it as 1.0 anyway
349 self.version = 10
350 elif version.startswith("HTTP/1."):
351 self.version = 11 # use HTTP/1.1 code for HTTP/1.x where x>=1
352 else:
353 raise UnknownProtocol(version)
354
355 self.headers = self.msg = parse_headers(self.fp)
356
357 if self.debuglevel > 0:
358 for hdr, val in self.headers.items():
359 print("header:", hdr + ":", val)
360
361 # are we using the chunked-style of transfer encoding?
362 tr_enc = self.headers.get("transfer-encoding")
363 if tr_enc and tr_enc.lower() == "chunked":
364 self.chunked = True
365 self.chunk_left = None
366 else:
367 self.chunked = False
368
369 # will the connection close at the end of the response?
370 self.will_close = self._check_close()
371
372 # do we have a Content-Length?
373 # NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is "chunked"
374 self.length = None
375 length = self.headers.get("content-length")
376 if length and not self.chunked:
377 try:
378 self.length = int(length)
379 except ValueError:
380 self.length = None
381 else:
382 if self.length < 0: # ignore nonsensical negative lengths
383 self.length = None
384 else:
385 self.length = None
386

Calls 11

_read_statusMethod · 0.95
_check_closeMethod · 0.95
_read_headersFunction · 0.85
UnknownProtocolClass · 0.85
parse_headersFunction · 0.85
printFunction · 0.50
stripMethod · 0.45
startswithMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45
lowerMethod · 0.45