Add Py3 helpers to common.py
This commit is contained in:
parent
8edd2cc75e
commit
cd918d0dc6
|
@ -19,6 +19,7 @@
|
|||
"""
|
||||
Common constants and global variables.
|
||||
"""
|
||||
from paramiko.py3compat import *
|
||||
|
||||
MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, MSG_SERVICE_REQUEST, \
|
||||
MSG_SERVICE_ACCEPT = range(1, 7)
|
||||
|
@ -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_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:
|
||||
MSG_NAMES = {
|
||||
|
@ -69,7 +74,7 @@ MSG_NAMES = {
|
|||
MSG_CHANNEL_REQUEST: 'channel-request',
|
||||
MSG_CHANNEL_SUCCESS: 'channel-success',
|
||||
MSG_CHANNEL_FAILURE: 'channel-failure'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# authentication request return codes:
|
||||
|
@ -118,6 +123,44 @@ else:
|
|||
import logging
|
||||
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
|
||||
INFO = logging.INFO
|
||||
|
|
Loading…
Reference in New Issue