diff --git a/.appveyor.yml b/.appveyor.yml index a9506909..20f3b5c8 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,12 +1,13 @@ +max_jobs: 5 +build: + parallel: true + verbosity: minimal +skip_branch_with_pr: true environment: global: - # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the - # /E:ON and /V:ON options are not enabled in the batch script intepreter - # See: http://stackoverflow.com/a/13751649/163740 - CMD_IN_ENV: "cmd /E:ON /V:ON /C %APPVEYOR_BUILD_FOLDER%\\ci\\appveyor\\run_with_env.cmd" PYTHONUNBUFFERED: 1 EMBEDDED_LIB: 1 - OPENSSL_VER: 1.1.0h + SYSTEM_LIBSSH2: 1 PYPI_USER: secure: 2m0jy6JD/R9RExIosOT6YA== PYPI_PASS: @@ -17,21 +18,18 @@ environment: PYTHON_ARCH: "64" MSVC: "Visual Studio 14 Win64" ARCH: x64_86 - SYSTEM_LIBSSH2: 1 - PYTHON: "C:\\Python37-x64" PYTHON_VERSION: "3.7" PYTHON_ARCH: "64" MSVC: "Visual Studio 14 Win64" ARCH: x64_86 - SYSTEM_LIBSSH2: 1 - PYTHON: "C:\\Python38-x64" PYTHON_VERSION: "3.8" PYTHON_ARCH: "64" MSVC: "Visual Studio 14 Win64" ARCH: x64_86 - SYSTEM_LIBSSH2: 1 install: # If there is a newer build queued for the same PR, cancel this one. @@ -43,8 +41,12 @@ install: https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` throw "There are newer queued builds for this pull request, failing early." } - - ECHO "Installed SDKs:" - - ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\"" + - set OPENSSL_DIR="C:\OpenSSL-v11-Win%PYTHON_ARCH%" + - set VCLIBDIR=%WINDIR%\System32 + - cp %VCLIBDIR%/vcruntime*.dll ssh2/ + - cp %VCLIBDIR%/msvcp*.dll ssh2/ + - cp %VCLIBDIR%/msvcr*.dll ssh2/ + - cp %OPENSSL_DIR%/bin/*.dll ssh2/ # Prepend newly installed Python to the PATH of this build (this cannot be # done from inside the powershell script as it would require to restart @@ -55,17 +57,7 @@ install: - "python --version" - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" - # Upgrade to the latest version of pip to avoid it displaying warnings - # about it being out of date. - # - "pip install --disable-pip-version-check --user --upgrade pip" - - # Install the build dependencies of the project. If some dependencies contain - # compiled extensions and are not provided as pre-built wheel packages, - # pip will build them from source using the MSVC compiler matching the - # target Python version and architecture - - "%CMD_IN_ENV% pip install -r requirements_dev.txt" - - "%CMD_IN_ENV% pip install -U wheel setuptools twine" - - git submodule update --init --recursive + - pip install -U wheel setuptools twine cython # .c files need to be generated on Windows to handle platform # specific code. @@ -74,17 +66,17 @@ install: - python ci/appveyor/fix_version.py . - mv -f .git .git.bak - 7z x ci\appveyor\zlib1211.zip - - 7z x ci\appveyor\openssl-%OPENSSL_VER%-x%PYTHON_ARCH%-VC2017.zip - - cp openssl-%OPENSSL_VER%-x%PYTHON_ARCH%-VC2017\libssl-1_1-x%PYTHON_ARCH%.dll ssh2\ || cp openssl-%OPENSSL_VER%-x%PYTHON_ARCH%-VC2017\libssl-1_1.dll ssh2\ - - cp openssl-%OPENSSL_VER%-x%PYTHON_ARCH%-VC2017\libcrypto-1_1-x%PYTHON_ARCH%.dll ssh2\ || cp openssl-%OPENSSL_VER%-x%PYTHON_ARCH%-VC2017\libcrypto-1_1.dll ssh2\ - ps: ls ssh2 + build_script: - - "%CMD_IN_ENV% ci\\appveyor\\build_zlib.bat" - - "%CMD_IN_ENV% ci\\appveyor\\build_ssh2.bat" + - ci\\appveyor\\build_zlib.bat + - ci\\appveyor\\build_ssh2.bat - rm -f ssh2/*.c - - "%CMD_IN_ENV% python setup.py build_ext -I libssh2/include" - - "%CMD_IN_ENV% python setup.py build" - - "%CMD_IN_ENV% python setup.py install" + - python -V + - python setup.py build_ext -I libssh2/include + - python setup.py build + - python setup.py install + - ps: ls ssh2 test_script: - cd dist @@ -93,7 +85,7 @@ test_script: after_test: # If tests are successful, create binary packages for the project. - - "%CMD_IN_ENV% python setup.py bdist_wheel " + - python setup.py bdist_wheel - mv dist/* . artifacts: diff --git a/.travis.yml b/.travis.yml index 224b4480..77ba7240 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,22 +7,11 @@ cache: - "$HOME/.git/lfs" notifications: email: false -sudo: required -dist: xenial -services: - - docker python: - 2.7 - 3.6 - 3.7 - 3.8 -addons: - apt: - packages: - - openssh-server - - rpm - - dpkg - - cmake install: - pip install flake8 jinja2 sphinx sphinx_rtd_theme - python setup.py build_ext --inplace @@ -39,31 +28,39 @@ script: - cd doc - make html - cd .. +sudo: required +dist: xenial +services: + - docker +addons: + apt: + packages: + - openssh-server + - rpm + - dpkg + - cmake jobs: include: + - stage: test + if: type = push OR \ + (type = pull_request AND fork = true) + - &osx-wheels stage: build packages + if: tag IS present os: osx osx_image: xcode11.6 env: - - PYENV: 3.6.11 - SYSTEM_LIBSSH2: 1 - before_cache: - - brew cleanup before_install: - - brew update - - brew install ccache - - brew outdated openssl || travis_wait brew upgrade openssl || echo "y" - - sudo -H pip install twine + - brew install libssh2 + - pip3 install twine - which twine - - sudo ci/install-ssh2.sh - - cp /usr/local/lib/libssh2* . - - mkdir -p wheels install: skip script: - - travis_wait ./ci/travis/pyenv-wheel.sh + - ./ci/osx-wheel.sh after_success: - if [[ ! -z "$TRAVIS_TAG" ]]; then twine upload --skip-existing -u $PYPI_U -p $PYPI_P wheels/*.whl; @@ -73,50 +70,9 @@ jobs: - <<: *osx-wheels osx_image: xcode11.3 - env: - - PYENV: 3.6.11 - - SYSTEM_LIBSSH2: 1 - install: skip - script: - - travis_wait ./ci/travis/pyenv-wheel.sh - - - <<: *osx-wheels - osx_image: xcode11.6 - env: - - PYENV: 3.7.8 - - SYSTEM_LIBSSH2: 1 - install: skip - script: - - travis_wait ./ci/travis/pyenv-wheel.sh - - - <<: *osx-wheels - osx_image: xcode11.3 - env: - - PYENV: 3.7.8 - - SYSTEM_LIBSSH2: 1 - install: skip - script: - - travis_wait ./ci/travis/pyenv-wheel.sh - - - <<: *osx-wheels - osx_image: xcode11.3 - env: - - PYENV: 3.8.5 - - SYSTEM_LIBSSH2: 1 - install: skip - script: - - travis_wait ./ci/travis/pyenv-wheel.sh - - - <<: *osx-wheels - osx_image: xcode11.6 - env: - - PYENV: 3.8.5 - - SYSTEM_LIBSSH2: 1 - install: skip - script: - - travis_wait ./ci/travis/pyenv-wheel.sh - stage: build packages + if: tag IS present os: linux python: 3.6 env: diff --git a/ci/appveyor/anaconda_upload.py b/ci/appveyor/anaconda_upload.py deleted file mode 100644 index 82060cc4..00000000 --- a/ci/appveyor/anaconda_upload.py +++ /dev/null @@ -1,13 +0,0 @@ -import sys -import os -from glob import glob -import subprocess -import traceback - - -cmd = ['anaconda', '-t', os.environ['ANACONDA_TOKEN'], 'upload'] -cmd.extend(glob('*.tar.bz2')) -try: - subprocess.check_call(cmd) -except subprocess.CalledProcessError: - sys.exit(1) diff --git a/ci/appveyor/build_ssh2.bat b/ci/appveyor/build_ssh2.bat index 6246f879..fdfbde04 100755 --- a/ci/appveyor/build_ssh2.bat +++ b/ci/appveyor/build_ssh2.bat @@ -1,55 +1,23 @@ mkdir src cd src -IF "%PYTHON_ARCH%" == "32" ( - set OPENSSL_DIR="C:\OpenSSL-v11-Win32" -) ELSE ( - set OPENSSL_DIR="C:\OpenSSL-v11-Win64" +ECHO "Building with platform %MSVC%" +cmake ..\libssh2 -G "NMake Makefiles" ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DCRYPTO_BACKEND=OpenSSL ^ + -G"%MSVC%" ^ + -DBUILD_SHARED_LIBS=OFF ^ + -DENABLE_ZLIB_COMPRESSION=ON ^ + -DENABLE_CRYPT_NONE=ON ^ + -DENABLE_MAC_NONE=ON ^ + -DZLIB_LIBRARY=C:/zlib/lib/zlib.lib ^ + -DZLIB_INCLUDE_DIR=C:/zlib/include ^ + -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% ) -ls %OPENSSL_DIR%\lib -ls %OPENSSL_DIR%\lib\VC -ls %OPENSSL_DIR%\lib\VC\static - -IF "%MSVC%" == "Visual Studio 9" ( - ECHO "Building without platform set" - cmake ..\libssh2 -G "NMake Makefiles" ^ - -DCMAKE_BUILD_TYPE=Release ^ - -DCRYPTO_BACKEND=OpenSSL ^ - -DBUILD_SHARED_LIBS=OFF ^ - -DENABLE_ZLIB_COMPRESSION=ON ^ - -DENABLE_CRYPT_NONE=ON ^ - -DENABLE_MAC_NONE=ON ^ - -DZLIB_LIBRARY=C:/zlib/lib/zlib.lib ^ - -DZLIB_INCLUDE_DIR=C:/zlib/include ^ - -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -REM -DOPENSSL_MSVC_STATIC_RT=TRUE -REM -DOPENSSL_USE_STATIC_LIBS=TRUE -) ELSE ( - ECHO "Building with platform %MSVC%" - cmake ..\libssh2 -G "NMake Makefiles" ^ - -DCMAKE_BUILD_TYPE=Release ^ - -DCRYPTO_BACKEND=OpenSSL ^ - -G"%MSVC%" ^ - -DBUILD_SHARED_LIBS=OFF ^ - -DENABLE_ZLIB_COMPRESSION=ON ^ - -DENABLE_CRYPT_NONE=ON ^ - -DENABLE_MAC_NONE=ON ^ - -DZLIB_LIBRARY=C:/zlib/lib/zlib.lib ^ - -DZLIB_INCLUDE_DIR=C:/zlib/include ^ - -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -REM -DOPENSSL_MSVC_STATIC_RT=TRUE -REM -DOPENSSL_USE_STATIC_LIBS=TRUE -) - - cp %OPENSSL_DIR%\lib\VC\libcrypto%PYTHON_ARCH%MD.lib %APPVEYOR_BUILD_FOLDER% cp %OPENSSL_DIR%\lib\VC\libssl%PYTHON_ARCH%MD.lib %APPVEYOR_BUILD_FOLDER% cmake --build . --config Release cd .. -ls -ls ssh2 -ls src/src cp src/src/libssh2.lib %PYTHON%/libs/ || cp src/src/Release/libssh2.lib %PYTHON%/libs/ -ls %PYTHON%/libs/ diff --git a/ci/appveyor/openssl-1.1.0h-x64-VC2017.zip b/ci/appveyor/openssl-1.1.0h-x64-VC2017.zip deleted file mode 100644 index 55570d66..00000000 --- a/ci/appveyor/openssl-1.1.0h-x64-VC2017.zip +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c3592481c530ec3a74cf9e3f436a629ad50eeb820173482782e7bfee0bebc69f -size 1806520 diff --git a/ci/appveyor/run_with_env.cmd b/ci/appveyor/run_with_env.cmd deleted file mode 100644 index 68379b1f..00000000 --- a/ci/appveyor/run_with_env.cmd +++ /dev/null @@ -1,71 +0,0 @@ -:: To build extensions for 64 bit Python 3.5 or later no special environment needs -:: to be configured for the Python extension code alone, however, all dependent -:: libraries also need to be compiled with the same SDK in order to be able to -:: link them together. -:: -:: This script sets SDK version and environment for all commands. -:: -:: To build extensions for 64 bit Python 3.4 or earlier, we need to configure environment -:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: -:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1) -:: -:: To build extensions for 64 bit Python 2, we need to configure environment -:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of: -:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0) -:: -:: 32 bit builds do not require specific environment configurations. -:: -:: Note: this script needs to be run with the /E:ON and /V:ON flags for the -:: cmd interpreter, at least for (SDK v7.0) -:: -:: More details at: -:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows -:: https://stackoverflow.com/a/13751649/163740 -:: -:: Original Author: Olivier Grisel -:: License: CC0 1.0 Universal: https://creativecommons.org/publicdomain/zero/1.0/ -:: This version based on updates for python 3.5 by Phil Elson at: -:: https://github.com/pelson/Obvious-CI/tree/master/scripts -:: Further updates to always correctly set SDK version and environment so -:: that compiled library dependencies use same SDK as Python extension. - -@ECHO OFF - -SET COMMAND_TO_RUN=%* -SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows - -SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%" -SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1% -IF %MAJOR_PYTHON_VERSION% == "2" ( - SET WINDOWS_SDK_VERSION="v7.0" - SET SET_SDK_64=Y -) ELSE IF %MAJOR_PYTHON_VERSION% == "3" ( - SET WINDOWS_SDK_VERSION="v7.1" - IF %MINOR_PYTHON_VERSION% LEQ 4 ( - SET SET_SDK_64=Y - ) ELSE ( - SET SET_SDK_64=N - ) -) ELSE ( - ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%" - EXIT 1 -) - -"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% - -IF "%PYTHON_ARCH%"=="64" ( - IF %SET_SDK_64% == Y ( - ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture - SET DISTUTILS_USE_SDK=1 - SET MSSdk=1 - ) - ECHO Setting MSVC %WINDOWS_SDK_VERSION% build environment for 64 bit architecture - "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release - ECHO Executing: %COMMAND_TO_RUN% - call %COMMAND_TO_RUN% || EXIT 1 -) ELSE ( - ECHO Setting MSVC %WINDOWS_SDK_VERSION% build environment for 32 bit architecture - "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x86 /release - ECHO Executing: %COMMAND_TO_RUN% - call %COMMAND_TO_RUN% || EXIT 1 -) diff --git a/ci/osx-wheel.sh b/ci/osx-wheel.sh new file mode 100755 index 00000000..6014eee8 --- /dev/null +++ b/ci/osx-wheel.sh @@ -0,0 +1,27 @@ +#!/bin/bash -xe + +pip3 install -U virtualenv +python3 -m virtualenv -p "$(which python3)" venv + +set +x +source venv/bin/activate +set -x + +python -V +pip3 install -U setuptools pip +pip3 install -U delocate wheel +SYSTEM_LIBSSH2=1 python3 setup.py bdist_wheel +ls -lhtr /usr/local/lib/ +delocate-listdeps dist/*.whl +delocate-wheel -v -w wheels dist/*.whl +delocate-listdeps wheels/*.whl + +ls -l wheels/*.whl +rm -f /usr/local/lib/libssh2* +pip3 install -v wheels/*.whl +pwd; mkdir -p temp; cd temp; pwd +python3 -c "from ssh2.session import Session; Session()" && echo "Import successfull" +cd ..; pwd +set +x +deactivate +set -x diff --git a/requirements_dev.txt b/requirements_dev.txt index 7383b387..8bf2de5c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -4,3 +4,4 @@ jinja2 sphinx sphinx_rtd_theme pytest +pytest-rerunfailures diff --git a/setup.py b/setup.py index c0a6af26..992b0426 100644 --- a/setup.py +++ b/setup.py @@ -90,6 +90,7 @@ if ON_WINDOWS: package_data['ssh2'].extend([ 'libcrypto*.dll', 'libssl*.dll', + 'msvc*.dll', 'vcruntime*.dll', ]) cmdclass = versioneer.get_cmdclass() @@ -123,9 +124,9 @@ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: System :: Shells', 'Topic :: System :: Networking', 'Topic :: Software Development :: Libraries', diff --git a/ssh2/agent.c b/ssh2/agent.c index ff0ad03a..b9ce5984 100644 --- a/ssh2/agent.c +++ b/ssh2/agent.c @@ -1258,6 +1258,7 @@ static PyObject *(*__pyx_f_4ssh2_5utils_to_bytes)(PyObject *); /*proto*/ static PyTypeObject *__pyx_ptype_4ssh2_5agent_Agent = 0; static int __pyx_f_4ssh2_5agent_auth_identity(char const *, LIBSSH2_AGENT *, struct libssh2_agent_publickey **, struct libssh2_agent_publickey *); /*proto*/ static void __pyx_f_4ssh2_5agent_clear_agent(LIBSSH2_AGENT *); /*proto*/ +static LIBSSH2_AGENT *__pyx_f_4ssh2_5agent_agent_init(LIBSSH2_SESSION *); /*proto*/ #define __Pyx_MODULE_NAME "ssh2.agent" extern int __pyx_module_is_main_ssh2__agent; int __pyx_module_is_main_ssh2__agent = 0; @@ -1331,8 +1332,10 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, PyObject *__pyx_v_username, struct __pyx_obj_4ssh2_4pkey_PublicKey *__pyx_v_pkey); /* proto */ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_4ssh2_5agent_5Agent_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_4ssh2_5agent_5Agent_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_14get_identity_path(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_16set_identity_path(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, PyObject *__pyx_v_path); /* proto */ +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_18__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_20__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_tp_new_4ssh2_5agent_Agent(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__2; @@ -2465,8 +2468,8 @@ static PyObject *__pyx_f_4ssh2_5agent_PyAgent(LIBSSH2_AGENT *__pyx_v_agent, stru * cdef class Agent: * * def __cinit__(self, Session session): # <<<<<<<<<<<<<< - * self._agent = NULL - * self._session = session + * cdef c_ssh2.LIBSSH2_AGENT *_agent = agent_init(session._session) + * self._agent = _agent */ /* Python wrapper */ @@ -2528,22 +2531,37 @@ static int __pyx_pw_4ssh2_5agent_5Agent_1__cinit__(PyObject *__pyx_v_self, PyObj } static int __pyx_pf_4ssh2_5agent_5Agent___cinit__(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, struct __pyx_obj_4ssh2_7session_Session *__pyx_v_session) { + LIBSSH2_AGENT *__pyx_v__agent; int __pyx_r; __Pyx_RefNannyDeclarations + LIBSSH2_AGENT *__pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); /* "ssh2/agent.pyx":102 * * def __cinit__(self, Session session): - * self._agent = NULL # <<<<<<<<<<<<<< + * cdef c_ssh2.LIBSSH2_AGENT *_agent = agent_init(session._session) # <<<<<<<<<<<<<< + * self._agent = _agent * self._session = session - * */ - __pyx_v_self->_agent = NULL; + __pyx_t_1 = __pyx_f_4ssh2_5agent_agent_init(__pyx_v_session->_session); if (unlikely(__pyx_t_1 == ((LIBSSH2_AGENT *)NULL))) __PYX_ERR(1, 102, __pyx_L1_error) + __pyx_v__agent = __pyx_t_1; /* "ssh2/agent.pyx":103 * def __cinit__(self, Session session): - * self._agent = NULL + * cdef c_ssh2.LIBSSH2_AGENT *_agent = agent_init(session._session) + * self._agent = _agent # <<<<<<<<<<<<<< + * self._session = session + * + */ + __pyx_v_self->_agent = __pyx_v__agent; + + /* "ssh2/agent.pyx":104 + * cdef c_ssh2.LIBSSH2_AGENT *_agent = agent_init(session._session) + * self._agent = _agent * self._session = session # <<<<<<<<<<<<<< * * def __dealloc__(self): @@ -2558,17 +2576,22 @@ static int __pyx_pf_4ssh2_5agent_5Agent___cinit__(struct __pyx_obj_4ssh2_5agent_ * cdef class Agent: * * def __cinit__(self, Session session): # <<<<<<<<<<<<<< - * self._agent = NULL - * self._session = session + * cdef c_ssh2.LIBSSH2_AGENT *_agent = agent_init(session._session) + * self._agent = _agent */ /* function exit code */ __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("ssh2.agent.Agent.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "ssh2/agent.pyx":105 +/* "ssh2/agent.pyx":106 * self._session = session * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2591,7 +2614,7 @@ static void __pyx_pf_4ssh2_5agent_5Agent_2__dealloc__(struct __pyx_obj_4ssh2_5ag __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "ssh2/agent.pyx":106 + /* "ssh2/agent.pyx":107 * * def __dealloc__(self): * with nogil: # <<<<<<<<<<<<<< @@ -2606,7 +2629,7 @@ static void __pyx_pf_4ssh2_5agent_5Agent_2__dealloc__(struct __pyx_obj_4ssh2_5ag #endif /*try:*/ { - /* "ssh2/agent.pyx":107 + /* "ssh2/agent.pyx":108 * def __dealloc__(self): * with nogil: * clear_agent(self._agent) # <<<<<<<<<<<<<< @@ -2616,7 +2639,7 @@ static void __pyx_pf_4ssh2_5agent_5Agent_2__dealloc__(struct __pyx_obj_4ssh2_5ag __pyx_f_4ssh2_5agent_clear_agent(__pyx_v_self->_agent); } - /* "ssh2/agent.pyx":106 + /* "ssh2/agent.pyx":107 * * def __dealloc__(self): * with nogil: # <<<<<<<<<<<<<< @@ -2635,7 +2658,7 @@ static void __pyx_pf_4ssh2_5agent_5Agent_2__dealloc__(struct __pyx_obj_4ssh2_5ag } } - /* "ssh2/agent.pyx":105 + /* "ssh2/agent.pyx":106 * self._session = session * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2647,7 +2670,7 @@ static void __pyx_pf_4ssh2_5agent_5Agent_2__dealloc__(struct __pyx_obj_4ssh2_5ag __Pyx_RefNannyFinishContext(); } -/* "ssh2/agent.pyx":109 +/* "ssh2/agent.pyx":110 * clear_agent(self._agent) * * def list_identities(self): # <<<<<<<<<<<<<< @@ -2681,7 +2704,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_4list_identities(CYTHON_UNUSED str return __pyx_r; } -/* "ssh2/agent.pyx":115 +/* "ssh2/agent.pyx":116 * pass * * def get_identities(self): # <<<<<<<<<<<<<< @@ -2719,19 +2742,19 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_identities", 0); - /* "ssh2/agent.pyx":120 + /* "ssh2/agent.pyx":121 * :rtype: list(:py:class:`ssh2.pkey.PublicKey`)""" * cdef int rc * cdef list identities = [] # <<<<<<<<<<<<<< * cdef c_ssh2.libssh2_agent_publickey *identity = NULL * cdef c_ssh2.libssh2_agent_publickey *prev = NULL */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 120, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 121, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_identities = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "ssh2/agent.pyx":121 + /* "ssh2/agent.pyx":122 * cdef int rc * cdef list identities = [] * cdef c_ssh2.libssh2_agent_publickey *identity = NULL # <<<<<<<<<<<<<< @@ -2740,7 +2763,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 */ __pyx_v_identity = NULL; - /* "ssh2/agent.pyx":122 + /* "ssh2/agent.pyx":123 * cdef list identities = [] * cdef c_ssh2.libssh2_agent_publickey *identity = NULL * cdef c_ssh2.libssh2_agent_publickey *prev = NULL # <<<<<<<<<<<<<< @@ -2749,7 +2772,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 */ __pyx_v_prev = NULL; - /* "ssh2/agent.pyx":123 + /* "ssh2/agent.pyx":124 * cdef c_ssh2.libssh2_agent_publickey *identity = NULL * cdef c_ssh2.libssh2_agent_publickey *prev = NULL * if c_ssh2.libssh2_agent_list_identities(self._agent) != 0: # <<<<<<<<<<<<<< @@ -2759,14 +2782,14 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 __pyx_t_2 = ((libssh2_agent_list_identities(__pyx_v_self->_agent) != 0) != 0); if (unlikely(__pyx_t_2)) { - /* "ssh2/agent.pyx":124 + /* "ssh2/agent.pyx":125 * cdef c_ssh2.libssh2_agent_publickey *prev = NULL * if c_ssh2.libssh2_agent_list_identities(self._agent) != 0: * raise AgentListIdentitiesError( # <<<<<<<<<<<<<< * "Failure requesting identities from agent." * "Agent must be connected first") */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_AgentListIdentitiesError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 124, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_AgentListIdentitiesError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { @@ -2780,14 +2803,14 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 } __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_s_Failure_requesting_identities_fr_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_s_Failure_requesting_identities_fr_2); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 124, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 124, __pyx_L1_error) + __PYX_ERR(1, 125, __pyx_L1_error) - /* "ssh2/agent.pyx":123 + /* "ssh2/agent.pyx":124 * cdef c_ssh2.libssh2_agent_publickey *identity = NULL * cdef c_ssh2.libssh2_agent_publickey *prev = NULL * if c_ssh2.libssh2_agent_list_identities(self._agent) != 0: # <<<<<<<<<<<<<< @@ -2796,7 +2819,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 */ } - /* "ssh2/agent.pyx":127 + /* "ssh2/agent.pyx":128 * "Failure requesting identities from agent." * "Agent must be connected first") * while c_ssh2.libssh2_agent_get_identity( # <<<<<<<<<<<<<< @@ -2805,7 +2828,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 */ while (1) { - /* "ssh2/agent.pyx":128 + /* "ssh2/agent.pyx":129 * "Agent must be connected first") * while c_ssh2.libssh2_agent_get_identity( * self._agent, &identity, prev) == 0: # <<<<<<<<<<<<<< @@ -2815,19 +2838,19 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 __pyx_t_2 = ((libssh2_agent_get_identity(__pyx_v_self->_agent, (&__pyx_v_identity), __pyx_v_prev) == 0) != 0); if (!__pyx_t_2) break; - /* "ssh2/agent.pyx":129 + /* "ssh2/agent.pyx":130 * while c_ssh2.libssh2_agent_get_identity( * self._agent, &identity, prev) == 0: * identities.append(PyPublicKey(identity)) # <<<<<<<<<<<<<< * prev = identity * return identities */ - __pyx_t_1 = __pyx_f_4ssh2_4pkey_PyPublicKey(__pyx_v_identity); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 129, __pyx_L1_error) + __pyx_t_1 = __pyx_f_4ssh2_4pkey_PyPublicKey(__pyx_v_identity); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 130, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_identities, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 129, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_identities, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 130, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "ssh2/agent.pyx":130 + /* "ssh2/agent.pyx":131 * self._agent, &identity, prev) == 0: * identities.append(PyPublicKey(identity)) * prev = identity # <<<<<<<<<<<<<< @@ -2837,7 +2860,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 __pyx_v_prev = __pyx_v_identity; } - /* "ssh2/agent.pyx":131 + /* "ssh2/agent.pyx":132 * identities.append(PyPublicKey(identity)) * prev = identity * return identities # <<<<<<<<<<<<<< @@ -2849,7 +2872,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 __pyx_r = __pyx_v_identities; goto __pyx_L0; - /* "ssh2/agent.pyx":115 + /* "ssh2/agent.pyx":116 * pass * * def get_identities(self): # <<<<<<<<<<<<<< @@ -2871,7 +2894,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_6get_identities(struct __pyx_obj_4 return __pyx_r; } -/* "ssh2/agent.pyx":133 +/* "ssh2/agent.pyx":134 * return identities * * def userauth(self, username not None, # <<<<<<<<<<<<<< @@ -2914,11 +2937,11 @@ static PyObject *__pyx_pw_4ssh2_5agent_5Agent_9userauth(PyObject *__pyx_v_self, case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pkey)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("userauth", 1, 2, 2, 1); __PYX_ERR(1, 133, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("userauth", 1, 2, 2, 1); __PYX_ERR(1, 134, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "userauth") < 0)) __PYX_ERR(1, 133, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "userauth") < 0)) __PYX_ERR(1, 134, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2931,16 +2954,16 @@ static PyObject *__pyx_pw_4ssh2_5agent_5Agent_9userauth(PyObject *__pyx_v_self, } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("userauth", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 133, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("userauth", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 134, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("ssh2.agent.Agent.userauth", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(((PyObject *)__pyx_v_username) == Py_None)) { - PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "username"); __PYX_ERR(1, 133, __pyx_L1_error) + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "username"); __PYX_ERR(1, 134, __pyx_L1_error) } - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pkey), __pyx_ptype_4ssh2_4pkey_PublicKey, 1, "pkey", 0))) __PYX_ERR(1, 134, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pkey), __pyx_ptype_4ssh2_4pkey_PublicKey, 1, "pkey", 0))) __PYX_ERR(1, 135, __pyx_L1_error) __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_8userauth(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self), __pyx_v_username, __pyx_v_pkey); /* function exit code */ @@ -2970,19 +2993,19 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("userauth", 0); - /* "ssh2/agent.pyx":147 + /* "ssh2/agent.pyx":148 * :rtype: int""" * cdef int rc * cdef bytes b_username = to_bytes(username) # <<<<<<<<<<<<<< * cdef char *_username = b_username * with nogil: */ - __pyx_t_1 = __pyx_f_4ssh2_5utils_to_bytes(__pyx_v_username); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 147, __pyx_L1_error) + __pyx_t_1 = __pyx_f_4ssh2_5utils_to_bytes(__pyx_v_username); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_b_username = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "ssh2/agent.pyx":148 + /* "ssh2/agent.pyx":149 * cdef int rc * cdef bytes b_username = to_bytes(username) * cdef char *_username = b_username # <<<<<<<<<<<<<< @@ -2991,12 +3014,12 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 */ if (unlikely(__pyx_v_b_username == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(1, 148, __pyx_L1_error) + __PYX_ERR(1, 149, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyBytes_AsWritableString(__pyx_v_b_username); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_AsWritableString(__pyx_v_b_username); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 149, __pyx_L1_error) __pyx_v__username = __pyx_t_2; - /* "ssh2/agent.pyx":149 + /* "ssh2/agent.pyx":150 * cdef bytes b_username = to_bytes(username) * cdef char *_username = b_username * with nogil: # <<<<<<<<<<<<<< @@ -3011,7 +3034,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 #endif /*try:*/ { - /* "ssh2/agent.pyx":150 + /* "ssh2/agent.pyx":151 * cdef char *_username = b_username * with nogil: * rc = c_ssh2.libssh2_agent_userauth( # <<<<<<<<<<<<<< @@ -3020,7 +3043,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 */ __pyx_v_rc = libssh2_agent_userauth(__pyx_v_self->_agent, __pyx_v__username, __pyx_v_pkey->_pkey); - /* "ssh2/agent.pyx":152 + /* "ssh2/agent.pyx":153 * rc = c_ssh2.libssh2_agent_userauth( * self._agent, _username, pkey._pkey) * if rc != 0 and rc != c_ssh2.LIBSSH2_ERROR_EAGAIN: # <<<<<<<<<<<<<< @@ -3038,7 +3061,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 } if (__pyx_t_3) { - /* "ssh2/agent.pyx":153 + /* "ssh2/agent.pyx":154 * self._agent, _username, pkey._pkey) * if rc != 0 and rc != c_ssh2.LIBSSH2_ERROR_EAGAIN: * with gil: # <<<<<<<<<<<<<< @@ -3051,17 +3074,17 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 #endif /*try:*/ { - /* "ssh2/agent.pyx":154 + /* "ssh2/agent.pyx":155 * if rc != 0 and rc != c_ssh2.LIBSSH2_ERROR_EAGAIN: * with gil: * raise AgentAuthenticationError( # <<<<<<<<<<<<<< * "Error authenticating user %s with provided public key", * username) */ - __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_AgentAuthenticationError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 154, __pyx_L8_error) + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_AgentAuthenticationError); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 155, __pyx_L8_error) __Pyx_GOTREF(__pyx_t_4); - /* "ssh2/agent.pyx":156 + /* "ssh2/agent.pyx":157 * raise AgentAuthenticationError( * "Error authenticating user %s with provided public key", * username) # <<<<<<<<<<<<<< @@ -3083,7 +3106,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_s_Error_authenticating_user_s_with, __pyx_v_username}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 154, __pyx_L8_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 155, __pyx_L8_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -3091,13 +3114,13 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_s_Error_authenticating_user_s_with, __pyx_v_username}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 154, __pyx_L8_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 155, __pyx_L8_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 154, __pyx_L8_error) + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 155, __pyx_L8_error) __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_5) { __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; @@ -3108,17 +3131,17 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 __Pyx_INCREF(__pyx_v_username); __Pyx_GIVEREF(__pyx_v_username); PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_username); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 154, __pyx_L8_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 155, __pyx_L8_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __PYX_ERR(1, 154, __pyx_L8_error) + __PYX_ERR(1, 155, __pyx_L8_error) } - /* "ssh2/agent.pyx":153 + /* "ssh2/agent.pyx":154 * self._agent, _username, pkey._pkey) * if rc != 0 and rc != c_ssh2.LIBSSH2_ERROR_EAGAIN: * with gil: # <<<<<<<<<<<<<< @@ -3135,7 +3158,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 } } - /* "ssh2/agent.pyx":152 + /* "ssh2/agent.pyx":153 * rc = c_ssh2.libssh2_agent_userauth( * self._agent, _username, pkey._pkey) * if rc != 0 and rc != c_ssh2.LIBSSH2_ERROR_EAGAIN: # <<<<<<<<<<<<<< @@ -3145,7 +3168,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 } } - /* "ssh2/agent.pyx":149 + /* "ssh2/agent.pyx":150 * cdef bytes b_username = to_bytes(username) * cdef char *_username = b_username * with nogil: # <<<<<<<<<<<<<< @@ -3171,7 +3194,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 } } - /* "ssh2/agent.pyx":157 + /* "ssh2/agent.pyx":158 * "Error authenticating user %s with provided public key", * username) * return rc # <<<<<<<<<<<<<< @@ -3179,13 +3202,13 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 * def disconnect(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rc); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 157, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rc); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "ssh2/agent.pyx":133 + /* "ssh2/agent.pyx":134 * return identities * * def userauth(self, username not None, # <<<<<<<<<<<<<< @@ -3208,7 +3231,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_8userauth(struct __pyx_obj_4ssh2_5 return __pyx_r; } -/* "ssh2/agent.pyx":159 +/* "ssh2/agent.pyx":160 * return rc * * def disconnect(self): # <<<<<<<<<<<<<< @@ -3240,7 +3263,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh int __pyx_clineno = 0; __Pyx_RefNannySetupContext("disconnect", 0); - /* "ssh2/agent.pyx":164 + /* "ssh2/agent.pyx":165 * :rtype: int""" * cdef int rc * with nogil: # <<<<<<<<<<<<<< @@ -3255,7 +3278,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh #endif /*try:*/ { - /* "ssh2/agent.pyx":165 + /* "ssh2/agent.pyx":166 * cdef int rc * with nogil: * rc = c_ssh2.libssh2_agent_disconnect(self._agent) # <<<<<<<<<<<<<< @@ -3265,7 +3288,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh __pyx_v_rc = libssh2_agent_disconnect(__pyx_v_self->_agent); } - /* "ssh2/agent.pyx":164 + /* "ssh2/agent.pyx":165 * :rtype: int""" * cdef int rc * with nogil: # <<<<<<<<<<<<<< @@ -3284,7 +3307,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh } } - /* "ssh2/agent.pyx":166 + /* "ssh2/agent.pyx":167 * with nogil: * rc = c_ssh2.libssh2_agent_disconnect(self._agent) * return rc # <<<<<<<<<<<<<< @@ -3292,13 +3315,13 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh * def connect(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rc); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 166, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rc); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "ssh2/agent.pyx":159 + /* "ssh2/agent.pyx":160 * return rc * * def disconnect(self): # <<<<<<<<<<<<<< @@ -3317,7 +3340,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_10disconnect(struct __pyx_obj_4ssh return __pyx_r; } -/* "ssh2/agent.pyx":168 +/* "ssh2/agent.pyx":169 * return rc * * def connect(self): # <<<<<<<<<<<<<< @@ -3352,7 +3375,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("connect", 0); - /* "ssh2/agent.pyx":176 + /* "ssh2/agent.pyx":177 * :rtype: int""" * cdef int rc * rc = c_ssh2.libssh2_agent_connect(self._agent) # <<<<<<<<<<<<<< @@ -3361,7 +3384,7 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 */ __pyx_v_rc = libssh2_agent_connect(__pyx_v_self->_agent); - /* "ssh2/agent.pyx":177 + /* "ssh2/agent.pyx":178 * cdef int rc * rc = c_ssh2.libssh2_agent_connect(self._agent) * if rc != 0: # <<<<<<<<<<<<<< @@ -3371,13 +3394,14 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 __pyx_t_1 = ((__pyx_v_rc != 0) != 0); if (unlikely(__pyx_t_1)) { - /* "ssh2/agent.pyx":178 + /* "ssh2/agent.pyx":179 * rc = c_ssh2.libssh2_agent_connect(self._agent) * if rc != 0: * raise AgentConnectionError("Unable to connect to agent") # <<<<<<<<<<<<<< * return rc + * */ - __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_AgentConnectionError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 178, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_AgentConnectionError); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 179, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { @@ -3391,14 +3415,14 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 } __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_s_Unable_to_connect_to_agent) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_s_Unable_to_connect_to_agent); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 178, __pyx_L1_error) + if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 179, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __PYX_ERR(1, 178, __pyx_L1_error) + __PYX_ERR(1, 179, __pyx_L1_error) - /* "ssh2/agent.pyx":177 + /* "ssh2/agent.pyx":178 * cdef int rc * rc = c_ssh2.libssh2_agent_connect(self._agent) * if rc != 0: # <<<<<<<<<<<<<< @@ -3407,19 +3431,21 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 */ } - /* "ssh2/agent.pyx":179 + /* "ssh2/agent.pyx":180 * if rc != 0: * raise AgentConnectionError("Unable to connect to agent") * return rc # <<<<<<<<<<<<<< + * + * def get_identity_path(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_rc); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 179, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_rc); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; - /* "ssh2/agent.pyx":168 + /* "ssh2/agent.pyx":169 * return rc * * def connect(self): # <<<<<<<<<<<<<< @@ -3440,6 +3466,302 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 return __pyx_r; } +/* "ssh2/agent.pyx":182 + * return rc + * + * def get_identity_path(self): # <<<<<<<<<<<<<< + * cdef bytes _path + * cdef const char* c_path = NULL + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_15get_identity_path(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_4ssh2_5agent_5Agent_14get_identity_path[] = "Agent.get_identity_path(self)"; +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_15get_identity_path(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_identity_path (wrapper)", 0); + __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_14get_identity_path(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_14get_identity_path(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self) { + PyObject *__pyx_v__path = 0; + char const *__pyx_v_c_path; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_identity_path", 0); + + /* "ssh2/agent.pyx":184 + * def get_identity_path(self): + * cdef bytes _path + * cdef const char* c_path = NULL # <<<<<<<<<<<<<< + * with nogil: + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + */ + __pyx_v_c_path = NULL; + + /* "ssh2/agent.pyx":185 + * cdef bytes _path + * cdef const char* c_path = NULL + * with nogil: # <<<<<<<<<<<<<< + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + * if c_path is NULL: + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "ssh2/agent.pyx":186 + * cdef const char* c_path = NULL + * with nogil: + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) # <<<<<<<<<<<<<< + * if c_path is NULL: + * return + */ + __pyx_v_c_path = libssh2_agent_get_identity_path(__pyx_v_self->_agent); + } + + /* "ssh2/agent.pyx":185 + * cdef bytes _path + * cdef const char* c_path = NULL + * with nogil: # <<<<<<<<<<<<<< + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + * if c_path is NULL: + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L5; + } + __pyx_L5:; + } + } + + /* "ssh2/agent.pyx":187 + * with nogil: + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + * if c_path is NULL: # <<<<<<<<<<<<<< + * return + * _path = c_path + */ + __pyx_t_1 = ((__pyx_v_c_path == NULL) != 0); + if (__pyx_t_1) { + + /* "ssh2/agent.pyx":188 + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + * if c_path is NULL: + * return # <<<<<<<<<<<<<< + * _path = c_path + * return _path + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + + /* "ssh2/agent.pyx":187 + * with nogil: + * c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + * if c_path is NULL: # <<<<<<<<<<<<<< + * return + * _path = c_path + */ + } + + /* "ssh2/agent.pyx":189 + * if c_path is NULL: + * return + * _path = c_path # <<<<<<<<<<<<<< + * return _path + * + */ + __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_c_path); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 189, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v__path = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "ssh2/agent.pyx":190 + * return + * _path = c_path + * return _path # <<<<<<<<<<<<<< + * + * def set_identity_path(self, path not None): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v__path); + __pyx_r = __pyx_v__path; + goto __pyx_L0; + + /* "ssh2/agent.pyx":182 + * return rc + * + * def get_identity_path(self): # <<<<<<<<<<<<<< + * cdef bytes _path + * cdef const char* c_path = NULL + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("ssh2.agent.Agent.get_identity_path", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v__path); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "ssh2/agent.pyx":192 + * return _path + * + * def set_identity_path(self, path not None): # <<<<<<<<<<<<<< + * cdef bytes b_path = to_bytes(path) + * cdef const char *c_path = b_path + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_17set_identity_path(PyObject *__pyx_v_self, PyObject *__pyx_v_path); /*proto*/ +static char __pyx_doc_4ssh2_5agent_5Agent_16set_identity_path[] = "Agent.set_identity_path(self, path)"; +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_17set_identity_path(PyObject *__pyx_v_self, PyObject *__pyx_v_path) { + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("set_identity_path (wrapper)", 0); + if (unlikely(((PyObject *)__pyx_v_path) == Py_None)) { + PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "path"); __PYX_ERR(1, 192, __pyx_L1_error) + } + __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_16set_identity_path(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self), ((PyObject *)__pyx_v_path)); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_16set_identity_path(struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, PyObject *__pyx_v_path) { + PyObject *__pyx_v_b_path = 0; + char const *__pyx_v_c_path; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + char const *__pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set_identity_path", 0); + + /* "ssh2/agent.pyx":193 + * + * def set_identity_path(self, path not None): + * cdef bytes b_path = to_bytes(path) # <<<<<<<<<<<<<< + * cdef const char *c_path = b_path + * with nogil: + */ + __pyx_t_1 = __pyx_f_4ssh2_5utils_to_bytes(__pyx_v_path); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 193, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_b_path = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "ssh2/agent.pyx":194 + * def set_identity_path(self, path not None): + * cdef bytes b_path = to_bytes(path) + * cdef const char *c_path = b_path # <<<<<<<<<<<<<< + * with nogil: + * c_ssh2.libssh2_agent_set_identity_path( + */ + if (unlikely(__pyx_v_b_path == Py_None)) { + PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); + __PYX_ERR(1, 194, __pyx_L1_error) + } + __pyx_t_2 = __Pyx_PyBytes_AsString(__pyx_v_b_path); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 194, __pyx_L1_error) + __pyx_v_c_path = __pyx_t_2; + + /* "ssh2/agent.pyx":195 + * cdef bytes b_path = to_bytes(path) + * cdef const char *c_path = b_path + * with nogil: # <<<<<<<<<<<<<< + * c_ssh2.libssh2_agent_set_identity_path( + * self._agent, c_path) + */ + { + #ifdef WITH_THREAD + PyThreadState *_save; + Py_UNBLOCK_THREADS + __Pyx_FastGIL_Remember(); + #endif + /*try:*/ { + + /* "ssh2/agent.pyx":196 + * cdef const char *c_path = b_path + * with nogil: + * c_ssh2.libssh2_agent_set_identity_path( # <<<<<<<<<<<<<< + * self._agent, c_path) + */ + libssh2_agent_set_identity_path(__pyx_v_self->_agent, __pyx_v_c_path); + } + + /* "ssh2/agent.pyx":195 + * cdef bytes b_path = to_bytes(path) + * cdef const char *c_path = b_path + * with nogil: # <<<<<<<<<<<<<< + * c_ssh2.libssh2_agent_set_identity_path( + * self._agent, c_path) + */ + /*finally:*/ { + /*normal exit:*/{ + #ifdef WITH_THREAD + __Pyx_FastGIL_Forget(); + Py_BLOCK_THREADS + #endif + goto __pyx_L5; + } + __pyx_L5:; + } + } + + /* "ssh2/agent.pyx":192 + * return _path + * + * def set_identity_path(self, path not None): # <<<<<<<<<<<<<< + * cdef bytes b_path = to_bytes(path) + * cdef const char *c_path = b_path + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("ssh2.agent.Agent.set_identity_path", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_b_path); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("no default __reduce__ due to non-trivial __cinit__") @@ -3447,20 +3769,20 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_12connect(struct __pyx_obj_4ssh2_5 */ /* Python wrapper */ -static PyObject *__pyx_pw_4ssh2_5agent_5Agent_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_4ssh2_5agent_5Agent_14__reduce_cython__[] = "Agent.__reduce_cython__(self)"; -static PyObject *__pyx_pw_4ssh2_5agent_5Agent_15__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_19__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_4ssh2_5agent_5Agent_18__reduce_cython__[] = "Agent.__reduce_cython__(self)"; +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_19__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_14__reduce_cython__(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self)); + __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_18__reduce_cython__(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_4ssh2_5agent_5Agent_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self) { +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_18__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3505,20 +3827,20 @@ static PyObject *__pyx_pf_4ssh2_5agent_5Agent_14__reduce_cython__(CYTHON_UNUSED */ /* Python wrapper */ -static PyObject *__pyx_pw_4ssh2_5agent_5Agent_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static char __pyx_doc_4ssh2_5agent_5Agent_16__setstate_cython__[] = "Agent.__setstate_cython__(self, __pyx_state)"; -static PyObject *__pyx_pw_4ssh2_5agent_5Agent_17__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_21__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static char __pyx_doc_4ssh2_5agent_5Agent_20__setstate_cython__[] = "Agent.__setstate_cython__(self, __pyx_state)"; +static PyObject *__pyx_pw_4ssh2_5agent_5Agent_21__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_16__setstate_cython__(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_4ssh2_5agent_5Agent_20__setstate_cython__(((struct __pyx_obj_4ssh2_5agent_Agent *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_4ssh2_5agent_5Agent_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_4ssh2_5agent_5Agent_20__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_4ssh2_5agent_Agent *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3617,8 +3939,10 @@ static PyMethodDef __pyx_methods_4ssh2_5agent_Agent[] = { {"userauth", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_4ssh2_5agent_5Agent_9userauth, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4ssh2_5agent_5Agent_8userauth}, {"disconnect", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_11disconnect, METH_NOARGS, __pyx_doc_4ssh2_5agent_5Agent_10disconnect}, {"connect", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_13connect, METH_NOARGS, __pyx_doc_4ssh2_5agent_5Agent_12connect}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_15__reduce_cython__, METH_NOARGS, __pyx_doc_4ssh2_5agent_5Agent_14__reduce_cython__}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_17__setstate_cython__, METH_O, __pyx_doc_4ssh2_5agent_5Agent_16__setstate_cython__}, + {"get_identity_path", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_15get_identity_path, METH_NOARGS, __pyx_doc_4ssh2_5agent_5Agent_14get_identity_path}, + {"set_identity_path", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_17set_identity_path, METH_O, __pyx_doc_4ssh2_5agent_5Agent_16set_identity_path}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_19__reduce_cython__, METH_NOARGS, __pyx_doc_4ssh2_5agent_5Agent_18__reduce_cython__}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_4ssh2_5agent_5Agent_21__setstate_cython__, METH_O, __pyx_doc_4ssh2_5agent_5Agent_20__setstate_cython__}, {0, 0, 0, 0} }; diff --git a/ssh2/agent.pyx b/ssh2/agent.pyx index 166ec907..d8b55bfe 100644 --- a/ssh2/agent.pyx +++ b/ssh2/agent.pyx @@ -99,7 +99,8 @@ cdef object PyAgent(c_ssh2.LIBSSH2_AGENT *agent, Session session): cdef class Agent: def __cinit__(self, Session session): - self._agent = NULL + cdef c_ssh2.LIBSSH2_AGENT *_agent = agent_init(session._session) + self._agent = _agent self._session = session def __dealloc__(self): @@ -177,3 +178,20 @@ cdef class Agent: if rc != 0: raise AgentConnectionError("Unable to connect to agent") return rc + + def get_identity_path(self): + cdef bytes _path + cdef const char* c_path = NULL + with nogil: + c_path = c_ssh2.libssh2_agent_get_identity_path(self._agent) + if c_path is NULL: + return + _path = c_path + return _path + + def set_identity_path(self, path not None): + cdef bytes b_path = to_bytes(path) + cdef const char *c_path = b_path + with nogil: + c_ssh2.libssh2_agent_set_identity_path( + self._agent, c_path) diff --git a/ssh2/c_ssh2.pxd b/ssh2/c_ssh2.pxd index 6cd9708e..d62ec70a 100644 --- a/ssh2/c_ssh2.pxd +++ b/ssh2/c_ssh2.pxd @@ -450,5 +450,8 @@ cdef extern from "libssh2.h" nogil: int libssh2_trace_sethandler(LIBSSH2_SESSION *session, void* context, libssh2_trace_handler_func callback) + const char *libssh2_agent_get_identity_path(LIBSSH2_AGENT *agent) + void libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent, + const char *path) IF HAVE_AGENT_FWD: int libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel) diff --git a/tests/test_agent.py b/tests/test_agent.py new file mode 100644 index 00000000..7a191a4d --- /dev/null +++ b/tests/test_agent.py @@ -0,0 +1,37 @@ +import os +import socket +from unittest import skipUnless + +from .base_test import SSH2TestCase +from ssh2.session import Session, LIBSSH2_HOSTKEY_HASH_MD5, \ + LIBSSH2_HOSTKEY_HASH_SHA1 +# from ssh2.sftp import SFTP +from ssh2.agent import Agent +# from ssh2.error_codes import LIBSSH2_ERROR_EAGAIN +from ssh2.exceptions import AuthenticationError, AgentAuthenticationError, \ + SCPProtocolError, RequestDeniedError, InvalidRequestError, \ + SocketSendError, FileError, PublickeyUnverifiedError +from ssh2.utils import wait_socket + + +class SessionTestCase(SSH2TestCase): + + def test_agent_pyobject(self): + agent = Agent(self.session) + self.assertIsInstance(agent, Agent) + + def test_agent_get_identities(self): + agent = Agent(self.session) + agent.connect() + ids = agent.get_identities() + self.assertIsInstance(ids, list) + agent.disconnect() + + def test_agent_id_path(self): + agent = Agent(self.session) + agent.connect() + _path = b'my_path' + agent.set_identity_path(_path) + path = agent.get_identity_path() + self.assertEqual(_path, path) + agent.disconnect()