(body, method)
return None
Get the content-length based on the body.

        If the body is None, we set Content-Length: 0 for methods that expect
        a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
        any method if the body is a str or bytes-like object and not a file.
Get the content-length based on the body.
Get the content - length based on the body .
def _get_content_length(body, method):
        """Get the content-length based on the body.

        If the body is None, we set Content-Length: 0 for methods that expect
        a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
        any method if the body is a str or bytes-like object and not a file.
        """
        if body is None:
            # do an explicit check for not None here to distinguish
            # between unset and set but empty
            if method.upper() in _METHODS_EXPECTING_BODY:
                return 0
            else:
                return None

        if hasattr(body, 'read'):
            # file-like object.
            return None

        try:
            # does it implement the buffer protocol (bytes, bytearray, array)?
            mv = memoryview(body)
            return mv.nbytes
        except TypeError:
            pass

        if isinstance(body, str):
            return len(body)

        return None
def _get_content_length ( body , method ) : if body is None : # do an explicit check for not None here to distinguish # between unset and set but empty if method . upper ( ) in _METHODS_EXPECTING_BODY : return 0 else : return None if hasattr ( body , 'read' ) : # file-like object. return None try : # does it implement the buffer protocol (bytes, bytearray, array)? mv = memoryview ( body ) return mv . nbytes except TypeError : pass if isinstance ( body , str ) : return len ( body ) return None