fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
205 stars 78 forks source link

Python 3.x buffer usage? #7

Closed nickolas1969 closed 8 years ago

nickolas1969 commented 9 years ago

Having a Python 3.4 conversion issue that I can't seem to solve:

prompt = 'router#' interact.expect(prompt)

Throws:

Traceback (most recent call last): File "./ssh-expect.py", line 37, in interact.expect(prompt) File "/usr/lib64/python3.4/site-packages/paramikoe.py", line 130, in expect buffer = buffer.replace('\r', '') TypeError: 'str' does not support the buffer interface

Which I see a lot in other code I write where using .decode('UTF-8') and .encode('UTF-8') get's me though, but in this case I get.

File "/usr/lib64/python3.4/site-packages/paramikoe.py", line 116, in expect for re_string in re_strings File "/usr/lib64/python3.4/site-packages/paramikoe.py", line 117, in if re.match('.*\n' + re_string + '$', TypeError: Can't convert 'int' object to str implicitly

Is there a method for Python 3.x for this module? :-D

nickolas1969 commented 9 years ago

Got it working by modifying "/usr/lib64/python3.4/site-packages/paramikoe.py"

here is what I changed:

130: buffer = buffer.replace(b'\r', b'') # (Added the b's) 135: sys.stdout.write(buffer.decode()) # Added .decode() 139: self.current_output += buffer.decode() # Added the .decode()

There are more spots that use the Python 2.x format, but my Python Programs have not hit them, so I won't change anything further until they do.

So what ever method pip/github installer used to build both my python 2.7 and 3.4 target versions, 3.4 did not catch this?

fgimian commented 9 years ago

Thanks for all your help. I'll take into account everything you mentioned and look at getting a Python 3.x compatible out soon.

Cheers Fotis

dholm commented 8 years ago

Any progress on this? :)