Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have bug with chinese #59

Closed
ibuler opened this issue Oct 27, 2016 · 8 comments
Closed

Have bug with chinese #59

ibuler opened this issue Oct 27, 2016 · 8 comments

Comments

@ibuler
Copy link

ibuler commented Oct 27, 2016

When output mix up with chinese and english will trigger a bug .

  File "/Users/guang/.virtualenvs/python2.7/lib/python2.7/site-packages/pyte/streams.py", line 378, in feed
    return super(ByteStream, self).feed(chars)
  File "/Users/guang/.virtualenvs/python2.7/lib/python2.7/site-packages/pyte/streams.py", line 166, in feed
    send(char)
  File "/Users/guang/.virtualenvs/python2.7/lib/python2.7/site-packages/pyte/streams.py", line 318, in _parser_fsm
    dispatch("draw", char)
  File "/Users/guang/.virtualenvs/python2.7/lib/python2.7/site-packages/pyte/streams.py", line 215, in dispatch
    handler(*args, **kwargs)
  File "/Users/guang/.virtualenvs/python2.7/lib/python2.7/site-packages/pyte/screens.py", line 448, in draw
    line[self.cursor.x + 1] = self.cursor.attrs._replace(data=" ")
IndexError: list assignment index out of range

image

pyte version 0.5.2

@superbobry
Copy link
Collaborator

superbobry commented Oct 27, 2016

This is a nasty one to track down. Could you attach the file reproducing the bug? I.e. I'd like to do stream.feed(open(...).read()) and see the error message.

@ibuler
Copy link
Author

ibuler commented Oct 27, 2016

>>> s = '\r\n1.log \x1b[0m\x1b[01;31mincubator-guacamole-client-0.9.9.tar.gz\x1b[0m tasks.pyc\r\n44.txt \x1b[01;34mincubator-guacamole-server-0.9.9\x1b[0m \x1b[01;34mtermrecord\x1b[0m\r\n\x1b[01;34ma\x1b[0m \x1b[01;31mincubator-guacamole-server-0.9.9.tar.gz\x1b[0m \x1b[01;34mTermRecord\x1b[0m\r\nab.sh input.log \x1b[01;34mTermRecord-1.2.4\x1b[0m\r\nadmin_121_10_170204.log install.log \x1b[01;31mTermRecord-1.2.4.tar.gz\x1b[0m\r\nadmin_121_10_170204.time install.log.syslog test.html\r\na.log \x1b[01;31mjdk1.7.0_79.tar.gz\x1b[0m \x1b[01;34mtestmis\x1b[0m\r\nanaconda-ks.cfg jumpserver.sql test_monitor.py\r\n\x1b[01;34mansible\x1b[0m Jumpserver\xe9\x9c\x80\xe6\xb1\x82\xe5\xaf\xbc\xe5\x9b\xbe.xmind test.o\r\n\x1b[01;31mansible-1.9.4-0.2.rc2.tar.gz\x1b[0m \x1b[01;34mlinux-rdp-gateway\x1b[0m test.py\r\n\x1b[01;34mansible-1.9.4-1\x1b[0m \x1b[01;34mlogs\x1b[0m test.sh\r\n\x1b[01;31mansible-1.9.4-1.tar.gz\x1b[0m ls test_tail.py\r\n\x1b[01;31mansible.tar.gz\x1b[0m \x1b[01;34mmis\x1b[0m test_tty.py\r\nansible_test.py \x1b[01;34mmysite\x1b[0m test.txt\r\n\x1b[01;31mapache-maven-3.3.9-bin.tar.gz\x1b[0m new_task.py text1.py\r\na.py new_worker.py text.py\r\ndjangobook2.0.CHM.20151201040715 \x1b[01;31mopenvpn.tar.gz\x1b[0m \x1b[01;34mtmp\x1b[0m\r\n\x1b[01;34mdjango-socketio\x1b[0m private.pem \x1b[01;31mtomcat-7.0.64-1.el6.x86_64.rpm\x1b[0m\r\nDjango\xe8\xaf\xbe\xe7\xa8\x8b.docx public.pem useradd.yaml\r\n\x1b[01;34mdwebsocket\x1b[0m \x1b[01;34mpublish\x1b[0m \x1b[01;34mutil-linux-2.27.1\x1b[0m\r\nemit_log_direct.py \x1b[01;34mpython2.6\x1b[0m \x1b[01;31mutil-linux-2.27.1.tar.gz\x1b[0m\r\nemit_log.py \x1b[01;34mPython-3.5.1\x1b[0m watch.py\r\ngc.txt \x1b[01;31mPython-3.5.1.tgz\x1b[0m \x1b[01;34mwebTerminal\x1b[0m\r\ngen_key.py \x1b[01;34mpyxterm\x1b[0m \x1b[01;34mWeiXin-Private-API\x1b[0m\r\n\x1b[01;34mgfwlist\x1b[0m queues.py weixin.py\r\ngitlog_test.sh \x1b[01;31mrabbitmq-server-3.6.3-1.noarch.rpm\x1b[0m weixin.py.save\r\n\x1b[01;34mguacamole-server-0.9.8\x1b[0m receive_logs_direct.py \x1b[01;34mwssh\x1b[0m\r\n\x1b[01;31mguacamole-server-0.9.8.tar.gz\x1b[0m receive_logs.py zzjumpserver.sh\r\nhello world rpc_client.py \x1b[01;35m\xe6\x97\xa0\xe6\xa0\x87\xe9\xa2\x98.png\x1b[0m\r\n\x1b[01;34mincubator-guacamole-client-0.9.9\x1b[0m rpc_server.py\r\n\x1b[m\x1b]0;root@localhost:~/old\x07[root@localhost old]#'

