<br><br><div><span class="gmail_quote">On 9/9/06, <b class="gmail_sendername">Manlio Perillo</b> &lt;<a href="mailto:manlio_perillo@libero.it">manlio_perillo@libero.it</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>&gt;&gt; There are some problems with this:<br>&gt;&gt;<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;elif isinstance(obj, str):<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w('&quot;')<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w(stringEncode(obj.decode(&quot;us-ascii&quot;))<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w('&quot;')
<br>&gt;&gt; ?<br>&gt;<br>&gt; Yes.&nbsp;&nbsp;What if it is not an ASCII string?<br><br>Raise an arror?<br>Is this really a problem?</blockquote><div><br><br>Yes.&nbsp; Yes it is.&nbsp; Javascript strings are unicode.&nbsp; Therefore the implementation must be able to convert the encoded string (byte representation) into Unicode when it arrives.
<br><br>In order to convert the parameter to unicode, the API has to know what encoding the original string was; or it must have it in Unicode form already.&nbsp; If the API accepts 8-bit str objects, then it must guess at the encoding to produce a unicode object.&nbsp; It will guess wrong very often, which leads to bugs.&nbsp; Therefore, it does not accept 8-bit str objects.
<br><br>You must provide Unicode objects to the API so that it does not have to guess.&nbsp; The errors you get are essentially the API telling you &quot;I refuse to guess.&quot;&nbsp; It forces the programmer to tell the API what encoding the original string had; the way you answer it is by decoding it yourself with the right encoding argument into a Unicode object.
<br><br><a href="http://gedcom-parse.sourceforge.net/doc/encoding.html">http://gedcom-parse.sourceforge.net/doc/encoding.html</a><br></div><br><br>C<br><br></div>