【问题标题】:What is the format of files in `pip-cache/pip/html`?`pip-cache/pip/html` 中的文件格式是什么?
【发布时间】:2020-06-18 11:20:23
【问题描述】:

我正在尝试从pip 缓存中恢复一些难以获取的依赖项。存储在上述目录中的所有文件都以字节cc=2 开头。我希望那里有类似.tar.gz 的文件,但不是。

我曾短暂尝试搜索pip 源代码,但大部分都找到了处理Wheel 档案的代码(本质上是.zip 文件)。我找不到处理/http/ 子文件夹的代码。不确定我查看的是源代码树的错误部分,还是错误的 pip 版本。

【问题讨论】:

标签: python linux pip


【解决方案1】:

pip 使用cachecontrol 加载/存储其缓存文件。 The filename is the sha224 of the URL being requested.

加载文件的代码可见at Gihub

对于cc=2的特殊情况,cc=2,后面的数据(注意逗号)可以被解码

cached = json.loads(zlib.decompress(data).decode("utf8"))

# We need to decode the items that we've base64 encoded
cached["response"]["body"] = _b64_decode_bytes(cached["response"]["body"])
cached["response"]["headers"] = dict(
    (_b64_decode_str(k), _b64_decode_str(v))
    for k, v in cached["response"]["headers"].items()
)
cached["response"]["reason"] = _b64_decode_str(cached["response"]["reason"])
cached["vary"] = dict(
    (_b64_decode_str(k), _b64_decode_str(v) if v is not None else v)
    for k, v in cached["vary"].items()
)

【讨论】:

  • 仅供我以后参考:将所有数据解包到unpacked:find var/pip-cache/pip/http -type f | parallel "<{} tail -c+6 | pigz -z -d | jq -r .response.body | base64 -d > unpacked/{/}"
猜你喜欢
  • 2021-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-16
  • 2017-07-25
  • 2015-02-26
  • 1970-01-01
  • 2019-11-30
相关资源
最近更新 更多