瀏覽代碼

Fix nested tags

E.g. <Owner> tag which has <ID> and <DisplayName>, e.g. https://appengage-video.s3.amazonaws.com/
master
JustAnotherArchivist 4 年之前
父節點
當前提交
3cc3a1ed38
共有 1 個檔案被更改,包括 11 行新增3 行删除
  1. +11
    -3
      s3-bucket-list

+ 11
- 3
s3-bucket-list 查看文件

@@ -89,10 +89,18 @@ while True:
assert len(tags) % 2 == 0
assert tags[-1] == b''
assert tags[-2] == b'</Contents'
assert all(a[1:] == b[b.rindex(b'</') + 2:] for a, b in zip(tags[:-2:2], tags[1:-2:2]))
openTags = [] # Current open tag hierarchy
fields = {}
for a, b in zip(tags[:-2:2], tags[1:-2:2]):
fields[a[1:].decode('utf-8')] = html.unescape(b[:b.rindex(b'</')].decode('utf-8'))
for tag in tags[:-2]:
if tag.startswith(b'<'):
openTags.append(tag[1:])
continue
assert openTags
if tag.endswith(b'</' + openTags[-1]):
fields[b'>'.join(openTags).decode('utf-8')] = html.unescape(tag[:-(len(openTags[-1]) + 2)].decode('utf-8'))
openTags.pop()
continue
assert False

size = int(fields['Size']) if 'Size' in fields else None



Loading…
取消
儲存