def _copy_or_move(self, environ, start_response, is_move):
srcPath = environ["<STR_LIT>"]<EOL>provider = self._davProvider<EOL>srcRes = provider.get_resource_inst(srcPath, environ)<EOL>srcParentRes = provider.get_resource_inst(util.get_uri_parent(srcPath), environ)<EOL>if srcRes is None:<EOL><INDENT>self._fail(HTTP_NOT_FOUND)<EOL><DEDENT>if "<STR_LIT>" not in environ:<EOL><INDENT>self._fail(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT>if not environ.setdefault("<STR_LIT>", "<STR_LIT:T>") in ("<STR_LIT:T>", "<STR_LIT:F>"):<EOL><INDENT>self._fail(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT>if util.get_content_length(environ) != <NUM_LIT:0>:<EOL><INDENT>body = environ["<STR_LIT>"].read(util.get_content_length(environ))<EOL>environ["<STR_LIT>"] = <NUM_LIT:1><EOL>_logger.info("<STR_LIT>".format(body[:<NUM_LIT:50>]))<EOL><DEDENT>if srcRes.is_collection:<EOL><INDENT>environ.setdefault("<STR_LIT>", "<STR_LIT>")<EOL>if not environ["<STR_LIT>"] in ("<STR_LIT:0>", "<STR_LIT>"):<EOL><INDENT>self._fail(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT>if is_move and environ["<STR_LIT>"] != "<STR_LIT>":<EOL><INDENT>self._fail(<EOL>HTTP_BAD_REQUEST,<EOL>"<STR_LIT>",<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>environ.setdefault("<STR_LIT>", "<STR_LIT:0>")<EOL>if not environ["<STR_LIT>"] in ("<STR_LIT:0>", "<STR_LIT>"):<EOL><INDENT>self._fail(HTTP_BAD_REQUEST, "<STR_LIT>")<EOL><DEDENT>environ["<STR_LIT>"] = "<STR_LIT:0>"<EOL><DEDENT>destinationHeader = compat.unquote(environ["<STR_LIT>"])<EOL>destScheme, destNetloc, destPath, _destParams, _destQuery, _destFrag = compat.urlparse(<EOL>destinationHeader, allow_fragments=False<EOL>)<EOL>if srcRes.is_collection:<EOL><INDENT>destPath = destPath.rstrip("<STR_LIT:/>") + "<STR_LIT:/>"<EOL><DEDENT>if destScheme and destScheme.lower() != environ["<STR_LIT>"].lower():<EOL><INDENT>self._fail(<EOL>HTTP_BAD_GATEWAY, "<STR_LIT>"<EOL>)<EOL><DEDENT>elif destNetloc and destNetloc.lower() != environ["<STR_LIT>"].lower():<EOL><INDENT>self._fail(<EOL>HTTP_BAD_GATEWAY, "<STR_LIT>"<EOL>)<EOL><DEDENT>elif not destPath.startswith(provider.mount_path + provider.share_path):<EOL><INDENT>self._fail(HTTP_BAD_GATEWAY, "<STR_LIT>")<EOL><DEDENT>destPath = destPath[len(provider.mount_path + provider.share_path) :]<EOL>assert destPath.startswith("<STR_LIT:/>")<EOL>destRes = provider.get_resource_inst(destPath, environ)<EOL>destExists = destRes is not None<EOL>destParentRes = provider.get_resource_inst(<EOL>util.get_uri_parent(destPath), environ<EOL>)<EOL>if not destParentRes or not destParentRes.is_collection:<EOL><INDENT>self._fail(HTTP_CONFLICT, "<STR_LIT>")<EOL><DEDENT>self._evaluate_if_headers(srcRes, environ)<EOL>self._evaluate_if_headers(destRes, environ)<EOL>if is_move:<EOL><INDENT>self._check_write_permission(srcRes, "<STR_LIT>", environ)<EOL>if srcParentRes:<EOL><INDENT>self._check_write_permission(srcParentRes, "<STR_LIT:0>", environ)<EOL><DEDENT><DEDENT>if not destExists:<EOL><INDENT>self._check_write_permission(destParentRes, "<STR_LIT:0>", environ)<EOL><DEDENT>self._check_write_permission(destRes, "<STR_LIT>", environ)<EOL>if srcPath == destPath:<EOL><INDENT>self._fail(HTTP_FORBIDDEN, "<STR_LIT>")<EOL><DEDENT>elif util.is_equal_or_child_uri(srcPath, destPath):<EOL><INDENT>self._fail(HTTP_FORBIDDEN, "<STR_LIT>")<EOL><DEDENT>if destExists and environ["<STR_LIT>"] != "<STR_LIT:T>":<EOL><INDENT>self._fail(<EOL>HTTP_PRECONDITION_FAILED,<EOL>"<STR_LIT>",<EOL>)<EOL><DEDENT>error_list = []<EOL>success_code = HTTP_CREATED<EOL>if destExists:<EOL><INDENT>success_code = HTTP_NO_CONTENT<EOL><DEDENT>try:<EOL><INDENT>if is_move:<EOL><INDENT>handled = srcRes.handle_move(destPath)<EOL><DEDENT>else:<EOL><INDENT>isInfinity = environ["<STR_LIT>"] == "<STR_LIT>"<EOL>handled = srcRes.handle_copy(destPath, isInfinity)<EOL><DEDENT>assert handled in (True, False) or type(handled) is list<EOL>if type(handled) is list:<EOL><INDENT>error_list = handled<EOL>handled = True<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>error_list = [(srcRes.get_href(), as_DAVError(e))]<EOL>handled = True<EOL><DEDENT>if handled:<EOL><INDENT>return self._send_response(<EOL>environ, start_response, srcRes, HTTP_NO_CONTENT, error_list<EOL>)<EOL><DEDENT>srcList = srcRes.get_descendants(add_self=True)<EOL>srcRootLen = len(srcPath)<EOL>destRootLen = len(destPath)<EOL>if destExists:<EOL><INDENT>if is_move or not destRes.is_collection or not srcRes.is_collection:<EOL><INDENT>_logger.debug("<STR_LIT>".format(destRes))<EOL>destRes.delete()<EOL>destRes = None<EOL><DEDENT>else:<EOL><INDENT>reverseDestList = destRes.get_descendants(<EOL>depth_first=True, add_self=False<EOL>)<EOL>srcPathList = [s.path for s in srcList]<EOL>_logger.debug("<STR_LIT>".format(srcPathList))<EOL>for dRes in reverseDestList:<EOL><INDENT>_logger.debug("<STR_LIT>".format(dRes))<EOL>relUrl = dRes.path[destRootLen:]<EOL>sp = srcPath + relUrl<EOL>if sp not in srcPathList:<EOL><INDENT>_logger.debug(<EOL>"<STR_LIT>".format(dRes)<EOL>)<EOL>dRes.delete()<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if is_move and srcRes.support_recursive_move(destPath):<EOL><INDENT>hasConflicts = False<EOL>for s in srcList:<EOL><INDENT>try:<EOL><INDENT>self._evaluate_if_headers(s, environ)<EOL><DEDENT>except Exception:<EOL><INDENT>hasConflicts = True<EOL>break<EOL><DEDENT><DEDENT>if not hasConflicts:<EOL><INDENT>try:<EOL><INDENT>_logger.debug("<STR_LIT>".format(srcRes, destPath))<EOL>error_list = srcRes.move_recursive(destPath)<EOL><DEDENT>except Exception as e:<EOL><INDENT>error_list = [(srcRes.get_href(), as_DAVError(e))]<EOL><DEDENT>return self._send_response(<EOL>environ, start_response, srcRes, success_code, error_list<EOL>)<EOL><DEDENT><DEDENT>ignoreDict = {}<EOL>for sRes in srcList:<EOL><INDENT>parentError = False<EOL>for ignorePath in ignoreDict.keys():<EOL><INDENT>if util.is_equal_or_child_uri(ignorePath, sRes.path):<EOL><INDENT>parentError = True<EOL>break<EOL><DEDENT><DEDENT>if parentError:<EOL><INDENT>_logger.debug(<EOL>"<STR_LIT>".format(sRes.path)<EOL>)<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>relUrl = sRes.path[srcRootLen:]<EOL>dPath = destPath + relUrl<EOL>self._evaluate_if_headers(sRes, environ)<EOL>sRes.copy_move_single(dPath, is_move)<EOL>if is_move and not sRes.is_collection:<EOL><INDENT>sRes.delete()<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>ignoreDict[sRes.path] = True<EOL>error_list.append((sRes.get_href(), as_DAVError(e)))<EOL><DEDENT><DEDENT>if is_move:<EOL><INDENT>reverseSrcList = srcList[:]<EOL>reverseSrcList.reverse()<EOL>_logger.debug("<STR_LIT>".format(ignoreDict))<EOL>for sRes in reverseSrcList:<EOL><INDENT>if not sRes.is_collection:<EOL><INDENT>continue<EOL><DEDENT>childError = False<EOL>for ignorePath in ignoreDict.keys():<EOL><INDENT>if util.is_equal_or_child_uri(sRes.path, ignorePath):<EOL><INDENT>childError = True<EOL>break<EOL><DEDENT><DEDENT>if childError:<EOL><INDENT>_logger.debug(<EOL>"<STR_LIT>".format(<EOL>sRes.path<EOL>)<EOL>)<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>_logger.debug("<STR_LIT>".format(sRes))<EOL>sRes.delete()<EOL><DEDENT>except Exception as e:<EOL><INDENT>error_list.append((srcRes.get_href(), as_DAVError(e)))<EOL><DEDENT><DEDENT>_logger.debug("<STR_LIT>".format(error_list))<EOL><DEDENT>return self._send_response(<EOL>environ, start_response, srcRes, success_code, error_list<EOL>)<EOL>
@see: http://www.webdav.org/specs/rfc4918.html#METHOD_COPY
@see: http://www.webdav.org/specs/rfc4918.html#METHOD_MOVE