>>> stream.feed(s)

`/Users/guang/.virtualenvs/python2.7/lib/python2.7/site-packages/pyte/screens.pyc in draw(self, char)
446 if char_width > 1:
447 # Add a stub after a two-cell character. See issue #9 on GitHub.
--> 448 line[self.cursor.x + 1] = self.cursor.attrs._replace(data=" ")
449
450 # .. note:: We can't use :meth: cursor_forward(), because that

IndexError: list assignment index out of range`

I save to a file, when I stream.feed(open(...).read()), It's well .

I see content is different will terminal, less some control char

1.log incubator-guacamole-client-0.9.9.tar.gz tasks.pyc\n44.txt incubator-guacamole-server-0.9.9 termrecord\na incubator-guacamole-server-0.9.9.tar.gz TermRecord\nab.sh input.log TermRecord-1.2.4\nadmin_121_10_170204.log install.log TermRecord-1.2.4.tar.gz\nadmin_121_10_170204.time install.log.syslog test.html\na.log jdk1.7.0_79.tar.gz testmis\nanaconda-ks.cfg jumpserver.sql test_monitor.py\nansible Jumpserver\xe9\x9c\x80\xe6\xb1\x82\xe5\xaf\xbc\xe5\x9b\xbe.xmind test.o\nansible-1.9.4-0.2.rc2.tar.gz linux-rdp-gateway test.py\nansible-1.9.4-1 logs test.sh\nansible-1.9.4-1.tar.gz ls test_tail.py\nansible.tar.gz mis test_tty.py\nansible_test.py mysite test.txt\napache-maven-3.3.9-bin.tar.gz new_task.py text1.py\na.py new_worker.py text.py\ndjangobook2.0.CHM.20151201040715 openvpn.tar.gz tmp\ndjango-socketio private.pem tomcat-7.0.64-1.el6.x86_64.rpm\nDjango\xe8\xaf\xbe\xe7\xa8\x8b.docx public.pem useradd.yaml\ndwebsocket publish util-linux-2.27.1\nemit_log_direct.py python2.6 util-linux-2.27.1.tar.gz\nemit_log.py Python-3.5.1 watch.py\ngc.txt Python-3.5.1.tgz webTerminal\ngen_key.py pyxterm WeiXin-Private-API\ngfwlist queues.py weixin.py\ngitlog_test.sh rabbitmq-server-3.6.3-1.noarch.rpm weixin.py.save\nguacamole-server-0.9.8 receive_logs_direct.py wssh\nguacamole-server-0.9.8.tar.gz receive_logs.py zzjumpserver.sh\nhello world rpc_client.py \xe6\x97\xa0\xe6\xa0\x87\xe9\xa2\x98.png\n

@ibuler
Copy link
Author

ibuler commented Oct 27, 2016

May be I know the reason, Screen object size is not equal my terminal size.

I set equal to my terminal size, It's Ok

@superbobry
Copy link
Collaborator

Ah, right. That could be the cause.

Make sure the COLUMNS and LINES env. variables match the Screen dimensions.

@ibuler
Copy link
Author

ibuler commented Oct 27, 2016

Ok, Thank you, It's a good project.

https://github.com/jumpserver/jumpserver
This is my project that use pyte to parser command user input.

Because in terminal, user input is not the full command, the server return is.
But server return will have some control char.

ifconfi[backspace button]ig will be ifconfi\x08\x1b[Kig

I want to get ifconfig. So I use pyte do it.

https://github.com/jumpserver/jumpserver/blob/master/connect.py#L138-L163

Thank you again

@superbobry
Copy link
Collaborator

Glad pyte is useful!

By the way, you can get rendered screen in Screen.display instead of manually iterating over Screen.buffer.

@wufeiqun
Copy link

遇到了类似的问题, 谷歌搜到这里了

Exception in thread Thread-568:
Traceback (most recent call last):
  File "/home/jumpserver/python3/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/jumpserver/python3/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/jumpserver/coco/coco/app.py", line 69, in process_request
    InteractiveServer(self).run()
  File "/home/jumpserver/coco/coco/interactive.py", line 290, in run
    self.dispatch()
  File "/home/jumpserver/coco/coco/interactive.py", line 125, in dispatch
    return self.search_and_proxy(option=option, from_result=twice)
  File "/home/jumpserver/coco/coco/interactive.py", line 274, in search_and_proxy
    self.dispatch(twice=True)
  File "/home/jumpserver/coco/coco/interactive.py", line 125, in dispatch
    return self.search_and_proxy(option=option, from_result=twice)
  File "/home/jumpserver/coco/coco/interactive.py", line 264, in search_and_proxy
    self.return_to_proxy(asset, system_user)
  File "/home/jumpserver/coco/coco/interactive.py", line 281, in return_to_proxy
    proxy_server.proxy()
  File "/home/jumpserver/coco/coco/proxy.py", line 162, in proxy
    self.get_output()
  File "/home/jumpserver/coco/coco/proxy.py", line 67, in get_output
    self.output = parser.parse_output(b''.join(self.output_data))
  File "/home/jumpserver/python3/lib/python3.6/site-packages/jms/utils.py", line 188, in parse_output
    self.stream.feed(data)
  File "/home/jumpserver/python3/lib/python3.6/site-packages/pyte/streams.py", line 378, in feed
    return super(ByteStream, self).feed(chars)
  File "/home/jumpserver/python3/lib/python3.6/site-packages/pyte/streams.py", line 166, in feed
    send(char)
  File "/home/jumpserver/python3/lib/python3.6/site-packages/pyte/streams.py", line 318, in _parser_fsm
    dispatch("draw", char)
  File "/home/jumpserver/python3/lib/python3.6/site-packages/pyte/streams.py", line 215, in dispatch
    handler(*args, **kwargs)
  File "/home/jumpserver/python3/lib/python3.6/site-packages/pyte/screens.py", line 448, in draw
    line[self.cursor.x + 1] = self.cursor.attrs._replace(data=" ")
IndexError: list assignment index out of range

@superbobry
Copy link
Collaborator

Hi @hellorocky, could you give a bit more context? Have you checked the env. variables mentioned above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants