diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2012-11-23 14:03:20 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2012-11-23 14:03:20 -0500 |
commit | 0698254b188736e47dc804e16595e96e8e37bd21 (patch) | |
tree | b8b4ad8cf35408af905229fd1443452dbfc3b645 | |
parent | 64d6734086fbf5db898495c69959921715617617 (diff) |
Use MemoryMap from jaraco.windows in lieu of mmap.mmap.
-rw-r--r-- | paramiko/win_pageant.py | 18 | ||||
-rw-r--r-- | setup.py | 5 |
2 files changed, 13 insertions, 10 deletions
diff --git a/paramiko/win_pageant.py b/paramiko/win_pageant.py index 17d7f5b3..0410a995 100644 --- a/paramiko/win_pageant.py +++ b/paramiko/win_pageant.py @@ -23,11 +23,12 @@ Functions for communicating with Pageant, the basic windows ssh agent program. import struct import threading -import mmap import array import platform import ctypes.wintypes +import jaraco.windows.mmap as mmap + _AGENT_COPYDATA_ID = 0x804e50ba _AGENT_MAX_MSGLEN = 8192 # Note: The WM_COPYDATA value is pulled from win32con, as a workaround @@ -61,19 +62,21 @@ class COPYDATASTRUCT(ctypes.Structure): ] def _query_pageant(msg): + """ + Communication with the Pageant process is done through a shared + memory-mapped file. + """ hwnd = _get_pageant_window_object() if not hwnd: # Raise a failure to connect exception, pageant isn't running anymore! return None + # create a name for the mmap map_name = 'PageantRequest%08x' % threading.current_thread().ident - # Create the shared memory from which Pageant will read the request - pymap = mmap.mmap(-1, _AGENT_MAX_MSGLEN, tagname=map_name, - access=mmap.ACCESS_WRITE) - try: + pymap = mmap.MemoryMap(map_name, _AGENT_MAX_MSGLEN) + with pymap: pymap.write(msg) - # Create an array buffer containing the mapped filename char_buffer = array.array("c", map_name + '\0') char_buffer_address, char_buffer_size = char_buffer.buffer_info() @@ -90,9 +93,6 @@ def _query_pageant(msg): retlen = struct.unpack('>I', datalen)[0] return datalen + pymap.read(retlen) return None - finally: - pymap.close() - class PageantConnection (object): """ @@ -40,7 +40,10 @@ import sys try: from setuptools import setup kw = { - 'install_requires': 'pycrypto >= 2.1, != 2.4', + 'install_requires': [ + 'pycrypto >= 2.1, != 2.4', + 'jaraco.windows >= 2.10, <3.0dev', + ], } except ImportError: from distutils.core import setup |