From dl at znain.net Fri May 18 14:01:06 2007 From: dl at znain.net (Dimitre Liotev) Date: Fri, 18 May 2007 10:01:06 -0400 Subject: [html-template-devel] problem with UTF characters in template Message-ID: <81bqgigrj1.fsf@oh177.znain.com> Hi, when I have UTF characters in a template I get this error: #\? is not a LATIN-1 character. [Condition of type FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR] Is there a way to fix this? I use Allegro CL Express on Windows. -- Dimitre Liotev From edi at agharta.de Fri May 18 14:08:51 2007 From: edi at agharta.de (Edi Weitz) Date: Fri, 18 May 2007 16:08:51 +0200 Subject: [html-template-devel] problem with UTF characters in template In-Reply-To: <81bqgigrj1.fsf@oh177.znain.com> (Dimitre Liotev's message of "Fri, 18 May 2007 10:01:06 -0400") References: <81bqgigrj1.fsf@oh177.znain.com> Message-ID: On Fri, 18 May 2007 10:01:06 -0400, Dimitre Liotev
wrote: > when I have UTF characters in a template I get this error: > > #\? is not a LATIN-1 character. > [Condition of type FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR] What external format did you specify? How about showing us the code you tried and providing a backtrace? Cheers, Edi. From dl at znain.net Fri May 18 15:24:15 2007 From: dl at znain.net (Dimitre Liotev) Date: Fri, 18 May 2007 11:24:15 -0400 Subject: [html-template-devel] problem with UTF characters in template In-Reply-To: (Edi Weitz's message of "Fri, 18 May 2007 16:08:51 +0200") References: <81bqgigrj1.fsf@oh177.znain.com> Message-ID: <814pmagnog.fsf@oh177.znain.com> Edi Weitz writes: > On Fri, 18 May 2007 10:01:06 -0400, Dimitre Liotev
wrote: > >> when I have UTF characters in a template I get this error: >> >> #\? is not a LATIN-1 character. >> [Condition of type FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR] > > What external format did you specify? How about showing us the code > you tried and providing a backtrace? > > Cheers, > Edi. Hi Edi, I am using the "Simple example" from your page http://weitz.de/html-template/, specifying :external-format "UTF-8" in the call to create-template-printer: (defparameter *template-dispatcher* (hunchentoot:create-prefix-dispatcher "/template-test/" (lambda () (let* ((html-template:*string-modifier* #'identity) (rows (loop for i below 49 by 7 collect (list :cols (loop for j from i below (+ i 7) for string = (format nil "~R" j) collect (list :content string :colorful-style (oddp j)))))) (values (list :rows rows))) (with-output-to-string (html-template:*default-template-output*) (html-template:fill-and-print-template (html-template:create-template-printer #p"foo.tmpl" :external-format "UTF-8") values)))))) (push *template-dispatcher* hunchentoot:*dispatch-table*) The template:
some cyrullic chars: ????
Now if I point the browser to http://localhost:8082/template-test/ it works fine if the UTF chars are not there, but if I put any cyrillic UTF encoded character in the template I get the error: #\? is not a LATIN-1 character. [Condition of type FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR] Restarts: 0: [ABORT] Abort entirely from this (lisp) process. Backtrace: 0: ((:INTERNAL SWANK:SWANK-DEBUGGER-HOOK 0)) Locals: CONDITION = :UNKNOWN 1: ((:INTERNAL (:TOP-LEVEL-FORM "swank-backend.lisp" 20112) 0) # #) Locals: SWANK-BACKEND::HOOK = # SWANK-BACKEND::FUN = # SWANK-BACKEND::FUN = # 2: (SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK # #) Locals: SWANK-BACKEND::HOOK = # SWANK-BACKEND::FUN = # SWANK-BACKEND::HOOK = # SWANK-BACKEND::FUN = # 3: ((:INTERNAL SWANK::CALL-WITH-CONNECTION 0)) Locals: SWANK::FUN = # 4: (SWANK::CALL-WITH-REDIRECTED-IO # #) Locals: SWANK::CONNECTION = # FUNCTION = # FUNCTION = # SWANK::IO = # SWANK::IN = # SWANK::CONNECTION = # SWANK::OUT = # 5: (SWANK::MAYBE-CALL-WITH-IO-REDIRECTION # #) Locals: SWANK::CONNECTION = # SWANK::FUN = # SWANK::CONNECTION = # SWANK::FUN = #(#) 6: (SWANK::CALL-WITH-CONNECTION # #) Locals: SWANK::CONNECTION = # SWANK::FUN = # SWANK::CONNECTION = # SYSTEM::.LAMBDA-LEXICAL-ENV. = #(#) SWANK::FUN = # 7: (SWANK:SWANK-DEBUGGER-HOOK # #) Locals: CONDITION = # SWANK::HOOK = # SYSTEM::.LAMBDA-LEXICAL-ENV. = # CONDITION = :UNKNOWN 8: (INVOKE-DEBUGGER #) Locals: CONDITION = # EXCL::LOCAL-0 = # EXCL::LOCAL-1 = # EXCL::LOCAL-2 = T 9: (SIGNAL #) Locals: EXCL::DATUM = # EXCL::ARGUMENTS = NIL EXCL::LOCAL-0 = NIL EXCL::LOCAL-1 = # EXCL::LOCAL-2 = ((ERROR . #)) EXCL::LOCAL-3 = (ERROR . #) EXCL::LOCAL-4 = # EXCL::LOCAL-5 = #\null EXCL::LOCAL-6 = # 10: (ERROR FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR :FORMAT-CONTROL "~S is not a LATIN-1 character." :FORMAT-ARGUMENTS (#\?) :STREAM #) Locals: EXCL::DATUM = FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR EXCL::ARGUMENTS = (:FORMAT-CONTROL "~S is not a LATIN-1 character." :FORMAT-ARGUMENTS (#\?) :STREAM #) EXCL::LOCAL-0 = (:FORMAT-CONTROL "~S is not a LATIN-1 character." :FORMAT-ARGUMENTS (#\?) :STREAM #) EXCL::LOCAL-1 = FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR EXCL::LOCAL-2 = # EXCL::LOCAL-3 = 97 EXCL::LOCAL-4 = 1 EXCL::LOCAL-5 = # EXCL::LOCAL-6 = # :UNKNOWN = NIL :UNKNOWN = NIL :UNKNOWN = NIL :UNKNOWN = NIL :UNKNOWN = NIL 11: (FLEXI-STREAMS::SIGNAL-ENCODING-ERROR # "~S is not a LATIN-1 character." #\?) Locals: FLEXI-STREAMS:FLEXI-STREAM = # FLEXI-STREAMS::FORMAT-CONTROL = "~S is not a LATIN-1 character." FLEXI-STREAMS::FORMAT-ARGS = (#\?) FLEXI-STREAMS::FORMAT-ARGS = (#\?) FLEXI-STREAMS:FLEXI-STREAM = # FLEXI-STREAMS::FORMAT-CONTROL = "~S is not a LATIN-1 character." 12: ((METHOD STREAM-WRITE-CHAR (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T)) # #\?) Locals: STREAM = # CHAR = #\? CHAR = #\? FLEXI-STREAMS:OCTET = 1044 STREAM = # 13: ((:INTERNAL (:EFFECTIVE-METHOD 2 NIL NIL NIL NIL) 0) # #\?) Locals: EXCL::METHARG0 = # EXCL::METHARG1 = #\? EXCL::LOCAL-0 = # EXCL::LOCAL-1 = #\? EXCL::LOCAL-2 = # EXCL::LOCAL-3 = # EXCL::LOCAL-4 = NIL EXCL::LOCAL-5 = 3 EXCL::LOCAL-6 = 137387322 EXCL::LOCAL-7 = # EXCL::LOCAL-8 = 2 14: ((METHOD TRIVIAL-GRAY-STREAMS:STREAM-WRITE-SEQUENCE (FLEXI-STREAMS:FLEXI-OUTPUT-STREAM T T T)) # " ..) Locals: FLEXI-STREAMS:FLEXI-OUTPUT-STREAM = # SEQUENCE = "
zero
.. FLEXI-STREAMS::START = 173 FLEXI-STREAMS::END = 4537 SEQUENCE = "
zero some cyrillic chars: ???? one
.. FLEXI-STREAMS:FLEXI-OUTPUT-STREAM = # #:|g1798| = # 15: ((METHOD STREAM-WRITE-STRING (TRIVIAL-GRAY-STREAMS:TRIVIAL-GRAY-STREAM-MIXIN T)) # "
zero some cyrillic chars: ???? one
..) Locals: STREAM = # TRIVIAL-GRAY-STREAMS::SEQ = "
zero
.. TRIVIAL-GRAY-STREAMS::START = 0 TRIVIAL-GRAY-STREAMS::END = NIL TRIVIAL-GRAY-STREAMS::START = 0 TRIVIAL-GRAY-STREAMS::END = NIL STREAM = # 16: (FLEXI-STREAMS:STRING-TO-OCTETS "
zero some cyrillic chars: ???? one
..) Locals: STRING = "
zero some cyrillic chars: ???? one
.. FLEXI-STREAMS::EXTERNAL-FORMAT = # FLEXI-STREAMS::START = :UNSUPPLIED FLEXI-STREAMS::END = :UNSUPPLIED FLEXI-STREAMS::OUT = # NIL = 0 STRING = "
zero some cyrillic chars: ???? one
.. FLEXI-STREAMS::START = 0 FLEXI-STREAMS::END = NIL FLEXI-STREAMS::EXTERNAL-FORMAT = # 17: (HUNCHENTOOT::COMPUTE-LENGTH "
zero some cyrillic chars: ???? one
..) Locals: NIL = "
zero some cyrillic chars: ???? one
.. EXCL::LOCAL-0 = "
zero some cyrillic chars: ???? one
.. EXCL::LOCAL-1 = # EXCL::LOCAL-2 = # 18: (HUNCHENTOOT::START-OUTPUT "
zero some cyrillic chars: ???? one
..) 19: (HUNCHENTOOT::PROCESS-REQUEST ((:HOST . "localhost:8082") (:USER-AGENT . "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)") (:ACCEPT . "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5") (:ACCEPT-LANGUAGE . "en-us,en;q=0.5") (:ACCEPT-ENCODING . "gzip,deflate") (:ACCEPT-CHARSET . "ISO-8859-1,utf-8;q=0.7,*;q=0.7") (:KEEP-ALIVE . "300") (:CONNECTION . "keep-alive") ..)) 20: (HUNCHENTOOT::PROCESS-CONNECTION # #) From edi at agharta.de Fri May 18 15:58:16 2007 From: edi at agharta.de (Edi Weitz) Date: Fri, 18 May 2007 17:58:16 +0200 Subject: [html-template-devel] problem with UTF characters in template In-Reply-To: <814pmagnog.fsf@oh177.znain.com> (Dimitre Liotev's message of "Fri, 18 May 2007 11:24:15 -0400") References: <81bqgigrj1.fsf@oh177.znain.com> <814pmagnog.fsf@oh177.znain.com> Message-ID: On Fri, 18 May 2007 11:24:15 -0400, Dimitre Liotev
wrote: > I am using the "Simple example" from your page > http://weitz.de/html-template/, specifying :external-format "UTF-8" > in the call to create-template-printer: Is the string "UTF-8" a valid external format specifier on AllegroCL? > (defparameter *template-dispatcher* > (hunchentoot:create-prefix-dispatcher "/template-test/" > (lambda () > (let* ((html-template:*string-modifier* #'identity) > (rows (loop for i below 49 by 7 > collect > (list :cols > (loop for j from i below (+ i 7) > for string = (format nil "~R" j) > collect (list :content string > :colorful-style (oddp j)))))) > (values (list :rows rows))) > (with-output-to-string (html-template:*default-template-output*) > (html-template:fill-and-print-template > (html-template:create-template-printer #p"foo.tmpl" :external-format "UTF-8") > values)))))) > > [...] > > 12: ((METHOD STREAM-WRITE-CHAR > (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T)) > # #\?) > Locals: > STREAM = # #x21279e5a> > CHAR = #\? > CHAR = #\? > FLEXI-STREAMS:OCTET = 1044 > STREAM = # #x21279e5a> The condition is signalled when Hunchentoot is trying to write the page to the client. You have to make sure that Hunchentoot knows that it's supposed to output UTF-8. See the examples that come with Hunchentoot for how this can be done. (And you should also set the headers accordingly, so the browser knows what to expect.) From dl at znain.net Fri May 18 18:55:33 2007 From: dl at znain.net (Dimitre Liotev) Date: Fri, 18 May 2007 14:55:33 -0400 Subject: [html-template-devel] problem with UTF characters in template In-Reply-To: (Edi Weitz's message of "Fri, 18 May 2007 17:58:16 +0200") References: <81bqgigrj1.fsf@oh177.znain.com> <814pmagnog.fsf@oh177.znain.com> Message-ID: <81y7jmezbu.fsf@oh177.znain.com> Edi Weitz writes: > On Fri, 18 May 2007 11:24:15 -0400, Dimitre Liotev
wrote: > >> I am using the "Simple example" from your page >> http://weitz.de/html-template/, specifying :external-format "UTF-8" >> in the call to create-template-printer: > > Is the string "UTF-8" a valid external format specifier on AllegroCL? I thought so, but it seems that the format must be specified as a keyword: CL-USER> (describe (find-if (lambda (x) (member :UTF-8 (excl:ef-nicknames x))) (EXCL:ALL-EXTERNAL-FORMATS))) # is a structure of type EXTERNAL-FORMAT. It has these slots: NAME (:E-CRLF :UTF8-BASE) NICKNAMES (:UTF8 :UTF-8) ... I thought the string "UTF-8" would also work because when I try WITH-OPEN-FILE with an invalid external format like "UTF-9", an error is thrown, while "UTF-8" is accepted and no error is raised. >> (defparameter *template-dispatcher* >> (hunchentoot:create-prefix-dispatcher "/template-test/" >> (lambda () >> (let* ((html-template:*string-modifier* #'identity) >> (rows (loop for i below 49 by 7 >> collect >> (list :cols >> (loop for j from i below (+ i 7) >> for string = (format nil "~R" j) >> collect (list :content string >> :colorful-style (oddp j)))))) >> (values (list :rows rows))) >> (with-output-to-string (html-template:*default-template-output*) >> (html-template:fill-and-print-template >> (html-template:create-template-printer #p"foo.tmpl" :external-format "UTF-8") >> values)))))) >> >> [...] >> >> 12: ((METHOD STREAM-WRITE-CHAR >> (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T)) >> # #\?) >> Locals: >> STREAM = #> #x21279e5a> >> CHAR = #\? >> CHAR = #\? >> FLEXI-STREAMS:OCTET = 1044 >> STREAM = #> #x21279e5a> > > The condition is signalled when Hunchentoot is trying to write the > page to the client. You have to make sure that Hunchentoot knows that > it's supposed to output UTF-8. See the examples that come with > Hunchentoot for how this can be done. (And you should also set the > headers accordingly, so the browser knows what to expect.) Thanks! For the sake of those who might encounter the same problem: I added this to my handler function: (setf (hunchentoot:reply-external-format) :UTF-8) This will set the reply-external-format only for the given handler. To set it globaly use this: (setf hunchentoot:*hunchentoot-default-external-format* :UTF-8)
zero some cyrillic chars: ???? one