我一直努力让2.5模块移植到3.0,主要是为自己的教育,当我已经得到了坚持。类“生成器”具有其init:

def __init__(self, **options):
    self._verifyOptions(options)
    self._options = options
    self._initDigest()
    self._initBuildNames()
    self._methods = []

但在发生错误:

def _initDigest(self):
    import os, sys, hashlib
    digester = hashlib.md5()
    digester.update(self._options.get('code'))
    self._digest = digester.hexdigest()

,其具有作为其回溯:

Traceback (most recent call last):
  File "<pyshell#5>", line 5, in <module>
    """, language="Cee")
  File "C:\Python30\lib\site-packages\PyInline\__init__.py", line 31, in build
    b = m.Builder(**args)
  File "C:\Python30\lib\site-packages\PyInline\Cee.py", line 17, in __init__
    self._initDigest()
  File "C:\Python30\lib\site-packages\PyInline\Cee.py", line 27, in _initDigest
    digester.update(self._options.get('code'))
TypeError: object supporting the buffer API required

我已经通过2to3的运行它,但它不就行了回升。据我所知,在更新功能时期待的参数是在字节/缓存的形式,但我已经尝试过几种不同的方法将其转换并没有成功。

和往常一样,任何帮助将不胜感激。 :)

有帮助吗?

解决方案

我猜测,这行:

digester.update(self._options.get('code'))

应成为:

digester.update(self._options.get('code').encode("utf-8"))

在实际所需的编码可以是你的情况不同,但UTF-8将在所有情况下工作。

其他提示

我还没有尝试3.0尚未。但现在有个字节和字符串的序列之间更大的区别。而前者,后者保持Unicode代码点不抱Unicode的,但只有encoded unicode字符串。散列上的字节序列进行操作。所以,你必须先进行编码的(Unicode)的字符串bevore他们喂养的哈希值。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top