小编use*_*785的帖子

pygit2 blob历史

我正在尝试git log filename使用pygit2在git裸存储库中进行相当的操作.该文档仅解释了如何执行git log此操作:

from pygit2 import GIT_SORT_TIME
for commit in repo.walk(oid, GIT_SORT_TIME):
    print(commit.hex)
Run Code Online (Sandbox Code Playgroud)

你有什么主意吗?

谢谢

编辑:

我现在有类似的东西,或多或少精确:

from pygit2 import GIT_SORT_TIME, Repository


repo = Repository('/path/to/repo')

def iter_commits(name):
    last_commit = None
    last_oid = None

    # loops through all the commits
    for commit in repo.walk(repo.head.oid, GIT_SORT_TIME):

        # checks if the file exists
        if name in commit.tree:
            # has it changed since last commit?
            # let's compare it's sha with the previous found sha
            oid = commit.tree[name].oid
            has_changed …
Run Code Online (Sandbox Code Playgroud)

python git history blob libgit2

7
推荐指数
1
解决办法
1188
查看次数

python-requests:获取响应内容的头部而不消耗所有内容

使用python-requests和python-magic,我想测试web资源的mime类型而不获取其所有内容(特别是如果此资源恰好是例如ogg文件或PDF文件).根据结果​​,我可能决定全部取出它.但是,在测试mime-type之后调用text方法只返回尚未消耗的内容.如何在不消耗响应内容的情况下测试mime类型?

以下是我目前的代码.

import requests
import magic


r = requests.get("http://www.december.com/html/demo/hello.html", prefetch=False)
mime = magic.from_buffer(r.iter_content(256).next(), mime=True)

if mime == "text/html":
    print(r.text)  # I'd like r.text to give me the entire response content
Run Code Online (Sandbox Code Playgroud)

谢谢!

python unicode http python-requests

4
推荐指数
2
解决办法
2784
查看次数

python标准lib相当于dateutil.parser.parse

我正在使用python dateutil解析datetimestamps,但希望避免额外的依赖.那么有没有办法与标准的python库做同等的事情:

dateutil.parser.parse("2012-12-12T12:00")
Run Code Online (Sandbox Code Playgroud)

非常感谢!

python datetime standard-library python-dateutil

3
推荐指数
1
解决办法
2331
查看次数