def parse_xml_body(environ, allow_empty=False):
<EOL>clHeader = environ.get("<STR_LIT>", "<STR_LIT>").strip()<EOL>if clHeader == "<STR_LIT>":<EOL><INDENT>requestbody = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>content_length = int(clHeader)<EOL>if content_length < <NUM_LIT:0>:<EOL><INDENT>raise DAVError(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>raise DAVError(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT>if content_length == <NUM_LIT:0>:<EOL><INDENT>requestbody = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>requestbody = environ["<STR_LIT>"].read(content_length)<EOL>environ["<STR_LIT>"] = <NUM_LIT:1><EOL><DEDENT><DEDENT>if requestbody == "<STR_LIT>":<EOL><INDENT>if allow_empty:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>raise DAVError(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT><DEDENT>try:<EOL><INDENT>rootEL = etree.fromstring(requestbody)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise DAVError(HTTP_BAD_REQUEST, "<STR_LIT>", src_exception=e)<EOL><DEDENT>if environ.get("<STR_LIT>"):<EOL><INDENT>_logger.info(<EOL>"<STR_LIT>".format(<EOL>environ["<STR_LIT>"],<EOL>compat.to_native(xml_to_bytes(rootEL, pretty_print=True)),<EOL>)<EOL>)<EOL>environ["<STR_LIT>"] = False<EOL><DEDENT>return rootEL<EOL>
Read request body XML into an etree.Element.

    Return None, if no request body was sent.
    Raise HTTP_BAD_REQUEST, if something else went wrong.

    TODO: this is a very relaxed interpretation: should we raise HTTP_BAD_REQUEST
    instead, if CONTENT_LENGTH is missing, invalid, or 0?

    RFC: For compatibility with HTTP/1.0 applications, HTTP/1.1 requests containing
    a message-body MUST include a valid Content-Length header field unless the
    server is known to be HTTP/1.1 compliant.
    If a request contains a message-body and a Content-Length is not given, the
    server SHOULD respond with 400 (bad request) if it cannot determine the
    length of the message, or with 411 (length required) if it wishes to insist
    on receiving a valid Content-Length."

    So I'd say, we should accept a missing CONTENT_LENGTH, and try to read the
    content anyway.
    But WSGI doesn't guarantee to support input.read() without length(?).
    At least it locked, when I tried it with a request that had a missing
    content-type and no body.

    Current approach: if CONTENT_LENGTH is

    - valid and >0:
      read body (exactly <CONTENT_LENGTH> bytes) and parse the result.
    - 0:
      Assume empty body and return None or raise exception.
    - invalid (negative or not a number:
      raise HTTP_BAD_REQUEST
    - missing:
      NOT: Try to read body until end and parse the result.
      BUT: assume '0'
    - empty string:
      WSGI allows it to be empty or absent: treated like 'missing'.