Loading ...
Sorry, an error occurred while loading the content.

Re: [Cheetahtemplate-discuss] unicode troubles

Expand Messages
  • Mike Orr
    ... The default encoding *is* ASCII for all practical purposes. Applications can t change it. The only way to change it is in site.py. -- Mike Orr
    Message 1 of 30 , Mar 29, 2007
    • 0 Attachment
      On 3/29/07, Tavis Rudd <tavis@...> wrote:
      > > no directive => Template must be ASCII. Output will be unicode if
      > > any placeholder value is unicode. (Possible exception if another value
      > > is a non-ASCII str.)
      > Well, technically the requirement isn't always ASCII, it's whatever the
      > default encoding is set to.

      The default encoding *is* ASCII for all practical purposes.
      Applications can't change it. The only way to change it is in
      site.py.

      --
      Mike Orr <sluggoster@...>

      -------------------------------------------------------------------------
      Take Surveys. Earn Cash. Influence the Future of IT
      Join SourceForge.net's Techsay panel and you'll get the chance to share your
      opinions on IT & business topics through brief surveys-and earn cash
      http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Tavis Rudd
      I believe this issue with WebSafe is fixed in the cvs now. ... Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net s Techsay panel and
      Message 2 of 30 , Apr 2, 2007
      • 0 Attachment
        I believe this issue with WebSafe is fixed in the cvs now.

        On Sun, 7 Jan 2007, Mike Orr wrote:

        > On 1/7/07, Charlie knudsen <charlie_knudsen@...> wrote:
        >>
        >> I may have made some progress on my issue. The below code is able to
        >> process the file:
        >> -----------------------
        >> t = Template(file="input.txt")
        >> out = t.respond()
        >> if type(out) != type(u''):
        >> out = out.decode('utf-8')
        >> print out.encode('utf-8')
        >> ---------------------------
        >> While this solves the simple example I outlined, I have not yet plugged this
        >> fix or variation of this fix into the actual my actual project. So please
        >> let me know if you could let me know if I am doing anything wrong, or why
        >> the decode function is needed I would appreciate it.
        >
        > Yes, this is reasonable. str(t) and unicode(t) break if the string
        > contains non-ASCII characters due to bugs in Python, so use
        > t.respond() instead, which preserves the string-or-unicode status. I
        > use precompiled ASCII templates with Unicode placeholder values and
        > get Unicode back fine. Perhaps you've discovered a bug in how
        > Template(file=) operates re Unicode. Is there a reason you can't use
        > precompiled templates?
        >
        > The WebSafe filter is not safe for non-ASCII characters because it
        > calls str() on the placeholder value. It needs to be based on
        > RawOrEncodedUnicode. I'm trying to clear out a couple other Python
        > projects so I can fix up the Filters module and a few other things
        > that need done in Cheetah.
        >
        > Sorry for not replying sooner. I was sick the past few days so I just
        > read your message quickly, and didn't realize the problem was so
        > similar to one I had had.
        >
        > --
        > Mike Orr <sluggoster@...>
        >
        > -------------------------------------------------------------------------
        > Take Surveys. Earn Cash. Influence the Future of IT
        > Join SourceForge.net's Techsay panel and you'll get the chance to share your
        > opinions on IT & business topics through brief surveys - and earn cash
        > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
        > _______________________________________________
        > Cheetahtemplate-discuss mailing list
        > Cheetahtemplate-discuss@...
        > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        >

        -------------------------------------------------------------------------
        Take Surveys. Earn Cash. Influence the Future of IT
        Join SourceForge.net's Techsay panel and you'll get the chance to share your
        opinions on IT & business topics through brief surveys-and earn cash
        http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Tavis Rudd
        The #unicode directive is implemented in the cvs now. Please note: - #unicode and #encoding are mutually exclusive. Use one or the other. - #unicode must be
        Message 3 of 30 , Apr 2, 2007
        • 0 Attachment
          The #unicode directive is implemented in the cvs now.
          Please note:
          - #unicode and #encoding are mutually exclusive. Use one or the other.
          - #unicode must be on a line by itself.
          - Strings in embedded code must be explictly marked as unicode if they
          contain non-ascii chars:

          #unicode latin-1
          $f("<some non-ascii char>") ## wrong
          $f(u"<some non-ascii char>") ## right

          However, this works fine:

          #unicode latin-1
          blah blah <some non-ascii char> blah blah

          Cheers,
          Tavis




          On Thu, 29 Mar 2007, Tavis Rudd wrote:
          >
          >
          > On Thu, 29 Mar 2007, Mike Orr wrote:
          >> On 3/29/07, Tavis Rudd <tavis@...> wrote:
          >>> The #unicode and #encoding directives could be combined in the form:
          >>> # unicode utf-8
          >>> # unicode latin-1
          >>> etc.
          >>
          >> Hmm. What about this?
          >>
          >> # unicode => Make output unicode.
          > using the system default input encoding
          >
          >> # unicode FOO => Make output unicode, and set input encoding.
          >> (Does this set the placeholder values' encoding too?)
          > No, it wouldn't do anything to the the encoding of placeholder values by
          > default. However, we could provide a filter that does that.
          >
          >> no directive => Template must be ASCII. Output will be unicode if
          >> any placeholder value is unicode. (Possible exception if another value
          >> is a non-ASCII str.)
          > Well, technically the requirement isn't always ASCII, it's whatever the
          > default encoding is set to.
          >
          >> #encoding sets the input encoding but does not make the output unicode.
          >> Its original purpose was to provide an "# -*- encoding" for non-ASCII
          >> templates, something that Python 2.4 suddenly required. I guess it
          >> should have made the output unicode too. But now there are lots of
          >> sites using it as is. Would they break if it started outputting
          >> unicode?
          >
          > Yes, it would break things.
          >
          >
          >
          > -------------------------------------------------------------------------
          > Take Surveys. Earn Cash. Influence the Future of IT
          > Join SourceForge.net's Techsay panel and you'll get the chance to share your
          > opinions on IT & business topics through brief surveys-and earn cash
          > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
          > _______________________________________________
          > Cheetahtemplate-discuss mailing list
          > Cheetahtemplate-discuss@...
          > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          >

          -------------------------------------------------------------------------
          Take Surveys. Earn Cash. Influence the Future of IT
          Join SourceForge.net's Techsay panel and you'll get the chance to share your
          opinions on IT & business topics through brief surveys-and earn cash
          http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        Your message has been successfully submitted and would be delivered to recipients shortly.