Skip to content

Commit

Permalink
Merge branch '2.1' into 910-int
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Jun 9, 2017
2 parents 4526052 + 7fe4373 commit ddf9a1a
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 152 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install:
# Self-install for setup.py-driven deps
- pip install -e .
# Dev (doc/test running) requirements
- pip install coveralls # For coveralls.io specifically
- pip install codecov # For codecov specifically
- pip install -r dev-requirements.txt
script:
# Main tests, w/ coverage!
Expand All @@ -33,4 +33,4 @@ notifications:
on_failure: change
email: false
after_success:
- coveralls
- codecov
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Paramiko
.. image:: https://travis-ci.org/paramiko/paramiko.svg?branch=master
:target: https://travis-ci.org/paramiko/paramiko
.. image:: https://coveralls.io/repos/paramiko/paramiko/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/paramiko/paramiko?branch=master
.. image:: https://codecov.io/gh/paramiko/paramiko/branch/master/graph/badge.svg
:target: https://codecov.io/gh/paramiko/paramiko

:Paramiko: Python SSH module
:Copyright: Copyright (c) 2003-2009 Robey Pointer <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
1 change: 0 additions & 1 deletion paramiko/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from paramiko.ecdsakey import ECDSAKey
from paramiko.hostkeys import HostKeys
from paramiko.py3compat import string_types
from paramiko.resource import ResourceManager
from paramiko.rsakey import RSAKey
from paramiko.ssh_exception import (
SSHException, BadHostKeyException, NoValidConnectionsError
Expand Down
22 changes: 11 additions & 11 deletions paramiko/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
Common constants and global variables.
"""
import logging
from paramiko.py3compat import (
byte_chr, PY2, bytes_types, string_types, b, long,
)
from paramiko.py3compat import byte_chr, PY2, bytes_types, text_type, long

MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, \
MSG_SERVICE_REQUEST, MSG_SERVICE_ACCEPT = range(1, 7)
Expand Down Expand Up @@ -163,14 +161,16 @@


def asbytes(s):
if not isinstance(s, bytes_types):
if isinstance(s, string_types):
s = b(s)
else:
try:
s = s.asbytes()
except Exception:
raise Exception('Unknown type')
"""Coerce to bytes if possible or return unchanged."""
if isinstance(s, bytes_types):
return s
if isinstance(s, text_type):
# Accept text and encode as utf-8 for compatibility only.
return s.encode("utf-8")
asbytes = getattr(s, "asbytes", None)
if asbytes is not None:
return asbytes()
# May be an object that implements the buffer api, let callers handle.
return s


Expand Down
6 changes: 4 additions & 2 deletions paramiko/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from paramiko.common import (
linefeed_byte_value, crlf, cr_byte, linefeed_byte, cr_byte_value,
)
from paramiko.py3compat import BytesIO, PY2, u, b, bytes_types
from paramiko.py3compat import BytesIO, PY2, u, bytes_types, text_type

from paramiko.util import ClosingContextManager

Expand Down Expand Up @@ -391,7 +391,9 @@ def write(self, data):
:param data: ``str``/``bytes`` data to write
"""
data = b(data)
if isinstance(data, text_type):
# Accept text and encode as utf-8 for compatibility only.
data = data.encode('utf-8')
if self._closed:
raise IOError('File is closed')
if not (self._flags & self.FLAG_WRITE):
Expand Down
7 changes: 1 addition & 6 deletions paramiko/hostkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@
import binascii
import os

from collections import MutableMapping
from hashlib import sha1
from hmac import HMAC

from paramiko.py3compat import b, u, encodebytes, decodebytes

try:
from collections import MutableMapping
except ImportError:
# noinspection PyUnresolvedReferences
from UserDict import DictMixin as MutableMapping

from paramiko.dsskey import DSSKey
from paramiko.rsakey import RSAKey
from paramiko.util import get_logger, constant_time_bytes_eq
Expand Down
2 changes: 1 addition & 1 deletion paramiko/kex_gss.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import os
from hashlib import sha1

from paramiko.common import * # noqa
from paramiko.common import DEBUG, max_byte, zero_byte
from paramiko import util
from paramiko.message import Message
from paramiko.py3compat import byte_chr, byte_mask, byte_ord
Expand Down
1 change: 0 additions & 1 deletion paramiko/primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from paramiko import util
from paramiko.py3compat import byte_mask, long
from paramiko.ssh_exception import SSHException
from paramiko.common import * # noqa


def _roll_random(n):
Expand Down
11 changes: 2 additions & 9 deletions paramiko/py3compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,8 @@ def b2s(s):
return s


try:
import cStringIO

StringIO = cStringIO.StringIO # NOQA
except ImportError:
import StringIO

StringIO = StringIO.StringIO # NOQA

import cStringIO
StringIO = cStringIO.StringIO
BytesIO = StringIO


Expand Down
71 changes: 0 additions & 71 deletions paramiko/resource.py

This file was deleted.

11 changes: 4 additions & 7 deletions paramiko/sftp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
from paramiko.channel import Channel
from paramiko.message import Message
from paramiko.common import INFO, DEBUG, o777
from paramiko.py3compat import (
bytestring, b, u, long, string_types, bytes_types,
)
from paramiko.py3compat import bytestring, b, u, long
from paramiko.sftp import (
BaseSFTP, CMD_OPENDIR, CMD_HANDLE, SFTPError, CMD_READDIR, CMD_NAME,
CMD_CLOSE, SFTP_FLAG_READ, SFTP_FLAG_WRITE, SFTP_FLAG_CREATE,
Expand Down Expand Up @@ -758,13 +756,12 @@ def _async_request(self, fileobj, t, *arg):
msg.add_int64(item)
elif isinstance(item, int):
msg.add_int(item)
elif isinstance(item, (string_types, bytes_types)):
msg.add_string(item)
elif isinstance(item, SFTPAttributes):
item._pack(msg)
else:
raise Exception(
'unknown type for %r type %r' % (item, type(item)))
# For all other types, rely on as_string() to either coerce
# to bytes before writing or raise a suitable exception.
msg.add_string(item)
num = self.request_number
self._expecting[num] = fileobj
self.request_number += 1
Expand Down
18 changes: 4 additions & 14 deletions paramiko/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class Transport(threading.Thread, ClosingContextManager):
'aes192-ctr',
'aes256-ctr',
'aes128-cbc',
'blowfish-cbc',
'aes192-cbc',
'aes256-cbc',
'blowfish-cbc',
'3des-cbc',
)
_preferred_macs = (
Expand Down Expand Up @@ -277,7 +277,6 @@ def __init__(self,
arguments.
"""
self.active = False
self._sshclient = None

if isinstance(sock, string_types):
# convert "host:port" into (host, port)
Expand Down Expand Up @@ -311,14 +310,9 @@ def __init__(self,
threading.Thread.__init__(self)
self.setDaemon(True)
self.sock = sock
# Python < 2.3 doesn't have the settimeout method - RogerB
try:
# we set the timeout so we can check self.active periodically to
# see if we should bail. socket.timeout exception is never
# propagated.
self.sock.settimeout(self._active_check_timeout)
except AttributeError:
pass
# we set the timeout so we can check self.active periodically to
# see if we should bail. socket.timeout exception is never propagated.
self.sock.settimeout(self._active_check_timeout)

# negotiated crypto parameters
self.packetizer = Packetizer(sock)
Expand Down Expand Up @@ -651,9 +645,6 @@ def load_server_moduli(filename=None):
Transport._modulus_pack = None
return False

def set_sshclient(self, sshclient):
self._sshclient = sshclient

def close(self):
"""
Close this session, and any open channels that are tied to it.
Expand All @@ -664,7 +655,6 @@ def close(self):
for chan in list(self._channels.values()):
chan._unlink()
self.sock.close()
self._sshclient = None

def get_remote_server_key(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion paramiko/win_pageant.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import ctypes.wintypes
import platform
import struct
from paramiko.util import * # noqa
from paramiko.common import zero_byte
from paramiko.py3compat import b

try:
Expand Down
27 changes: 22 additions & 5 deletions sites/www/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ Changelog
=========

* :bug:`865` SSHClient requests the type of host key it has (e.g. from
known_hosts) and does not consider a different type to be a "Missing"
host key. This fixes a common case where an ecdsa key is in known_hosts and
the server also has an rsa host key. Thanks to Pierce Lopez.
known_hosts) and does not consider a different type to be a "Missing" host
key. This fixes a common case where an ECDSA key is in known_hosts and the
server also has an RSA host key. Thanks to Pierce Lopez.
* :support:`906 (1.18+)` Clean up a handful of outdated imports and related
tweaks. Thanks to Pierce Lopez.
* :bug:`984` Enhance default cipher preference order such that
``aes(192|256)-cbc`` are preferred over ``blowfish-cbc``. Thanks to Alex
Gaynor.
* :bug:`971 (1.17+)` Allow any type implementing the buffer API to be used with
`BufferedFile <paramiko.file.BufferedFile>`, `Channel
<paramiko.channel.Channel>`, and `SFTPFile <paramiko.sftp_file.SFTPFile>`.
This resolves a regression introduced in 1.13 with the Python 3 porting
changes, when using types such as ``memoryview``. Credit: Martin Packman.
* :bug:`741` (also :issue:`809`, :issue:`772`; all via :issue:`912`) Writing
encrypted/password-protected private key files was silently broken since 2.0
due to an incorrect API call; this has been fixed.
Expand All @@ -16,6 +26,9 @@ Changelog

Thanks to ``@virlos`` for the original report, Chris Harris and ``@ibuler``
for initial draft PRs, and ``@jhgorrell`` for the final patch.
* :support:`956 (1.17+)` Switch code coverage service from coveralls.io to
codecov.io (& then disable the latter's auto-comments.) Thanks to Nikolai
Røed Kristiansen for the patch.
* :bug:`983` Move ``sha1`` above the now-arguably-broken ``md5`` in the list of
preferred MAC algorithms, as an incremental security improvement for users
whose target systems offer both. Credit: Pierce Lopez.
Expand All @@ -40,8 +53,12 @@ Changelog
(i.e. passes the maintainer's preferred `flake8 <http://flake8.pycqa.org/>`_
configuration) and add a ``flake8`` step to the Travis config. Big thanks to
Dorian Pula!
* :bug:`683` Make ``util.log_to_file`` append instead of replace. Thanks
to ``@vlcinsky`` for the report.
* :bug:`949 (1.17+)` SSHClient and Transport could cause a memory leak if
there's a connection problem or protocol error, even if ``Transport.close()``
is called. Thanks Kyle Agronick for the discovery and investigation, and
Pierce Lopez for assistance.
* :bug:`683 (1.17+)` Make ``util.log_to_file`` append instead of replace.
Thanks to ``@vlcinsky`` for the report.
* :release:`2.1.2 <2017-02-20>`
* :release:`2.0.5 <2017-02-20>`
* :release:`1.18.2 <2017-02-20>`
Expand Down
36 changes: 36 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2017 Martin Packman <[email protected]>
#
# This file is part of paramiko.
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

"""Base classes and helpers for testing paramiko."""

import unittest

from paramiko.py3compat import (
builtins,
)


def skipUnlessBuiltin(name):
"""Skip decorated test if builtin name does not exist."""
if getattr(builtins, name, None) is None:
skip = getattr(unittest, "skip", None)
if skip is None:
# Python 2.6 pseudo-skip
return lambda func: None
return skip("No builtin " + repr(name))
return lambda func: func
Loading

0 comments on commit ddf9a1a

Please sign in to comment.