durusmail: quixote-users: Unicode? scgi restart?
Unicode? scgi restart?
2003-11-14
2003-11-14
2003-11-14
2003-11-14
2003-11-14
2003-11-14
2003-11-14
Re: Unicode?
2003-11-14
2003-11-14
2003-11-14
2003-11-14
2003-11-14
Unicode? scgi restart?
Skip Montanaro
2003-11-14
Is there a way to get Quixote to "do the right thing" with Unicode?  For
example, I tried publishing:

    def freddie [html] ():
        u'Fr\xe9ddie Kr\xfcger'

and get this traceback:

    Traceback (most recent call last):
      File "/Users/skip/local/lib/python2.4/site-packages/quixote/publish.py",
line 534, in publish
        output = self.process_request(request, env)
      File "/Users/skip/local/lib/python2.4/site-packages/quixote/publish.py",
line 516, in process_request
        output = self.try_publish(request, env.get('PATH_INFO', ''))
      File "/Users/skip/local/lib/python2.4/site-packages/quixote/publish.py",
line 464, in try_publish
        output = object(request)
      File "/Users/skip/cgi/musi-cal/musi_cal/staticfiles.ptl", line 45, in
freddie
        u'Fr\xe9ddie Kr\xfcger'
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position
2: ordinal not in range(128)

Changing the body to

    u'Fr\xe9ddie Kr\xfcger'.encode("iso-8859-1")

didn't help either, though it works just fine from a Python interpreter
prompt.

It would be nice if I could just set a charset or encoding on the response
object and have Quixote do the proper encoding dance when it generates a
page.  Is there a way to do that?  One of my initial motivations for moving
away from Mason was that between the two of them, Perl and Mason seem to
screw up Unicode output pretty well.

On a related note, restarting the scgi server is a little bit of a pain.  Is
this the best I can do

    ps auxww | egrep 'python main' | egrep -v egrep \
    | awk '{print $2}' | sort -n | xargs kill -1

given that main.py includes this code at the bottom?

    def restart(sig, frame):
        os.execv(sys.executable, sys.argv)

    if __name__ == "__main__":
        # restart on HUP
        signal.signal(signal.SIGHUP, restart)

        # Install the import hook that enables PTL modules.
        quixote.enable_ptl()
        scgi.quixote_handler.main(Handler)

(Thank goodness for bash command recall!)

Thx,

Skip


reply