From dl@znain.net Fri May 18 10:01:15 2007 From: Dimitre Liotev To: html-template-devel@common-lisp.net Subject: [html-template-devel] problem with UTF characters in template Date: Fri, 18 May 2007 10:01:06 -0400 Message-ID: <81bqgigrj1.fsf@oh177.znain.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1457240001690606559==" --===============1457240001690606559== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 --===============1457240001690606559==-- From edi@agharta.de Fri May 18 10:08:49 2007 From: Edi Weitz To: html-template-devel@common-lisp.net Subject: Re: [html-template-devel] problem with UTF characters in template Date: Fri, 18 May 2007 16:08:51 +0200 Message-ID: In-Reply-To: <81bqgigrj1.fsf@oh177.znain.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6833688922881280911==" --===============6833688922881280911== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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. --===============6833688922881280911==-- From dl@znain.net Fri May 18 11:24:22 2007 From: Dimitre Liotev To: html-template-devel@common-lisp.net Subject: Re: [html-template-devel] problem with UTF characters in template Date: Fri, 18 May 2007 11:24:15 -0400 Message-ID: <814pmagnog.fsf@oh177.znain.com> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8255216617068270961==" --===============8255216617068270961== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =3D (format nil "~R" j) collect (list :content string=20 :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-forma= t "UTF-8") values)))))) =20 (push *template-dispatcher* hunchentoot:*dispatch-table*) The template:
some cyrullic chars: =D0=94=D0= =96=D0=93=D0=91
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 =3D :UNKNOWN 1: ((:INTERNAL (:TOP-LEVEL-FORM "swank-backend.lisp" 20112) 0) # #) Locals: SWANK-BACKEND::HOOK =3D # SWANK-BACKEND::FUN =3D # SWANK-BACKEND::FUN =3D # 2: (SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK # #) Locals: SWANK-BACKEND::HOOK =3D # SWANK-BACKEND::FUN =3D # SWANK-BACKEND::HOOK =3D # SWANK-BACKEND::FUN =3D # 3: ((:INTERNAL SWANK::CALL-WITH-CONNECTION 0)) Locals: SWANK::FUN =3D # 4: (SWANK::CALL-WITH-REDIRECTED-IO # #) Locals: SWANK::CONNECTION =3D # FUNCTION =3D # FUNCTION =3D # SWANK::IO =3D # SWANK::IN =3D # SWANK::CONNECTION =3D # SWANK::OUT =3D # 5: (SWANK::MAYBE-CALL-WITH-IO-REDIRECTION # #) Locals: SWANK::CONNECTION =3D # SWANK::FUN =3D # SWANK::CONNECTION =3D # SWANK::FUN =3D #(#) 6: (SWANK::CALL-WITH-CONNECTION # #) Locals: SWANK::CONNECTION =3D # SWANK::FUN =3D # SWANK::CONNECTION =3D # SYSTEM::.LAMBDA-LEXICAL-ENV. =3D #(#) SWANK::FUN =3D # 7: (SWANK:SWANK-DEBUGGER-HOOK # #) Locals: CONDITION =3D # SWANK::HOOK =3D # SYSTEM::.LAMBDA-LEXICAL-ENV. =3D # CONDITION =3D :UNKNOWN 8: (INVOKE-DEBUGGER #) Locals: CONDITION =3D # EXCL::LOCAL-0 =3D # EXCL::LOCAL-1 =3D # EXCL::LOCAL-2 =3D T 9: (SIGNAL #) Locals: EXCL::DATUM =3D # EXCL::ARGUMENTS =3D NIL EXCL::LOCAL-0 =3D NIL EXCL::LOCAL-1 =3D # EXCL::LOCAL-2 =3D ((ERROR . #)) EXCL::LOCAL-3 =3D (ERROR . #) EXCL::LOCAL-4 =3D # EXCL::LOCAL-5 =3D #\null EXCL::LOCAL-6 =3D # 10: (ERROR FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR :FORMAT-CONTROL "~S is not a LATIN-1 character." :FORMAT-ARGUMENTS (#\?) :STREAM #) Locals: EXCL::DATUM =3D FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR EXCL::ARGUMENTS =3D (:FORMAT-CONTROL "~S is not a LATIN-1 character." :FORMAT-ARGUMENTS (#\?) :STREAM #) EXCL::LOCAL-0 =3D (:FORMAT-CONTROL "~S is not a LATIN-1 character." :FORMAT-ARGUMENTS (#\?) :STREAM #) EXCL::LOCAL-1 =3D FLEXI-STREAMS:FLEXI-STREAM-ENCODING-ERROR EXCL::LOCAL-2 =3D # EXCL::LOCAL-3 =3D 97 EXCL::LOCAL-4 =3D 1 EXCL::LOCAL-5 =3D # EXCL::LOCAL-6 =3D # :UNKNOWN =3D NIL :UNKNOWN =3D NIL :UNKNOWN =3D NIL :UNKNOWN =3D NIL :UNKNOWN =3D NIL 11: (FLEXI-STREAMS::SIGNAL-ENCODING-ERROR # "~S is not a LATIN-1 character." #\?) Locals: FLEXI-STREAMS:FLEXI-STREAM =3D # FLEXI-STREAMS::FORMAT-CONTROL =3D "~S is not a LATIN-1 character." FLEXI-STREAMS::FORMAT-ARGS =3D (#\?) FLEXI-STREAMS::FORMAT-ARGS =3D (#\?) FLEXI-STREAMS:FLEXI-STREAM =3D # FLEXI-STREAMS::FORMAT-CONTROL =3D "~S is not a LATIN-1 character." 12: ((METHOD STREAM-WRITE-CHAR (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T)) # #\?) Locals: STREAM =3D # CHAR =3D #\? CHAR =3D #\? FLEXI-STREAMS:OCTET =3D 1044 STREAM =3D # 13: ((:INTERNAL (:EFFECTIVE-METHOD 2 NIL NIL NIL NIL) 0) # #\?) Locals: EXCL::METHARG0 =3D # EXCL::METHARG1 =3D #\? EXCL::LOCAL-0 =3D # EXCL::LOCAL-1 =3D #\? EXCL::LOCAL-2 =3D # EXCL::LOCAL-3 =3D # EXCL::LOCAL-4 =3D NIL EXCL::LOCAL-5 =3D 3 EXCL::LOCAL-6 =3D 137387322 EXCL::LOCAL-7 =3D # EXCL::LOCAL-8 =3D 2 14: ((METHOD TRIVIAL-GRAY-STREAMS:STREAM-WRITE-SEQUENCE (FLEXI-STREAMS:FLEXI-OUTPUT-STREAM T T T)) # " =20 =20 =20 ..) Locals: FLEXI-STREAMS:FLEXI-OUTPUT-STREAM =3D # SEQUENCE =3D "
zero
=20 =20 =20 =20 =20 =20 .. FLEXI-STREAMS::START =3D 173 FLEXI-STREAMS::END =3D 4537 SEQUENCE =3D "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 .. FLEXI-STREAMS:FLEXI-OUTPUT-STREAM =3D # #:|g1798| =3D # 15: ((METHOD STREAM-WRITE-STRING (TRIVIAL-GRAY-STREAMS:TRIVIAL-GRAY-STREAM-MIXIN T)) # "
zerosome cyrillic chars: ???? one
=20 =20 =20 ..) Locals: STREAM =3D # TRIVIAL-GRAY-STREAMS::SEQ =3D "
zero
=20 =20 =20 =20 =20 =20 .. TRIVIAL-GRAY-STREAMS::START =3D 0 TRIVIAL-GRAY-STREAMS::END =3D NIL TRIVIAL-GRAY-STREAMS::START =3D 0 TRIVIAL-GRAY-STREAMS::END =3D NIL STREAM =3D # 16: (FLEXI-STREAMS:STRING-TO-OCTETS "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 ..) Locals: STRING =3D "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 .. FLEXI-STREAMS::EXTERNAL-FORMAT =3D # FLEXI-STREAMS::START =3D :UNSUPPLIED FLEXI-STREAMS::END =3D :UNSUPPLIED FLEXI-STREAMS::OUT =3D # NIL =3D 0 STRING =3D "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 .. FLEXI-STREAMS::START =3D 0 FLEXI-STREAMS::END =3D NIL FLEXI-STREAMS::EXTERNAL-FORMAT =3D # 17: (HUNCHENTOOT::COMPUTE-LENGTH "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 ..) Locals: NIL =3D "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 .. EXCL::LOCAL-0 =3D "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 .. EXCL::LOCAL-1 =3D # EXCL::LOCAL-2 =3D # 18: (HUNCHENTOOT::START-OUTPUT "
zerosome cyrillic chars: ???? one
=20 =20 =20 =20 =20 =20 ..) 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=3D0.9,= text/plain;q=3D0.8,image/png,*/*;q=3D0.5") (:ACCEPT-LANGUAGE . "en-us,en;q=3D0.5") (:ACCEPT-ENCODING . "gzip,deflate") (:ACCEPT-CHARSET . "ISO-8859-1,utf-8;q=3D0.7,*;q=3D0.7") (:KEEP-ALIVE . "300") (:CONNECTION . "keep-alive") ..)) 20: (HUNCHENTOOT::PROCESS-CONNECTION # #) --===============8255216617068270961==-- From edi@agharta.de Fri May 18 11:58:15 2007 From: Edi Weitz To: html-template-devel@common-lisp.net Subject: Re: [html-template-devel] problem with UTF characters in template Date: Fri, 18 May 2007 17:58:16 +0200 Message-ID: In-Reply-To: <814pmagnog.fsf@oh177.znain.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4545503506508825879==" --===============4545503506508825879== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =3D (format nil "~R" j) > collect (list :content string=20 > :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-for= mat "UTF-8") > values)))))) > > [...] > > 12: ((METHOD STREAM-WRITE-CHAR > (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T)) > # #\?) > Locals: > STREAM =3D # #x21279e5a> > CHAR =3D #\? > CHAR =3D #\? > FLEXI-STREAMS:OCTET =3D 1044 > STREAM =3D # #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.) --===============4545503506508825879==-- From dl@znain.net Fri May 18 14:55:40 2007 From: Dimitre Liotev To: html-template-devel@common-lisp.net Subject: Re: [html-template-devel] problem with UTF characters in template Date: Fri, 18 May 2007 14:55:33 -0400 Message-ID: <81y7jmezbu.fsf@oh177.znain.com> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3679058792614867831==" --===============3679058792614867831== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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-FIL= E =20 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 =3D (format nil "~R" j) >> collect (list :content string=20 >> :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-fo= rmat "UTF-8") >> values)))))) >> >> [...] >> >> 12: ((METHOD STREAM-WRITE-CHAR >> (FLEXI-STREAMS::FLEXI-LATIN-1-OUTPUT-STREAM T)) >> # #\?) >> Locals: >> STREAM =3D #> #x21279e5a> >> CHAR =3D #\? >> CHAR =3D #\? >> FLEXI-STREAMS:OCTET =3D 1044 >> STREAM =3D #> #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) --===============3679058792614867831==--
zerosome cyrillic chars: ???? one