Date: Mon, 22 Oct 2007 02:28:12 GMT From: Sunry Chen <sunrychen@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/117388: chinese/pyDict has encode setting problem, and can't run in real console Message-ID: <200710220228.l9M2SC36030349@www.freebsd.org> Resent-Message-ID: <200710220230.l9M2U3wE051127@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 117388 >Category: ports >Synopsis: chinese/pyDict has encode setting problem, and can't run in real console >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Oct 22 02:30:03 UTC 2007 >Closed-Date: >Last-Modified: >Originator: Sunry Chen >Release: FreeBSD 6.2-STABLE >Organization: Shenzhen Institute of Technology >Environment: FreeBSD www.525183.com 6.2-STABLE FreeBSD 6.2-STABLE #8: Tue Sep 18 23:01:05 CST 2007 hplc@www.525183.com:/usr/obj/usr/src/sys/MYKERNEL i386 >Description: Run pydict in console or in X window's xterm, it generates such error: File "/usr/local/bin/pydict", line 332 SyntaxError: Non-ASCII character '\xa7' in file /usr/local/bin/pydict on line 33 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for de tails This is caused by source encoding problem. After solving this problem, it runs ok in X, but in real console it says: Traceback (most recent call last): File "/usr/local/bin/pydict", line 326, in <module> from gtk import * File "/usr/local/lib/python2.5/site-packages/gtk-1.2/gtk.py", line 33, in <mod ule> _gtk.gtk_init() RuntimeError: cannot open display This is because in real console there's no DISPLAY, while the code in line 326 or some others want to initialize the DISPLAY. >How-To-Repeat: Fresh installed chinese/pyDict, run pydict in console, not in X window's term! >Fix: 1. Add source encoding big5 for pydict source. 2. Adjust pydict python source code, add a judge statement not to import gtk or any other source which affecting running it in real console mode. Patch attached with submission follows: --- pydict.orig 2007-10-22 10:03:06.000000000 +0800 +++ pydict 2007-10-22 10:09:37.000000000 +0800 @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- encoding: big5 -*- +# -*- coding: big5 -*- #------------------------------------------------- # this is a program that utilize the library of xdict. # Made by Daniel Gau <r90057@im.ntu.edu.tw> @@ -323,16 +323,17 @@ """Get the word this object describes.""" return self.word -from gtk import * -from GDK import * +prop = [" "," "," ","<<形容詞>>","<<副詞>>","art. ","<<連接詞>>","int. ","<<名詞>>"," "," ","num. ", "prep. "," ","pron. ","<<動詞>>","<<助動詞>>","<<非及物動詞>>","<<及物動詞>>","vbl. "," ","st. ", "pr. ","<<過去分詞>>","<<複數>>","ing. "," ","<<形容詞>>","<<副詞>>","pla. ","pn. "," "] + from string import split,replace,strip,lstrip,find,lower -import GtkExtra import sys,os,string +if os.environ.has_key('DISPLAY') and len(sys.argv) == 1: + from gtk import * + from GDK import * + import GtkExtra -prop = [" "," "," ","<<形容詞>>","<<副詞>>","art. ","<<連接詞>>","int. ","<<名詞>>"," "," ","num. ", "prep. "," ","pron. ","<<動詞>>","<<助動詞>>","<<非及物動詞>>","<<及物動詞>>","vbl. "," ","st. ", "pr. ","<<過去分詞>>","<<複數>>","ing. "," ","<<形容詞>>","<<副詞>>","pla. ","pn. "," "] - -class Pref(GtkDialog): + class Pref(GtkDialog): def __init__(self,modal=TRUE,app=None): GtkDialog.__init__(self) self.connect("destroy", self.quit) @@ -483,7 +484,7 @@ def quit(self,w=None,event=None): self.hide() -class HelpDialog(GtkDialog): + class HelpDialog(GtkDialog): def __init__(self,modal=TRUE,file=None): GtkDialog.__init__(self) self.set_title("pyDict Help") @@ -543,7 +544,7 @@ self.quit() -class App(GtkWindow): + class App(GtkWindow): def __init__(self): GtkWindow.__init__(self,WINDOW_TOPLEVEL) self.create_vars() >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710220228.l9M2SC36030349>