Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r70953:b78e00087934 Date: 2014-04-24 17:37 -0700 http://bitbucket.org/pypy/pypy/changeset/b78e00087934/
Log: fix usage of bufferstr_w in _winreg diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py --- a/pypy/module/_winreg/interp_winreg.py +++ b/pypy/module/_winreg/interp_winreg.py @@ -2,7 +2,7 @@ from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty -from pypy.interpreter.error import OperationError, wrap_windowserror +from pypy.interpreter.error import OperationError, wrap_windowserror, oefmt from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib import rwinreg, rwin32 from rpython.rlib.rarithmetic import r_uint, intmask @@ -327,7 +327,14 @@ buf = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw') buf[0] = '\0' else: - value = space.bufferstr_w(w_value) + try: + value = w_value.readbuf_w(space) + except TypeError: + raise oefmt(space.w_TypeError, + "Objects of type '%T' can not be used as binary " + "registry values", w_value) + else: + value = value.as_str() buflen = len(value) buf = rffi.str2charp(value) diff --git a/pypy/module/_winreg/test/test_winreg.py b/pypy/module/_winreg/test/test_winreg.py --- a/pypy/module/_winreg/test/test_winreg.py +++ b/pypy/module/_winreg/test/test_winreg.py @@ -137,11 +137,15 @@ assert 0, "Did not raise" def test_SetValueEx(self): - from _winreg import CreateKey, SetValueEx + from _winreg import CreateKey, SetValueEx, REG_BINARY key = CreateKey(self.root_key, self.test_key_name) sub_key = CreateKey(key, "sub_key") for name, value, type in self.test_data: SetValueEx(sub_key, name, 0, type, value) + exc = raises(TypeError, SetValueEx, sub_key, 'test_name', None, + REG_BINARY, memoryview('abc')) + assert str(exc.value) == ("Objects of type 'memoryview' can not " + "be used as binary registry values") def test_readValues(self): from _winreg import OpenKey, EnumValue, QueryValueEx, EnumKey _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit