MCPcopy
hub / github.com/pallets/werkzeug / get_environ

Method get_environ

src/werkzeug/test.py:667–753  ·  view source on GitHub ↗

Return the built environ. .. versionchanged:: 0.15 The content type and length headers are set based on input stream detection. Previously this only set the WSGI keys.

(self)

Source from the content-addressed store, hash-verified

665 self.closed = True
666
667 def get_environ(self) -> WSGIEnvironment:
668 """Return the built environ.
669
670 .. versionchanged:: 0.15
671 The content type and length headers are set based on
672 input stream detection. Previously this only set the WSGI
673 keys.
674 """
675 input_stream = self.input_stream
676 content_length = self.content_length
677
678 mimetype = self.mimetype
679 content_type = self.content_type
680
681 if input_stream is not None:
682 start_pos = input_stream.tell()
683 input_stream.seek(0, 2)
684 end_pos = input_stream.tell()
685 input_stream.seek(start_pos)
686 content_length = end_pos - start_pos
687 elif mimetype == "multipart/form-data":
688 input_stream, content_length, boundary = stream_encode_multipart(
689 CombinedMultiDict([self.form, self.files])
690 )
691 content_type = f'{mimetype}; boundary="{boundary}"'
692 elif mimetype == "application/x-www-form-urlencoded":
693 form_encoded = _urlencode(self.form).encode("ascii")
694 content_length = len(form_encoded)
695 input_stream = BytesIO(form_encoded)
696 else:
697 input_stream = BytesIO()
698
699 result: WSGIEnvironment = {}
700 if self.environ_base:
701 result.update(self.environ_base)
702
703 def _path_encode(x: str) -> str:
704 return _wsgi_encoding_dance(unquote(x))
705
706 raw_uri = _wsgi_encoding_dance(self.request_uri)
707 result.update(
708 {
709 "REQUEST_METHOD": self.method,
710 "SCRIPT_NAME": _path_encode(self.script_root),
711 "PATH_INFO": _path_encode(self.path),
712 "QUERY_STRING": _wsgi_encoding_dance(self.query_string),
713 # Non-standard, added by mod_wsgi, uWSGI
714 "REQUEST_URI": raw_uri,
715 # Non-standard, added by gunicorn
716 "RAW_URI": raw_uri,
717 "SERVER_NAME": self.server_name,
718 "SERVER_PORT": str(self.server_port),
719 "HTTP_HOST": self.host,
720 "SERVER_PROTOCOL": self.server_protocol,
721 "wsgi.version": self.wsgi_version,
722 "wsgi.url_scheme": self.url_scheme,
723 "wsgi.input": input_stream,
724 "wsgi.errors": self.errors_stream,

Callers 10

get_requestMethod · 0.95
create_environFunction · 0.95
test_send_file.pyFile · 0.80
test_redirectFunction · 0.80

Calls 12

stream_encode_multipartFunction · 0.85
CombinedMultiDictClass · 0.85
_urlencodeFunction · 0.85
_wsgi_encoding_danceFunction · 0.85
to_wsgi_listMethod · 0.80
appendMethod · 0.80
tellMethod · 0.45
seekMethod · 0.45
updateMethod · 0.45
copyMethod · 0.45
removeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected