diff --git a/paramiko/agent.py b/paramiko/agent.py index 7e32c79..fcf9b64 100644 --- a/paramiko/agent.py +++ b/paramiko/agent.py @@ -20,15 +20,19 @@ SSH Agent interface for Unix clients. """ -import os, socket, struct +import os +import socket +import struct + +from paramiko.ssh_exception import SSHException +from paramiko.message import Message +from paramiko.pkey import PKey -from ssh_exception import SSHException -from message import Message -from pkey import PKey SSH2_AGENTC_REQUEST_IDENTITIES, SSH2_AGENT_IDENTITIES_ANSWER, \ SSH2_AGENTC_SIGN_REQUEST, SSH2_AGENT_SIGN_RESPONSE = range(11, 15) + class Agent: """ Client interface for using private keys from an SSH agent running on the diff --git a/paramiko/auth_handler.py b/paramiko/auth_handler.py index f2ea0d8..8764689 100644 --- a/paramiko/auth_handler.py +++ b/paramiko/auth_handler.py @@ -25,11 +25,11 @@ import threading # this helps freezing utils import encodings.utf_8 -from common import * -import util -from message import Message -from ssh_exception import SSHException, BadAuthenticationType, PartialAuthentication -from server import InteractiveQuery +from paramiko.common import * +from paramiko import util +from paramiko.message import Message +from paramiko.ssh_exception import SSHException, BadAuthenticationType, PartialAuthentication +from paramiko.server import InteractiveQuery class AuthHandler (object): diff --git a/paramiko/ber.py b/paramiko/ber.py index a28b4a7..6a7823d 100644 --- a/paramiko/ber.py +++ b/paramiko/ber.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -18,12 +16,14 @@ # along with Paramiko; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -import struct, util +import struct +import util class BERException (Exception): pass + class BER(object): """ Robey's tiny little attempt at a BER decoder. diff --git a/paramiko/channel.py b/paramiko/channel.py index db85aac..5edf4b3 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -20,14 +20,18 @@ Abstraction for an SSH2 channel. """ -import sys, time, threading, socket, os +import sys +import time +import threading +import socket +import os -from common import * -import util -from message import Message -from ssh_exception import SSHException -from file import BufferedFile -import pipe +from paramiko.common import * +from paramiko import util +from paramiko.message import Message +from paramiko.ssh_exception import SSHException +from paramiko.file import BufferedFile +from paramiko import pipe class Channel (object): @@ -1105,8 +1109,6 @@ class Channel (object): return size - - class ChannelFile (BufferedFile): """ A file-like wrapper around L{Channel}. A ChannelFile is created by calling diff --git a/paramiko/common.py b/paramiko/common.py index 548013d..360b804 100644 --- a/paramiko/common.py +++ b/paramiko/common.py @@ -33,6 +33,7 @@ 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 debugging: MSG_NAMES = { MSG_DISCONNECT: 'disconnect', @@ -70,19 +71,19 @@ MSG_NAMES = { MSG_CHANNEL_FAILURE: 'channel-failure' } -# authentication request return codes: +# authentication request return codes: AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED = range(3) # channel request failed reasons: - (OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, OPEN_FAILED_CONNECT_FAILED, OPEN_FAILED_UNKNOWN_CHANNEL_TYPE, OPEN_FAILED_RESOURCE_SHORTAGE) = range(0, 5) + CONNECTION_FAILED_CODE = { 1: 'Administratively prohibited', 2: 'Connect failed', @@ -95,7 +96,6 @@ DISCONNECT_SERVICE_NOT_AVAILABLE, DISCONNECT_AUTH_CANCELLED_BY_USER, \ DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 7, 13, 14 - from Crypto.Util.randpool import PersistentRandomPool, RandomPool # keep a crypto-strong PRNG nearby diff --git a/paramiko/dsskey.py b/paramiko/dsskey.py index d7534ba..6e94d81 100644 --- a/paramiko/dsskey.py +++ b/paramiko/dsskey.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -25,12 +23,13 @@ L{DSSKey} from Crypto.PublicKey import DSA from Crypto.Hash import SHA -from common import * -import util -from ssh_exception import SSHException -from message import Message -from ber import BER, BERException -from pkey import PKey +from paramiko.common import * +from paramiko import util +from paramiko.ssh_exception import SSHException +from paramiko.message import Message +from paramiko.ber import BER, BERException +from paramiko.pkey import PKey + class DSSKey (PKey): """ @@ -167,4 +166,3 @@ class DSSKey (PKey): self.y = keylist[4] self.x = keylist[5] self.size = util.bit_length(self.p) - diff --git a/paramiko/file.py b/paramiko/file.py index f066c4a..c29e7c4 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -24,6 +22,7 @@ BufferedFile. from cStringIO import StringIO + _FLAG_READ = 0x1 _FLAG_WRITE = 0x2 _FLAG_APPEND = 0x4 @@ -32,6 +31,7 @@ _FLAG_BUFFERED = 0x20 _FLAG_LINE_BUFFERED = 0x40 _FLAG_UNIVERSAL_NEWLINE = 0x80 + class BufferedFile (object): """ Reusable base class to implement python-style file buffering around a diff --git a/paramiko/kex_gex.py b/paramiko/kex_gex.py index e0974c1..994d76c 100644 --- a/paramiko/kex_gex.py +++ b/paramiko/kex_gex.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -27,10 +25,10 @@ client side, and a B{lot} more on the server side. from Crypto.Hash import SHA from Crypto.Util import number -from common import * -from message import Message -import util -from ssh_exception import SSHException +from paramiko.common import * +from paramiko import util +from paramiko.message import Message +from paramiko.ssh_exception import SSHException _MSG_KEXDH_GEX_GROUP, _MSG_KEXDH_GEX_INIT, _MSG_KEXDH_GEX_REPLY, _MSG_KEXDH_GEX_REQUEST = range(31, 35) diff --git a/paramiko/kex_group1.py b/paramiko/kex_group1.py index 3371368..a13cf3a 100644 --- a/paramiko/kex_group1.py +++ b/paramiko/kex_group1.py @@ -23,10 +23,11 @@ Standard SSH key exchange ("kex" if you wanna sound cool). Diffie-Hellman of from Crypto.Hash import SHA -from common import * -import util -from message import Message -from ssh_exception import SSHException +from paramiko.common import * +from paramiko import util +from paramiko.message import Message +from paramiko.ssh_exception import SSHException + _MSG_KEXDH_INIT, _MSG_KEXDH_REPLY = range(30, 32) diff --git a/paramiko/logging22.py b/paramiko/logging22.py index 85f5947..e21b154 100644 --- a/paramiko/logging22.py +++ b/paramiko/logging22.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -22,15 +20,18 @@ Stub out logging on python < 2.3. """ + DEBUG = 10 INFO = 20 WARNING = 30 ERROR = 40 CRITICAL = 50 + def getLogger(name): return _logger + class logger (object): def __init__(self): self.handlers = [ ] diff --git a/paramiko/message.py b/paramiko/message.py index e36d93a..1d75a01 100644 --- a/paramiko/message.py +++ b/paramiko/message.py @@ -20,8 +20,10 @@ Implementation of an SSH2 "message". """ -import struct, cStringIO -import util +import struct +import cStringIO + +from paramiko import util class Message (object): diff --git a/paramiko/packet.py b/paramiko/packet.py index b7a2793..6de9971 100644 --- a/paramiko/packet.py +++ b/paramiko/packet.py @@ -20,12 +20,17 @@ Packetizer. """ -import select, socket, struct, threading, time +import select +import socket +import struct +import threading +import time from Crypto.Hash import HMAC -from common import * -from ssh_exception import SSHException -from message import Message -import util + +from paramiko.common import * +from paramiko import util +from paramiko.ssh_exception import SSHException +from paramiko.message import Message class Packetizer (object): diff --git a/paramiko/pipe.py b/paramiko/pipe.py index 332090e..8c53987 100644 --- a/paramiko/pipe.py +++ b/paramiko/pipe.py @@ -67,7 +67,7 @@ class WindowsPipe (object): serv.bind(('127.0.0.1', 0)) serv.listen(1) - # need to save sockets in pipe_rsock/pipe_wsock so they don't get closed + # need to save sockets in _rsock/_wsock so they don't get closed self._rsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._rsock.connect(('127.0.0.1', serv.getsockname()[1])) diff --git a/paramiko/pkey.py b/paramiko/pkey.py index 79f56bc..75db8e5 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -20,15 +20,16 @@ Common API for all public keys. """ -import os, base64 +import base64 +import os from Crypto.Hash import MD5 from Crypto.Cipher import DES3 -from common import * -from message import Message -from ssh_exception import SSHException, PasswordRequiredException -import util +from paramiko.common import * +from paramiko import util +from paramiko.message import Message +from paramiko.ssh_exception import SSHException, PasswordRequiredException class PKey (object): diff --git a/paramiko/primes.py b/paramiko/primes.py index a6998cd..3677394 100644 --- a/paramiko/primes.py +++ b/paramiko/primes.py @@ -21,7 +21,8 @@ Utility functions for dealing with primes. """ from Crypto.Util import number -import util + +from paramiko import util def _generate_prime(bits, randpool): @@ -145,4 +146,3 @@ class ModulusPack (object): # now pick a random modulus of this bitsize n = _roll_random(self.randpool, len(self.pack[good])) return self.pack[good][n] - diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py index 7751b49..7e6b07e 100644 --- a/paramiko/rsakey.py +++ b/paramiko/rsakey.py @@ -24,12 +24,13 @@ from Crypto.PublicKey import RSA from Crypto.Hash import SHA, MD5 from Crypto.Cipher import DES3 -from common import * -from message import Message -from ber import BER, BERException -import util -from pkey import PKey -from ssh_exception import SSHException +from paramiko.common import * +from paramiko import util +from paramiko.message import Message +from paramiko.ber import BER, BERException +from paramiko.pkey import PKey +from paramiko.ssh_exception import SSHException + class RSAKey (PKey): """ @@ -161,4 +162,3 @@ class RSAKey (PKey): self.p = keylist[4] self.q = keylist[5] self.size = util.bit_length(self.n) - diff --git a/paramiko/server.py b/paramiko/server.py index 859ae6b..a0e3988 100644 --- a/paramiko/server.py +++ b/paramiko/server.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -23,8 +21,8 @@ L{ServerInterface} is an interface to override for server support. """ import threading -from common import * -import util +from paramiko.common import * +from paramiko import util class InteractiveQuery (object): diff --git a/paramiko/sftp.py b/paramiko/sftp.py index 78c204b..58d7103 100644 --- a/paramiko/sftp.py +++ b/paramiko/sftp.py @@ -16,11 +16,14 @@ # along with Paramiko; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -import struct, socket -from common import * -import util -from channel import Channel -from message import Message +import socket +import struct + +from paramiko.common import * +from paramiko import util +from paramiko.channel import Channel +from paramiko.message import Message + CMD_INIT, CMD_VERSION, CMD_OPEN, CMD_CLOSE, CMD_READ, CMD_WRITE, CMD_LSTAT, CMD_FSTAT, \ CMD_SETSTAT, CMD_FSETSTAT, CMD_OPENDIR, CMD_READDIR, CMD_REMOVE, CMD_MKDIR, \ diff --git a/paramiko/sftp_attr.py b/paramiko/sftp_attr.py index b2812c6..05ebcf7 100644 --- a/paramiko/sftp_attr.py +++ b/paramiko/sftp_attr.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -18,9 +16,10 @@ # along with Paramiko; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -import stat, time -from common import * -from sftp import * +import stat +import time +from paramiko.common import * +from paramiko.sftp import * class SFTPAttributes (object): diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 9efad31..06e402e 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -21,9 +21,9 @@ Client-mode SFTP support. """ import os -from sftp import * -from sftp_attr import SFTPAttributes -from sftp_file import SFTPFile +from paramiko.sftp import * +from paramiko.sftp_attr import SFTPAttributes +from paramiko.sftp_file import SFTPFile def _to_unicode(s): diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index 4fb0a4b..477aec1 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -20,10 +20,10 @@ L{SFTPFile} """ -from common import * -from sftp import * -from file import BufferedFile -from sftp_attr import SFTPAttributes +from paramiko.common import * +from paramiko.sftp import * +from paramiko.file import BufferedFile +from paramiko.sftp_attr import SFTPAttributes class SFTPFile (BufferedFile): diff --git a/paramiko/sftp_handle.py b/paramiko/sftp_handle.py index fc61596..e1d93e9 100644 --- a/paramiko/sftp_handle.py +++ b/paramiko/sftp_handle.py @@ -21,8 +21,9 @@ Abstraction of an SFTP file handle (for server mode). """ import os -from common import * -from sftp import * + +from paramiko.common import * +from paramiko.sftp import * class SFTPHandle (object): @@ -184,4 +185,4 @@ class SFTPHandle (object): self.__name = name -from sftp_server import SFTPServer +from paramiko.sftp_server import SFTPServer diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py index 13e05c0..9cc0550 100644 --- a/paramiko/sftp_server.py +++ b/paramiko/sftp_server.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -22,13 +20,15 @@ Server-mode SFTP support. """ -import os, errno +import os +import errno + from Crypto.Hash import MD5, SHA -from common import * -from server import SubsystemHandler -from sftp import * -from sftp_si import * -from sftp_attr import * +from paramiko.common import * +from paramiko.server import SubsystemHandler +from paramiko.sftp import * +from paramiko.sftp_si import * +from paramiko.sftp_attr import * # known hash algorithms for the "check-file" extension @@ -417,4 +417,4 @@ class SFTPServer (BaseSFTP, SubsystemHandler): self._send_status(request_number, SFTP_OP_UNSUPPORTED) -from sftp_handle import SFTPHandle +from paramiko.sftp_handle import SFTPHandle diff --git a/paramiko/sftp_si.py b/paramiko/sftp_si.py index 262cc72..16005d4 100644 --- a/paramiko/sftp_si.py +++ b/paramiko/sftp_si.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -23,8 +21,10 @@ L{SFTPServerInterface} is an interface to override for SFTP server support. """ import os -from common import * -from sftp import * + +from paramiko.common import * +from paramiko.sftp import * + class SFTPServerInterface (object): """ @@ -301,4 +301,3 @@ class SFTPServerInterface (object): @rtype: int """ return SFTP_OP_UNSUPPORTED - diff --git a/paramiko/ssh_exception.py b/paramiko/ssh_exception.py index 031623e..900d4a0 100644 --- a/paramiko/ssh_exception.py +++ b/paramiko/ssh_exception.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (C) 2003-2005 Robey Pointer # # This file is part of paramiko. @@ -29,12 +27,14 @@ class SSHException (Exception): """ pass + class PasswordRequiredException (SSHException): """ Exception raised when a password is needed to unlock a private key file. """ pass + class BadAuthenticationType (SSHException): """ Exception raised when an authentication type (like password) is used, but @@ -57,6 +57,7 @@ class BadAuthenticationType (SSHException): def __str__(self): return SSHException.__str__(self) + ' (allowed_types=%r)' % self.allowed_types + class PartialAuthentication (SSHException): """ An internal exception thrown in the case of partial authentication. diff --git a/paramiko/util.py b/paramiko/util.py index d0d2c0d..cf90033 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -16,14 +16,19 @@ # along with Paramiko; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -from __future__ import generators - """ Useful functions used by the rest of paramiko. """ -import sys, struct, traceback, threading -from common import * +from __future__ import generators + +import sys +import struct +import traceback +import threading + +from paramiko.common import * + # Change by RogerB - python < 2.3 doesn't have enumerate so we implement it if sys.version_info < (2,3): @@ -36,6 +41,7 @@ if sys.version_info < (2,3): yield (count, item) count += 1 + def inflate_long(s, always_positive=False): "turns a normalized byte string into a long-int (adapted from Crypto.Util.number)" out = 0L