Add Py3 helpers to common.py
This commit is contained in:
parent
8edd2cc75e
commit
cd918d0dc6
|
@ -19,12 +19,13 @@
|
||||||
"""
|
"""
|
||||||
Common constants and global variables.
|
Common constants and global variables.
|
||||||
"""
|
"""
|
||||||
|
from paramiko.py3compat import *
|
||||||
|
|
||||||
MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, MSG_SERVICE_REQUEST, \
|
MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, MSG_SERVICE_REQUEST, \
|
||||||
MSG_SERVICE_ACCEPT = range(1, 7)
|
MSG_SERVICE_ACCEPT = range(1, 7)
|
||||||
MSG_KEXINIT, MSG_NEWKEYS = range(20, 22)
|
MSG_KEXINIT, MSG_NEWKEYS = range(20, 22)
|
||||||
MSG_USERAUTH_REQUEST, MSG_USERAUTH_FAILURE, MSG_USERAUTH_SUCCESS, \
|
MSG_USERAUTH_REQUEST, MSG_USERAUTH_FAILURE, MSG_USERAUTH_SUCCESS, \
|
||||||
MSG_USERAUTH_BANNER = range(50, 54)
|
MSG_USERAUTH_BANNER = range(50, 54)
|
||||||
MSG_USERAUTH_PK_OK = 60
|
MSG_USERAUTH_PK_OK = 60
|
||||||
MSG_USERAUTH_INFO_REQUEST, MSG_USERAUTH_INFO_RESPONSE = range(60, 62)
|
MSG_USERAUTH_INFO_REQUEST, MSG_USERAUTH_INFO_RESPONSE = range(60, 62)
|
||||||
MSG_GLOBAL_REQUEST, MSG_REQUEST_SUCCESS, MSG_REQUEST_FAILURE = range(80, 83)
|
MSG_GLOBAL_REQUEST, MSG_REQUEST_SUCCESS, MSG_REQUEST_FAILURE = range(80, 83)
|
||||||
|
@ -33,6 +34,10 @@ MSG_CHANNEL_OPEN, MSG_CHANNEL_OPEN_SUCCESS, MSG_CHANNEL_OPEN_FAILURE, \
|
||||||
MSG_CHANNEL_EOF, MSG_CHANNEL_CLOSE, MSG_CHANNEL_REQUEST, \
|
MSG_CHANNEL_EOF, MSG_CHANNEL_CLOSE, MSG_CHANNEL_REQUEST, \
|
||||||
MSG_CHANNEL_SUCCESS, MSG_CHANNEL_FAILURE = range(90, 101)
|
MSG_CHANNEL_SUCCESS, MSG_CHANNEL_FAILURE = range(90, 101)
|
||||||
|
|
||||||
|
for key in list(globals().keys()):
|
||||||
|
if key.startswith('MSG_'):
|
||||||
|
globals()['c' + key] = byte_chr(globals()[key])
|
||||||
|
del key
|
||||||
|
|
||||||
# for debugging:
|
# for debugging:
|
||||||
MSG_NAMES = {
|
MSG_NAMES = {
|
||||||
|
@ -69,7 +74,7 @@ MSG_NAMES = {
|
||||||
MSG_CHANNEL_REQUEST: 'channel-request',
|
MSG_CHANNEL_REQUEST: 'channel-request',
|
||||||
MSG_CHANNEL_SUCCESS: 'channel-success',
|
MSG_CHANNEL_SUCCESS: 'channel-success',
|
||||||
MSG_CHANNEL_FAILURE: 'channel-failure'
|
MSG_CHANNEL_FAILURE: 'channel-failure'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# authentication request return codes:
|
# authentication request return codes:
|
||||||
|
@ -118,6 +123,44 @@ else:
|
||||||
import logging
|
import logging
|
||||||
PY22 = False
|
PY22 = False
|
||||||
|
|
||||||
|
if PY3:
|
||||||
|
zero_byte = b'\x00'
|
||||||
|
one_byte = b'\x01'
|
||||||
|
four_byte = b'\x04'
|
||||||
|
max_byte = b'\xff'
|
||||||
|
newline_byte = b'\n'
|
||||||
|
cr_byte = b'\r'
|
||||||
|
else:
|
||||||
|
zero_byte = '\x00'
|
||||||
|
one_byte = '\x01'
|
||||||
|
four_byte = '\x04'
|
||||||
|
max_byte = '\xff'
|
||||||
|
newline_byte = '\n'
|
||||||
|
cr_byte = '\r'
|
||||||
|
|
||||||
|
|
||||||
|
def asbytes(s):
|
||||||
|
if not isinstance(s, bytes_type):
|
||||||
|
if isinstance(s, string_types):
|
||||||
|
s = b(s)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
s = s.asbytes()
|
||||||
|
except Exception:
|
||||||
|
raise Exception('Unknown type')
|
||||||
|
return s
|
||||||
|
|
||||||
|
xffffffff = long(0xffffffff)
|
||||||
|
x80000000 = long(0x80000000)
|
||||||
|
long_zero = long(0)
|
||||||
|
long_one = long(1)
|
||||||
|
o666 = 438
|
||||||
|
o660 = 432
|
||||||
|
o644 = 420
|
||||||
|
o600 = 384
|
||||||
|
o777 = 511
|
||||||
|
o700 = 448
|
||||||
|
o70 = 56
|
||||||
|
|
||||||
DEBUG = logging.DEBUG
|
DEBUG = logging.DEBUG
|
||||||
INFO = logging.INFO
|
INFO = logging.INFO
|
||||||
|
|
Loading…
Reference in New Issue