def do_PUT(self, environ, start_response):
path = environ["<STR_LIT>"]<EOL>provider = self._davProvider<EOL>res = provider.get_resource_inst(path, environ)<EOL>parentRes = provider.get_resource_inst(util.get_uri_parent(path), environ)<EOL>isnewfile = res is None<EOL>if "<STR_LIT>" in environ:<EOL><INDENT>util.fail(HTTP_NOT_IMPLEMENTED, "<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" in environ:<EOL><INDENT>util.fail(<EOL>HTTP_BAD_REQUEST, "<STR_LIT>"<EOL>)<EOL><DEDENT>if res and res.is_collection:<EOL><INDENT>self._fail(HTTP_METHOD_NOT_ALLOWED, "<STR_LIT>")<EOL><DEDENT>elif (<EOL>parentRes is None or not parentRes.is_collection<EOL>):  <EOL><INDENT>self._fail(HTTP_CONFLICT, "<STR_LIT>")<EOL><DEDENT>self._evaluate_if_headers(res, environ)<EOL>if isnewfile:<EOL><INDENT>self._check_write_permission(parentRes, "<STR_LIT:0>", environ)<EOL>res = parentRes.create_empty_resource(util.get_uri_name(path))<EOL><DEDENT>else:<EOL><INDENT>self._check_write_permission(res, "<STR_LIT:0>", environ)<EOL><DEDENT>try:<EOL><INDENT>content_length = max(-<NUM_LIT:1>, int(environ.get("<STR_LIT>", -<NUM_LIT:1>)))<EOL><DEDENT>except ValueError:<EOL><INDENT>content_length = -<NUM_LIT:1><EOL><DEDENT>if (content_length < <NUM_LIT:0>) and (<EOL>environ.get("<STR_LIT>", "<STR_LIT>").lower() != "<STR_LIT>"<EOL>):<EOL><INDENT>agent = environ.get("<STR_LIT>", "<STR_LIT>")<EOL>if "<STR_LIT>" in agent or "<STR_LIT>" in agent:  <EOL><INDENT>_logger.warning(<EOL>"<STR_LIT>"<EOL>)<EOL>content_length = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>util.fail(<EOL>HTTP_LENGTH_REQUIRED,<EOL>"<STR_LIT>".format(<EOL>environ.get("<STR_LIT>")<EOL>),<EOL>)<EOL><DEDENT><DEDENT>hasErrors = False<EOL>try:<EOL><INDENT>if environ.get("<STR_LIT>", "<STR_LIT>").lower() == "<STR_LIT>":<EOL><INDENT>data_stream = self._stream_data_chunked(environ, self.block_size)<EOL><DEDENT>else:<EOL><INDENT>data_stream = self._stream_data(<EOL>environ, content_length, self.block_size<EOL>)<EOL><DEDENT>fileobj = res.begin_write(content_type=environ.get("<STR_LIT>"))<EOL>if getattr(fileobj, "<STR_LIT>", None):<EOL><INDENT>fileobj.writelines(data_stream)<EOL><DEDENT>else:<EOL><INDENT>for data in data_stream:<EOL><INDENT>fileobj.write(data)<EOL><DEDENT><DEDENT>fileobj.close()<EOL><DEDENT>except Exception as e:<EOL><INDENT>res.end_write(with_errors=True)<EOL>_logger.exception("<STR_LIT>")<EOL>util.fail(e)<EOL><DEDENT>res.end_write(hasErrors)<EOL>headers = None<EOL>if res.support_etag():<EOL><INDENT>entitytag = res.get_etag()<EOL>if entitytag is not None:<EOL><INDENT>headers = [("<STR_LIT>", '<STR_LIT>'.format(entitytag))]<EOL><DEDENT><DEDENT>if isnewfile:<EOL><INDENT>return util.send_status_response(<EOL>environ, start_response, HTTP_CREATED, add_headers=headers<EOL>)<EOL><DEDENT>return util.send_status_response(<EOL>environ, start_response, HTTP_NO_CONTENT, add_headers=headers<EOL>)<EOL>
@see: http://www.webdav.org/specs/rfc4918.html#METHOD_PUT