class_docstr: Test /component endpoint.
class_docstr_tok: ["Test","\/component","endpoint","."]
docstr: Test support for binary files reads.
docstr_tok: ["Test","support","for","binary","files","reads","."]
code: def test_support_binary_files_request(self):
      """Test support for binary files reads."""
  
      def _open_read(m, payload):
          is_binary = False
          args, kwargs = m.call_args
          if len(args) > 1:
              if "b" in args[1]:
                  is_binary = True
          encoding = "utf-8"
          if "encoding" in kwargs:
              encoding = kwargs["encoding"]
  
          if is_binary:
              from io import BytesIO
  
              return BytesIO(payload)
          else:
              from io import TextIOWrapper
  
              return TextIOWrapper(str(payload, encoding=encoding))
  
      with mock.patch(
          "streamlit.components.v1.components.os.path.isdir"
      ):
          declare_component("test", path=PATH)
  
      payload = b"\x00\x01\x00\x00\x00\x0D\x00\x80"  # binary non utf-8 payload
  
      with mock.patch(
          "streamlit.web.server.component_request_handler.open"
      ) as m:
          m.return_value.__enter__ = lambda _: _open_read(m, payload)
          response = self._request_component(
              "tests.streamlit.web.server.component_request_handler_test.test"
          )
  
      self.assertEqual(200, response.code)
      self.assertEqual(
          payload,
          response.body,
      )
  
file_path: streamlit/lib/tests/streamlit/web/server/component_request_handler_test.py
imports: from unittest import mock
  import tornado.testing
  import tornado.web
  from streamlit.components.v1.components import ComponentRegistry, declare_component
  from streamlit.web.server import ComponentRequestHandler
label_desc: Use image node_id 11 for calling the ComponentRequestHandlerTest obj's underlying member method code with example usage: obj.test_support_binary_files_request() and returns: BytesIO, TextIOWrapper