Skip to content

Commit

Permalink
Bug fix release
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas Poulopoulos committed Jul 5, 2016
1 parent e09d370 commit 800222d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Device handlers are easy to implement and prove to be futureproof.
* Many bug and performance fixes

### Contributors
* v0.5.1: [Nitin Kumar](https://github.com/vnitinv), [Kristian Larsson](https://github.com/plajjan), [palashgupta](https://github.com/palashgupta), [Jonathan Provost](https://github.com/JoProvost), [Jainpriyal](https://github.com/Jainpriyal), [sharang](https://github.com/sharang), [pseguel](https://github.com/pseguel), [nnakamot](https://github.com/nnakamot), [Алексей Пастухов](https://github.com/p-alik), [Christian Giese](https://github.com/GIC-de), [Peipei Guo](https://github.com/peipeiguo), [Time Warner Cable Openstack Team](https://github.com/twc-openstack)
* v0.5.2: [Nitin Kumar](https://github.com/vnitinv), [Kristian Larsson](https://github.com/plajjan), [palashgupta](https://github.com/palashgupta), [Jonathan Provost](https://github.com/JoProvost), [Jainpriyal](https://github.com/Jainpriyal), [sharang](https://github.com/sharang), [pseguel](https://github.com/pseguel), [nnakamot](https://github.com/nnakamot), [Алексей Пастухов](https://github.com/p-alik), [Christian Giese](https://github.com/GIC-de), [Peipei Guo](https://github.com/peipeiguo), [Time Warner Cable Openstack Team](https://github.com/twc-openstack)
* v0.4.7: [Einar Nilsen-Nygaard](https://github.com/einarnn), [Vaibhav Bajpai](https://github.com/vbajpai), Norio Nakamoto
* v0.4.6: [Nitin Kumar](https://github.com/vnitinv), [Carl Moberg](https://github.com/cmoberg), [Stavros Kroustouris](https://github.com/kroustou)
* v0.4.5: [Sebastian Wiesinger](https://github.com/sebastianw), [Vincent Bernat](https://github.com/vincentbernat), [Matthew Stone](https://github.com/bigmstone), [Nitin Kumar](https://github.com/vnitinv)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ Device handlers are easy to implement and prove to be futureproof.

* Python 3 support
* Bug fixes
* Performance improvements


### Contributors
* v0.5.1: [Nitin Kumar](https://github.com/vnitinv), [Kristian Larsson](https://github.com/plajjan), [palashgupta](https://github.com/palashgupta), [Jonathan Provost](https://github.com/JoProvost), [Jainpriyal](https://github.com/Jainpriyal), [sharang](https://github.com/sharang), [pseguel](https://github.com/pseguel), [nnakamot](https://github.com/nnakamot), [Алексей Пастухов](https://github.com/p-alik), [Christian Giese](https://github.com/GIC-de), [Peipei Guo](https://github.com/peipeiguo), [Time Warner Cable Openstack Team](https://github.com/twc-openstack)
* v0.5.2: [Nitin Kumar](https://github.com/vnitinv), [Kristian Larsson](https://github.com/plajjan), [palashgupta](https://github.com/palashgupta), [Jonathan Provost](https://github.com/JoProvost), [Jainpriyal](https://github.com/Jainpriyal), [sharang](https://github.com/sharang), [pseguel](https://github.com/pseguel), [nnakamot](https://github.com/nnakamot), [Алексей Пастухов](https://github.com/p-alik), [Christian Giese](https://github.com/GIC-de), [Peipei Guo](https://github.com/peipeiguo), [Time Warner Cable Openstack Team](https://github.com/twc-openstack)
* v0.4.7: [Einar Nilsen-Nygaard](https://github.com/einarnn), [Vaibhav Bajpai](https://github.com/vbajpai), Norio Nakamoto
* v0.4.6: [Nitin Kumar](https://github.com/vnitinv), [Carl Moberg](https://github.com/cmoberg), [Stavros Kroustouris](https://github.com/kroustou)
* v0.4.5: [Sebastian Wiesinger](https://github.com/sebastianw), [Vincent Bernat](https://github.com/vincentbernat), [Matthew Stone](https://github.com/bigmstone), [Nitin Kumar](https://github.com/vnitinv)
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Supported device handlers
Changes \| brief
~~~~~~~~~~~~~~~~

**v0.5.1**
**v0.5.2**

- Add support for Python 3
- Improve Junos ioproc performance
Expand Down Expand Up @@ -165,7 +165,7 @@ Changes \| brief
Acknowledgements
~~~~~~~~~~~~~~~~

- v0.5.1: `Nitin Kumar`_, `Kristian Larsson`_, `palashgupta`_,
- v0.5.2: `Nitin Kumar`_, `Kristian Larsson`_, `palashgupta`_,
`Jonathan Provost`_, `Jainpriyal`_, `sharang`_, `pseguel`_,
`nnakamot`_, `Алексей Пастухов`_, `Christian Giese`_, `Peipei Guo`_,
`Time Warner Cable Openstack Team`_
Expand Down
2 changes: 1 addition & 1 deletion ncclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = (0,5,1)
__version__ = (0,5,2)

import sys

Expand Down
82 changes: 28 additions & 54 deletions ncclient/transport/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import socket
import getpass
from binascii import hexlify
from six import StringIO
from io import BytesIO
from lxml import etree
from select import select

Expand All @@ -37,6 +35,7 @@
BUF_SIZE = 4096
# v1.0: RFC 4742
MSG_DELIM = "]]>]]>"
MSG_DELIM_LEN = len(MSG_DELIM)
# v1.1: RFC 6242
END_DELIM = '\n##\n'

Expand Down Expand Up @@ -69,6 +68,13 @@ def textify(buf):
def textify(buf):
return buf.decode('UTF-8')

if sys.version < '3':
from six import StringIO
else:
from io import BytesIO as StringIO



class SSHSession(Session):

"Implements a :rfc:`4742` NETCONF session over SSH."
Expand All @@ -82,10 +88,7 @@ def __init__(self, device_handler):
self._channel = None
self._channel_id = None
self._channel_name = None
if sys.version<'3':
self._buffer = StringIO() # for incoming data
else:
self._buffer = BytesIO() # for incoming data
self._buffer = StringIO()
# parsing-related, see _parse()
self._device_handler = device_handler
self._parsing_state10 = 0
Expand All @@ -106,58 +109,29 @@ def _parse10(self):

"""Messages are delimited by MSG_DELIM. The buffer could have grown by
a maximum of BUF_SIZE bytes everytime this method is called. Retains
state across method calls and if a byte has been read it will not be
state across method calls and if a chunk has been read it will not be
considered again."""

logger.debug("parsing netconf v1.0")
delim = MSG_DELIM
n = len(delim)
expect = self._parsing_state10
buf = self._buffer
buf.seek(self._parsing_pos10)
while True:
x = buf.read(1)
if isinstance(x, bytes):
x = x.decode('UTF-8')
if not x: # done reading
break
elif x == delim[expect]: # what we expected
expect += 1 # expect the next delim char
if MSG_DELIM in buf.read().decode('UTF-8'):
buf.seek(0)
msg, _, remaining = buf.read().decode('UTF-8').partition(MSG_DELIM)
msg = msg.strip()
if sys.version < '3':
self._dispatch_message(msg.encode())
else:
expect = 0
continue
# loop till last delim char expected, break if other char encountered
for i in range(expect, n):
x = buf.read(1)
if isinstance(x, bytes):
x = x.decode('UTF-8')
if not x: # done reading
break
if x == delim[expect]: # what we expected
expect += 1 # expect the next delim char
else:
expect = 0 # reset
break
else: # if we didn't break out of the loop, full delim was parsed
msg_till = buf.tell() - n
buf.seek(0)
logger.debug('parsed new message')
if sys.version < '3':
self._dispatch_message(buf.read(msg_till).strip())
buf.seek(n, os.SEEK_CUR)
rest = buf.read()
buf = StringIO()
else:
self._dispatch_message(buf.read(msg_till).strip().decode('UTF-8'))
buf.seek(n, os.SEEK_CUR)
rest = buf.read()
buf = BytesIO()
buf.write(rest)
buf.seek(0)
expect = 0
self._buffer = buf
self._parsing_state10 = expect
self._parsing_pos10 = self._buffer.tell()
self._dispatch_message(msg)
# create new buffer which contains remaining of old buffer
self._buffer = StringIO()
self._buffer.write(remaining.encode())
self._parsing_pos10 = 0
else:
# handle case that MSG_DELIM is split over two chunks
self._parsing_pos10 = buf.tell() - MSG_DELIM_LEN
if self._parsing_pos10 < 0:
self._parsing_pos10 = 0

def _parse11(self):
logger.debug("parsing netconf v1.1")
Expand Down Expand Up @@ -236,7 +210,7 @@ def _parse11(self):
state = inbetween
chunk = b''.join(chunk_list)
message_list.append(textify(chunk))
chunk_list = [] # Reset chunk_list
chunk_list = [] # Reset chunk_list
logger.debug('parsed new chunk: %s'%(chunk))
elif state == inbetween:
if inendpos == 0:
Expand Down Expand Up @@ -324,7 +298,7 @@ def close(self):
self._transport.close()
self._channel = None
self._connected = False


# REMEMBER to update transport.rst if sig. changes, since it is hardcoded there
def connect(self, host, port=830, timeout=None, unknown_host_cb=default_unknown_host_cb,
Expand Down

0 comments on commit 800222d

Please sign in to comment.