Skip to content

Commit dec3ef1

Browse files
committed
minor cleanup
1 parent 2fc657a commit dec3ef1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

win32ctypes/core/ctypes/_authentication.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
from ctypes import POINTER, Structure, c_char_p, cast
1010
from ctypes.wintypes import (
1111
BOOL, DWORD, FILETIME, LPCWSTR, LPWSTR)
12+
from weakref import WeakKeyDictionary
1213

1314
from ._common import LPBYTE, _PyBytes_FromStringAndSize
1415
from ._util import function_factory, check_false_factory, dlls
1516

17+
# values to ref and make sure that they will not go away
18+
_keep_alive = WeakKeyDictionary()
19+
1620

1721
class CREDENTIAL_ATTRIBUTE(Structure):
1822
_fields_ = [
@@ -59,14 +63,14 @@ class CREDENTIAL(Structure):
5963

6064
@classmethod
6165
def fromdict(cls, credential):
62-
c_credentials = cls()
63-
c_pcredentials = PCREDENTIAL(c_credentials)
64-
ctypes.memset(c_pcredentials, 0, ctypes.sizeof(c_credentials))
66+
c_credential = cls()
67+
c_pcredential = PCREDENTIAL(c_credential)
68+
ctypes.memset(c_pcredential, 0, ctypes.sizeof(c_credential))
6569
for key in credential:
6670
if key == 'CredentialBlob':
6771
blob_data, blob_size = _make_blob(credential['CredentialBlob'])
68-
c_credentials.CredentialBlob = blob_data
69-
c_credentials.CredentialBlobSize = blob_size
72+
c_credential.CredentialBlob = blob_data
73+
c_credential.CredentialBlobSize = blob_size
7074
elif key == 'Attributes':
7175
attributes = credential.get('Attributes', '')
7276
count = len(attributes)
@@ -76,14 +80,13 @@ def fromdict(cls, credential):
7680
raise ValueError('Multiple attributes are not supported')
7781
c_attribute = CREDENTIAL_ATTRIBUTE.fromdict(attributes[0])
7882
c_pattribute = PCREDENTIAL_ATTRIBUTE(c_attribute)
79-
c_credentials.Attributes = c_pattribute
80-
c_credentials.AttributeCount = count
83+
c_credential.Attributes = c_pattribute
84+
c_credential.AttributeCount = count
8185
else:
8286
setattr(c_credentials, key, credential[key])
83-
return c_credentials
87+
return c_credential
8488

8589

86-
_data = []
8790
PCREDENTIAL = POINTER(CREDENTIAL)
8891
PPCREDENTIAL = POINTER(PCREDENTIAL)
8992
PPPCREDENTIAL = POINTER(PPCREDENTIAL)
@@ -103,7 +106,6 @@ def credential_attribute2dict(c_attribute):
103106

104107
def credential2dict(c_credential):
105108
credential = {}
106-
107109
for key, type_ in CREDENTIAL._fields_:
108110
if key == 'CredentialBlob':
109111
blob = _PyBytes_FromStringAndSize(
@@ -124,7 +126,7 @@ def credential2dict(c_credential):
124126

125127

126128
def _make_blob(data):
127-
''' Convert a string to LPBYTE compatible blob dict values
129+
''' Convert a string to LPBYTE compatible blob value
128130
129131
'''
130132
blob_data = ctypes.create_unicode_buffer(data)

0 commit comments

Comments
 (0)