@staticmethod<EOL><INDENT>def encode_body(req):<DEDENT>
if isinstance(req.body, text_type):<EOL><INDENT>split = req.headers.get('<STR_LIT>', '<STR_LIT>').split('<STR_LIT:;>')<EOL>if len(split) == <NUM_LIT:2>:<EOL><INDENT>ct, cs = split<EOL>cs = cs.split('<STR_LIT:=>')[<NUM_LIT:1>]<EOL>req.body = req.body.encode(cs)<EOL><DEDENT>else:<EOL><INDENT>ct = split[<NUM_LIT:0>]<EOL>if (ct == '<STR_LIT>' or<EOL>'<STR_LIT>' in ct):<EOL><INDENT>req.body = req.body.encode()<EOL><DEDENT>else:<EOL><INDENT>req.body = req.body.encode('<STR_LIT:utf-8>')<EOL>req.headers['<STR_LIT>'] = ct + '<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT>
Encode body of request to bytes and update content-type if required.

If the body of req is Unicode then encode to the charset found in
content-type header if present, otherwise UTF-8, or ASCII if
content-type is application/x-www-form-urlencoded. If encoding to UTF-8
then add charset to content-type. Modifies req directly, does not
return a modified copy.

req -- Requests PreparedRequest object