更新文件: webdav_simulator/115.txt, webdav_simulator/sim.txt, webdav_simulator/get115list.py, webdav_simulator/run.sh, webdav_simulator/webdav_simulator.py

This commit is contained in:
ZJP Monitor
2025-05-10 11:57:09 +08:00
parent 0b30bdeee2
commit b44775e13c
5 changed files with 70219 additions and 7 deletions

View File

@ -12,12 +12,13 @@ import yaml
class Node:
"""虚拟文件系统节点"""
def __init__(self, name, is_dir=False):
def __init__(self, name, is_dir=False, size=0):
self.name = name
self.is_dir = is_dir
self.children = {}
self.content = b""
self.last_modified = datetime.now()
self.size = size
def parse_paths(text_lines):
"""解析完整路径配置文件"""
@ -27,6 +28,14 @@ def parse_paths(text_lines):
if not line:
continue
arr = line.split('\t')
line = arr[0]
size = 0
if len(arr)>1:
try:
size = int(arr[1])
except:
print("error line:"+line)
is_dir = line.endswith('/')
stripped = line.strip('/')
parts = stripped.split('/') if stripped else []
@ -45,7 +54,7 @@ def parse_paths(text_lines):
if not parts:
# 根目录文件(如 /file.txt
if stripped not in current.children:
current.children[stripped] = Node(stripped, is_dir=False)
current.children[stripped] = Node(stripped, is_dir=False, size=size)
continue
dirs, file_name = parts[:-1], parts[-1]
@ -56,7 +65,7 @@ def parse_paths(text_lines):
current.children[part] = Node(part, is_dir=True)
current = current.children[part]
if file_name not in current.children:
current.children[file_name] = Node(file_name, is_dir=False)
current.children[file_name] = Node(file_name, is_dir=False, size=size)
return root
class VirtualFSProvider(DAVProvider):
@ -112,7 +121,14 @@ class VirtualResource(_DAVResource):
def support_etag(self):
return True if self.node.is_dir else False
def get_content(self):
return BytesIO("VIRTUAL".encode())
content = "VIRTUAL".encode('utf-8')
buf = BytesIO(content)
buf.seek(0)
return buf
def get_content_type(self):
return "application/octet-stream"
def get_content_length(self):
return self.node.size
def main():
parser = argparse.ArgumentParser(description='WebDAV路径模拟服务器')