diff options
author | Aarni Koskela <akx@iki.fi> | 2014-01-21 00:13:22 +0200 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2014-01-21 13:31:43 -0800 |
commit | b0c689d7c86d9c3c421f4289c038c11464002dbb (patch) | |
tree | c64209e743c7c82b8131db1626f83a05e2242200 | |
parent | d32d457775224c7afa12456810603def13bdc6a6 (diff) |
Support Py2.5 to Py3.4 for thread identity (thanks @lndbrg)
-rw-r--r-- | paramiko/win_pageant.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/paramiko/win_pageant.py b/paramiko/win_pageant.py index a7aea87b..1c0bc98c 100644 --- a/paramiko/win_pageant.py +++ b/paramiko/win_pageant.py @@ -28,6 +28,7 @@ import ctypes.wintypes import platform import struct import thread +import threading from . import _winapi @@ -38,6 +39,13 @@ _AGENT_MAX_MSGLEN = 8192 win32con_WM_COPYDATA = 74 +def get_thread_ident(): + try: # thread.get_ident() exists from Py2.5 to Py2.7. + return thread.get_ident() + except AttributeError: # threading.current_thread().ident exists from Py2.6 up to Py3.4. + return threading.current_thread().ident + + def _get_pageant_window_object(): return ctypes.windll.user32.FindWindowA('Pageant', 'Pageant') @@ -51,7 +59,10 @@ def can_talk_to_agent(): """ return bool(_get_pageant_window_object()) + ULONG_PTR = ctypes.c_uint64 if platform.architecture()[0] == '64bit' else ctypes.c_uint32 + + class COPYDATASTRUCT(ctypes.Structure): """ ctypes implementation of @@ -61,7 +72,8 @@ class COPYDATASTRUCT(ctypes.Structure): ('num_data', ULONG_PTR), ('data_size', ctypes.wintypes.DWORD), ('data_loc', ctypes.c_void_p), - ] + ] + def _query_pageant(msg): """ @@ -74,7 +86,7 @@ def _query_pageant(msg): return None # create a name for the mmap - map_name = 'PageantRequest%08x' % thread.get_ident() + map_name = 'PageantRequest%08x' % get_thread_ident() pymap = _winapi.MemoryMap(map_name, _AGENT_MAX_MSGLEN, _winapi.get_security_attributes_for_user(), @@ -98,7 +110,8 @@ def _query_pageant(msg): return datalen + pymap.read(retlen) return None -class PageantConnection (object): + +class PageantConnection(object): """ Mock "connection" to an agent which roughly approximates the behavior of a unix local-domain socket (as used by Agent). Requests are sent to the |