code: def _encode_codepage(codepage, text):
      
  
      assert isinstance(text, text_type)
  
      if not text:
          return b""
  
      size = (len(text.encode("utf-16-le", _surrogatepass)) //
              ctypes.sizeof(winapi.WCHAR))
  
      # get the required buffer size
      length = winapi.WideCharToMultiByte(
          codepage, 0, text, size, None, 0, None, None)
      if length == 0:
          raise ctypes.WinError()
  
      # decode to the buffer
      buf = ctypes.create_string_buffer(length)
      length = winapi.WideCharToMultiByte(
          codepage, 0, text, size, buf, length, None, None)
      if length == 0:
          raise ctypes.WinError()
      return buf[:length]
docs: Args:
          codepage (int)
          text (text)
      Returns:
          `bytes`
  
      Encode text using the given code page. Will not fail if a char
      can't be encoded using that codepage.