Skip to content

Commit ff51ef4

Browse files
author
Pan
committed
Added cython based libssh2 bindings, error codes and initial session extension class implementation with exceptions
0 parents  commit ff51ef4

File tree

9 files changed

+11868
-0
lines changed

9 files changed

+11868
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.egg-info
2+
*.pyc
3+
dist
4+
build
5+
*~
6+
*.so

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include libssh2/*.c
2+
include libssh2/*.h

README.rst

Whitespace-only changes.

setup.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from __future__ import print_function
2+
3+
import platform
4+
import os
5+
import sys
6+
import glob
7+
8+
# import versioneer
9+
from setuptools import setup, find_packages, Extension
10+
11+
cpython = platform.python_implementation() == 'CPython'
12+
13+
try:
14+
from Cython.Build import cythonize
15+
except ImportError:
16+
USING_CYTHON = False
17+
else:
18+
USING_CYTHON = True
19+
20+
ext = 'pyx' if USING_CYTHON else 'c'
21+
22+
sources = glob.glob("ssh2/*.%s" % (ext,))
23+
24+
extensions = [
25+
Extension("ssh2.ssh2",
26+
sources=sources,
27+
libraries=['ssh2'],
28+
# extra_compile_args=["-O3"],
29+
),
30+
]
31+
32+
if USING_CYTHON:
33+
extensions = cythonize(
34+
extensions,
35+
compiler_directives={'embedsignature': True,
36+
'optimize.use_switch': True,
37+
# 'boundscheck': False,
38+
'wraparound': False,
39+
})
40+
41+
setup(
42+
name='libssh2-python',
43+
# version=versioneer.get_version(),
44+
version='0.1a0',
45+
url='https://github.com/ParallelSSH/libssh2_python',
46+
license='LGPLv2',
47+
author='Panos Kittenis',
48+
author_email='22e889d8@opayq.com',
49+
description=('Python bindings for libssh2 based on Cython'),
50+
long_description=open('README.rst').read(),
51+
packages=find_packages('.'),
52+
zip_safe=False,
53+
include_package_data=True,
54+
platforms='any',
55+
classifiers=[
56+
'Intended Audience :: Developers',
57+
'Operating System :: OS Independent',
58+
'Programming Language :: Python',
59+
'Programming Language :: Python :: 2',
60+
'Programming Language :: Python :: 3',
61+
],
62+
ext_modules=extensions,
63+
)

ssh2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .ssh2 import Session, Channel

ssh2/error_codes.pxd

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cdef extern from "libssh2.h" nogil:
2+
# Error Codes (defined by libssh2)
3+
# The library once used -1 as a generic error return value on numerous
4+
# places through the code, which subsequently was converted to
5+
# LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
6+
# the goal is to never ever return this code but instead make sure that a
7+
# more accurate and descriptive error code is used.
8+
enum:
9+
_LIBSSH2_ERROR_NONE "LIBSSH2_ERROR_NONE"
10+
_LIBSSH2_ERROR_SOCKET_NONE "LIBSSH2_ERROR_SOCKET_NONE"
11+
_LIBSSH2_ERROR_BANNER_RECV "LIBSSH2_ERROR_BANNER_RECV"
12+
_LIBSSH2_ERROR_BANNER_SEND "LIBSSH2_ERROR_BANNER_SEND"
13+
_LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE "LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE"
14+
_LIBSSH2_ERROR_TIMEOUT "LIBSSH2_ERROR_TIMEOUT"
15+
_LIBSSH2_ERROR_HOSTKEY_INIT "LIBSSH2_ERROR_HOSTKEY_INIT"
16+
_LIBSSH2_ERROR_HOSTKEY_SIGN "LIBSSH2_ERROR_HOSTKEY_SIGN"
17+
_LIBSSH2_ERROR_DECRYPT "LIBSSH2_ERROR_DECRYPT"
18+
_LIBSSH2_ERROR_SOCKET_DISCONNECT "LIBSSH2_ERROR_SOCKET_DISCONNECT"
19+
_LIBSSH2_ERROR_PROTO "LIBSSH2_ERROR_PROTO"
20+
_LIBSSH2_ERROR_PASSWORD_EXPIRED "LIBSSH2_ERROR_PASSWORD_EXPIRED"
21+
_LIBSSH2_ERROR_FILE "LIBSSH2_ERROR_FILE"
22+
_LIBSSH2_ERROR_METHOD_NONE "LIBSSH2_ERROR_METHOD_NONE"
23+
_LIBSSH2_ERROR_AUTHENTICATION_FAILED "LIBSSH2_ERROR_AUTHENTICATION_FAILED"
24+
_LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED "LIBSSH2_ERROR_AUTHENTICATION_FAILED"
25+
_LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED "LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED"
26+
_LIBSSH2_ERROR_CHANNEL_OUTOFORDER "LIBSSH2_ERROR_CHANNEL_OUTOFORDER"
27+
_LIBSSH2_ERROR_CHANNEL_FAILURE "LIBSSH2_ERROR_CHANNEL_FAILURE"
28+
_LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED "LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED"
29+
_LIBSSH2_ERROR_CHANNEL_UNKNOWN "LIBSSH2_ERROR_CHANNEL_UNKNOWN"
30+
_LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED "LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED"
31+
_LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED "LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED"
32+
_LIBSSH2_ERROR_CHANNEL_CLOSED "LIBSSH2_ERROR_CHANNEL_CLOSED"
33+
_LIBSSH2_ERROR_CHANNEL_EOF_SENT "LIBSSH2_ERROR_CHANNEL_EOF_SENT"
34+
_LIBSSH2_ERROR_SCP_PROTOCOL "LIBSSH2_ERROR_SCP_PROTOCOL"
35+
_LIBSSH2_ERROR_ZLIB "LIBSSH2_ERROR_ZLIB"
36+
_LIBSSH2_ERROR_SOCKET_TIMEOUT "LIBSSH2_ERROR_SOCKET_TIMEOUT"
37+
_LIBSSH2_ERROR_SFTP_PROTOCOL "LIBSSH2_ERROR_SFTP_PROTOCOL"
38+
_LIBSSH2_ERROR_REQUEST_DENIED "LIBSSH2_ERROR_REQUEST_DENIED"
39+
_LIBSSH2_ERROR_METHOD_NOT_SUPPORTED "LIBSSH2_ERROR_METHOD_NOT_SUPPORTED"
40+
_LIBSSH2_ERROR_INVAL "LIBSSH2_ERROR_INVAL"
41+
_LIBSSH2_ERROR_INVALID_POLL_TYPE "LIBSSH2_ERROR_INVALID_POLL_TYPE"
42+
_LIBSSH2_ERROR_PUBLICKEY_PROTOCOL "LIBSSH2_ERROR_PUBLICKEY_PROTOCOL"
43+
_LIBSSH2_ERROR_EAGAIN "LIBSSH2_ERROR_EAGAIN"
44+
_LIBSSH2CHANNEL_EAGAIN "LIBSSH2_ERROR_EAGAIN"
45+
_LIBSSH2_ERROR_BUFFER_TOO_SMALL "LIBSSH2_ERROR_BUFFER_TOO_SMALL"
46+
_LIBSSH2_ERROR_BAD_USE "LIBSSH2_ERROR_BAD_USE"
47+
_LIBSSH2_ERROR_COMPRESS "LIBSSH2_ERROR_COMPRESS"
48+
_LIBSSH2_ERROR_OUT_OF_BOUNDARY "LIBSSH2_ERROR_OUT_OF_BOUNDARY"
49+
_LIBSSH2_ERROR_AGENT_PROTOCOL "LIBSSH2_ERROR_AGENT_PROTOCOL"
50+
_LIBSSH2_ERROR_SOCKET_RECV "LIBSSH2_ERROR_SOCKET_RECV"
51+
_LIBSSH2_ERROR_ENCRYPT "LIBSSH2_ERROR_ENCRYPT"
52+
_LIBSSH2_ERROR_BAD_SOCKET "LIBSSH2_ERROR_BAD_SOCKET"
53+
_LIBSSH2_ERROR_KNOWN_HOSTS "LIBSSH2_ERROR_KNOWN_HOSTS"

0 commit comments

Comments
 (0)