Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a8c360ee
Commit
a8c360ee
authored
Jul 17, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SF patch# 1755229 by Amaury Forgeot d'Arc: fix _winreg module and tests.
Untested.
parent
52b8976a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
34 deletions
+24
-34
Lib/test/test_winreg.py
Lib/test/test_winreg.py
+4
-11
PC/_winreg.c
PC/_winreg.c
+20
-23
No files found.
Lib/test/test_winreg.py
View file @
a8c360ee
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
from
_winreg
import
*
from
_winreg
import
*
import
os
,
sys
import
os
,
sys
from
test.test_support
import
verify
,
have_unicode
from
test.test_support
import
verify
test_key_name
=
"SOFTWARE
\
\
Python Registry Test Key - Delete Me"
test_key_name
=
"SOFTWARE
\
\
Python Registry Test Key - Delete Me"
...
@@ -13,17 +13,10 @@ test_data = [
...
@@ -13,17 +13,10 @@ test_data = [
(
"String Val"
,
"A string value"
,
REG_SZ
),
(
"String Val"
,
"A string value"
,
REG_SZ
),
(
"StringExpand"
,
"The path is %path%"
,
REG_EXPAND_SZ
),
(
"StringExpand"
,
"The path is %path%"
,
REG_EXPAND_SZ
),
(
"Multi-string"
,
[
"Lots"
,
"of"
,
"string"
,
"values"
],
REG_MULTI_SZ
),
(
"Multi-string"
,
[
"Lots"
,
"of"
,
"string"
,
"values"
],
REG_MULTI_SZ
),
(
"Raw Data"
,
(
"binary"
+
chr
(
0
)
+
"data"
),
REG_BINARY
),
(
"Raw Data"
,
bytes
(
"binary"
+
chr
(
0
)
+
"data"
),
REG_BINARY
),
(
"Big String"
,
"x"
*
(
2
**
14
-
1
),
REG_SZ
),
(
"Big String"
,
"x"
*
(
2
**
14
-
1
),
REG_SZ
),
(
"Big Binary"
,
"x"
*
(
2
**
14
),
REG_BINARY
),
(
"Big Binary"
,
b"x"
*
(
2
**
14
),
REG_BINARY
),
]
]
if
have_unicode
:
test_data
+=
[
(
str
(
"Unicode Val"
),
str
(
"A Unicode value"
),
REG_SZ
,),
(
"UnicodeExpand"
,
str
(
"The path is %path%"
),
REG_EXPAND_SZ
),
(
"Multi-unicode"
,
[
str
(
"Lots"
),
str
(
"of"
),
str
(
"unicode"
),
str
(
"values"
)],
REG_MULTI_SZ
),
(
"Multi-mixed"
,
[
str
(
"Unicode"
),
str
(
"and"
),
"string"
,
"values"
],
REG_MULTI_SZ
),
]
def
WriteTestData
(
root_key
):
def
WriteTestData
(
root_key
):
# Set the default value for this key.
# Set the default value for this key.
...
@@ -65,7 +58,7 @@ def WriteTestData(root_key):
...
@@ -65,7 +58,7 @@ def WriteTestData(root_key):
def
ReadTestData
(
root_key
):
def
ReadTestData
(
root_key
):
# Check we can get default value for this key.
# Check we can get default value for this key.
val
=
QueryValue
(
root_key
,
test_key_name
)
val
=
QueryValue
(
root_key
,
test_key_name
)
verify
(
val
==
"Default value"
,
"Registry didn't give back the correct value"
)
verify
(
type
(
val
)
is
str
and
val
==
"Default value"
,
"Registry didn't give back the correct value"
)
key
=
OpenKey
(
root_key
,
test_key_name
)
key
=
OpenKey
(
root_key
,
test_key_name
)
# Read the sub-keys
# Read the sub-keys
...
...
PC/_winreg.c
View file @
a8c360ee
...
@@ -404,7 +404,7 @@ PyHKEY_strFunc(PyObject *ob)
...
@@ -404,7 +404,7 @@ PyHKEY_strFunc(PyObject *ob)
PyHKEYObject
*
pyhkey
=
(
PyHKEYObject
*
)
ob
;
PyHKEYObject
*
pyhkey
=
(
PyHKEYObject
*
)
ob
;
char
resBuf
[
160
];
char
resBuf
[
160
];
wsprintf
(
resBuf
,
"<PyHKEY:%p>"
,
pyhkey
->
hkey
);
wsprintf
(
resBuf
,
"<PyHKEY:%p>"
,
pyhkey
->
hkey
);
return
Py
String
_FromString
(
resBuf
);
return
Py
Unicode
_FromString
(
resBuf
);
}
}
static
int
static
int
...
@@ -444,6 +444,7 @@ static PyNumberMethods PyHKEY_NumberMethods =
...
@@ -444,6 +444,7 @@ static PyNumberMethods PyHKEY_NumberMethods =
PyHKEY_binaryFailureFunc
,
/* nb_and */
PyHKEY_binaryFailureFunc
,
/* nb_and */
PyHKEY_binaryFailureFunc
,
/* nb_xor */
PyHKEY_binaryFailureFunc
,
/* nb_xor */
PyHKEY_binaryFailureFunc
,
/* nb_or */
PyHKEY_binaryFailureFunc
,
/* nb_or */
NULL
,
/* nb_coerce */
PyHKEY_intFunc
,
/* nb_int */
PyHKEY_intFunc
,
/* nb_int */
PyHKEY_unaryFailureFunc
,
/* nb_long */
PyHKEY_unaryFailureFunc
,
/* nb_long */
PyHKEY_unaryFailureFunc
,
/* nb_float */
PyHKEY_unaryFailureFunc
,
/* nb_float */
...
@@ -729,11 +730,10 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
...
@@ -729,11 +730,10 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
return
FALSE
;
return
FALSE
;
need_decref
=
1
;
need_decref
=
1
;
}
}
if
(
!
Py
String
_Check
(
value
))
if
(
!
Py
Bytes
_Check
(
value
))
return
FALSE
;
return
FALSE
;
*
retDataSize
=
1
+
strlen
(
*
retDataSize
=
1
+
strlen
(
PyString_AS_STRING
(
PyBytes_AS_STRING
(
value
));
(
PyStringObject
*
)
value
));
}
}
*
retDataBuf
=
(
BYTE
*
)
PyMem_NEW
(
DWORD
,
*
retDataSize
);
*
retDataBuf
=
(
BYTE
*
)
PyMem_NEW
(
DWORD
,
*
retDataSize
);
if
(
*
retDataBuf
==
NULL
){
if
(
*
retDataBuf
==
NULL
){
...
@@ -744,8 +744,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
...
@@ -744,8 +744,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
strcpy
((
char
*
)
*
retDataBuf
,
""
);
strcpy
((
char
*
)
*
retDataBuf
,
""
);
else
else
strcpy
((
char
*
)
*
retDataBuf
,
strcpy
((
char
*
)
*
retDataBuf
,
PyString_AS_STRING
(
PyBytes_AS_STRING
(
value
));
(
PyStringObject
*
)
value
));
if
(
need_decref
)
if
(
need_decref
)
Py_DECREF
(
value
);
Py_DECREF
(
value
);
break
;
break
;
...
@@ -770,7 +769,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
...
@@ -770,7 +769,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
PyObject
*
t
;
PyObject
*
t
;
t
=
PyList_GET_ITEM
(
t
=
PyList_GET_ITEM
(
(
PyListObject
*
)
value
,
j
);
(
PyListObject
*
)
value
,
j
);
if
(
Py
String
_Check
(
t
))
{
if
(
Py
Bytes
_Check
(
t
))
{
obs
[
j
]
=
t
;
obs
[
j
]
=
t
;
Py_INCREF
(
t
);
Py_INCREF
(
t
);
}
else
if
(
PyUnicode_Check
(
t
))
{
}
else
if
(
PyUnicode_Check
(
t
))
{
...
@@ -783,8 +782,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
...
@@ -783,8 +782,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
}
else
}
else
goto
reg_multi_fail
;
goto
reg_multi_fail
;
size
+=
1
+
strlen
(
size
+=
1
+
strlen
(
PyString_AS_STRING
(
PyBytes_AS_STRING
(
obs
[
j
]));
(
PyStringObject
*
)
obs
[
j
]));
}
}
*
retDataSize
=
size
+
1
;
*
retDataSize
=
size
+
1
;
...
@@ -800,12 +798,9 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
...
@@ -800,12 +798,9 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
{
{
PyObject
*
t
;
PyObject
*
t
;
t
=
obs
[
j
];
t
=
obs
[
j
];
strcpy
(
P
,
strcpy
(
P
,
PyBytes_AS_STRING
(
t
));
PyString_AS_STRING
(
(
PyStringObject
*
)
t
));
P
+=
1
+
strlen
(
P
+=
1
+
strlen
(
PyString_AS_STRING
(
PyBytes_AS_STRING
(
t
));
(
PyStringObject
*
)
t
));
Py_DECREF
(
obs
[
j
]);
Py_DECREF
(
obs
[
j
]);
}
}
/* And doubly-terminate the list... */
/* And doubly-terminate the list... */
...
@@ -922,7 +917,7 @@ Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
...
@@ -922,7 +917,7 @@ Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
obData
=
Py_None
;
obData
=
Py_None
;
}
}
else
else
obData
=
Py_BuildValue
(
"
s
#"
,
obData
=
Py_BuildValue
(
"
y
#"
,
(
char
*
)
retDataBuf
,
(
char
*
)
retDataBuf
,
retDataSize
);
retDataSize
);
break
;
break
;
...
@@ -1047,7 +1042,7 @@ PyEnumKey(PyObject *self, PyObject *args)
...
@@ -1047,7 +1042,7 @@ PyEnumKey(PyObject *self, PyObject *args)
if
(
rc
!=
ERROR_SUCCESS
)
if
(
rc
!=
ERROR_SUCCESS
)
return
PyErr_SetFromWindowsErrWithFunction
(
rc
,
"RegEnumKeyEx"
);
return
PyErr_SetFromWindowsErrWithFunction
(
rc
,
"RegEnumKeyEx"
);
retStr
=
Py
String
_FromStringAndSize
(
tmpbuf
,
len
);
retStr
=
Py
Unicode
_FromStringAndSize
(
tmpbuf
,
len
);
return
retStr
;
/* can be NULL */
return
retStr
;
/* can be NULL */
}
}
...
@@ -1109,7 +1104,7 @@ PyEnumValue(PyObject *self, PyObject *args)
...
@@ -1109,7 +1104,7 @@ PyEnumValue(PyObject *self, PyObject *args)
retVal
=
NULL
;
retVal
=
NULL
;
goto
fail
;
goto
fail
;
}
}
retVal
=
Py_BuildValue
(
"
s
Oi"
,
retValueBuf
,
obData
,
typ
);
retVal
=
Py_BuildValue
(
"
U
Oi"
,
retValueBuf
,
obData
,
typ
);
Py_DECREF
(
obData
);
Py_DECREF
(
obData
);
fail:
fail:
PyMem_Free
(
retValueBuf
);
PyMem_Free
(
retValueBuf
);
...
@@ -1232,17 +1227,19 @@ PyQueryValue(PyObject *self, PyObject *args)
...
@@ -1232,17 +1227,19 @@ PyQueryValue(PyObject *self, PyObject *args)
!=
ERROR_SUCCESS
)
!=
ERROR_SUCCESS
)
return
PyErr_SetFromWindowsErrWithFunction
(
rc
,
return
PyErr_SetFromWindowsErrWithFunction
(
rc
,
"RegQueryValue"
);
"RegQueryValue"
);
ret
Str
=
PyString_FromStringAndSize
(
NULL
,
bufSize
);
ret
Buf
=
(
char
*
)
PyMem_Malloc
(
bufSize
);
if
(
ret
Str
==
NULL
)
if
(
ret
Buf
==
NULL
)
return
NULL
;
return
PyErr_NoMemory
()
;
retBuf
=
PyString_AS_STRING
(
retStr
);
if
((
rc
=
RegQueryValue
(
hKey
,
subKey
,
retBuf
,
&
bufSize
))
if
((
rc
=
RegQueryValue
(
hKey
,
subKey
,
retBuf
,
&
bufSize
))
!=
ERROR_SUCCESS
)
{
!=
ERROR_SUCCESS
)
{
Py
_DECREF
(
retStr
);
Py
Mem_Free
(
retBuf
);
return
PyErr_SetFromWindowsErrWithFunction
(
rc
,
return
PyErr_SetFromWindowsErrWithFunction
(
rc
,
"RegQueryValue"
);
"RegQueryValue"
);
}
}
_PyString_Resize
(
&
retStr
,
strlen
(
retBuf
));
retStr
=
PyUnicode_DecodeMBCS
(
retBuf
,
strlen
(
retBuf
),
NULL
);
PyMem_Free
(
retBuf
);
return
retStr
;
return
retStr
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment