944,201 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1543
  • Python RSS
Nov 9th, 2007
0

line drawing characters not displayed properly - python unicode

Expand Post »
hello,

I am very new to python scripting and would require some help. Thers a product
called Ajaxterm which makes use of python scripts and Ajax that I am using. It's a web based unix terminal emulator. I have set this up to work correctly. But there are some unicode related issues thats coming when using this product.

Let me elaborate much on this product for better understanding. this product makes python to interact with the Unix os, takes the output, generates an xml and displays it on a webpage by making use of ajax. so, to use this product we need to run a python file which acts as the server and a user can use http//myserver:myport from a client machine and access the unix box.

This is what I am trying to do: After logging in with my user id, I am trying to do a database login in my unix box. when i use putty, the login screen comes up as the pic1 in the attachment (Expected). but, when i use the terminal emulator (ajaxterm), it comes up like in the pics (Actual).

I have pinpointed to the code where this happens. the code is:

Python Syntax (Toggle Plain Text)
  1. t=(self.proc[fd]['term'])
  2. str= os.read(fd,65536)
  3. t.write(str)

As far as i understood, 't' makes an instance of the current terminal, 'str' contains the reply that the python script takes from the unix os to pass it to the web terminal. till now, 'str' would still give me the wrong line drawing character (checked by printing str on the console)
but, I changed the code for 'str' to the following

Python Syntax (Toggle Plain Text)
  1. str= unicode(os.read(fd,65536), "UTF-8")

and could see that 'str' prints the proper unicode line drawing characters as expected on the console.

the line 3 in the original code makes the 'str' to write to the webterminal. but, when i print 't'
on the console, it does still have the incorrect line drawing characters ('t' finally gets printed on the web console).

What am i doing wrong? I assume that 'str' automatically gets changed to the encoding that 't' is using when 't.write(str)' is encountered. I tried doing a

Python Syntax (Toggle Plain Text)
  1. reload(sys)
  2. sys.setdefaultencoding('UTF-8')
in the python code and i could see that prining the defaultencoding is giving me 'UTF-8'.

I am not sure what I am doing wrong. maybe i am not understanding what exactly
the lines
t=(self.proc[fd]['term']) and t.write(str) does or how i could manipulate it to make it work as expected. I tried to seach on this on the web, but didnt get much of help.

Sorry for the long description, but I'd really appreciate if anyone could help me on this.

Thank you.
Attached Thumbnails
Click image for larger version

Name:	defect.JPG
Views:	10
Size:	35.1 KB
ID:	4415  
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pythonhelp is offline Offline
2 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Python GUI to configure Cisco device
Next Thread in Python Forum Timeline: Need help getting text to display in a graphics window





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC