Re: troubles with unicode

Petr Jakeš <[email protected]>
Newsgroups gmane.comp.python.sqlobject
Message-ID <CAERU-VbB-h+kv95nnDrwhaphtt1FchbP_Qeic+OSrjrc8Dq=WA@mail.gmail.com>
After some investigation of the method columnsFromSchema it looks like
Firebird (FB 2.5 SuperServer actualy) returns the information about the
field type in following form:

> u'SHORT
> '
> so it is necessary to add
> t = t.strip()
> in the for loop (tested)
>
> Anyway, I guess it cant hurt anything.
>
> My guess was wrong. It ruined a lot of things in my web app (TurboGears
actually). I see on many of my pages something like bellow included
Traceback.

According to the Ivan Crstic, <http://farmdev.com/talks/unicode/> the
schema for working with international characters = unicode has to be:

   1. Decode early
   (by reading ASCII from the database and decode it using charset value
   default to the database or to the field)

   >>> def to_unicode_or_bust(...         obj, encoding='utf-8'):...
  if isinstance(obj, basestring):...         if not isinstance(obj,
unicode):...             obj = unicode(obj, encoding)...     return
obj

   2. Unicode everywhere
   3. Encode late

But I am l lost again with all this UnicodeEncodeError troubles.
Any idea how to solve it? What I am doing wrong?

Page handler: <bound method ProdejniMista.stavyZasobniku of
<fantomas.controllers.ProdejniMista instance at 0x3404e18>>
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py",
line 121, in _run
    self.main()
  File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/cherrypy/_cphttptools.py",
line 264, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in stavyZasobniku
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 360, in expose
    *args, **kw)
  File "<string>", line 5, in run_with_transaction
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/database.py",
line 359, in so_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 373, in <lambda>
    mapping, fragment, args, kw)))
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 423, in _execute_func
    return _process_output(output, template, format, content_type,
mapping, fragment)
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/controllers.py",
line 88, in _process_output
    fragment=fragment)
  File "/usr/local/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/view/base.py",
line 159, in render
    return engine.render(**kw)
  File "/usr/lib/python2.5/site-packages/TurboKid-1.0.5-py2.5.egg/turbokid/kidsupport.py",
line 220, in render
    output=output, format=format)
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/__init__.py",
line 301, in serialize
    raise_template_error(module=self.__module__)
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/__init__.py",
line 299, in serialize
    return serializer.serialize(self, encoding, fragment, format)
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/serialization.py",
line 107, in serialize
    text = ''.join(self.generate(stream, encoding, fragment, format))
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/serialization.py",
line 629, in generate
    for ev, item in self.apply_filters(stream, format):
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/serialization.py",
line 165, in format_stream
    for ev, item in stream:
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/parser.py",
line 221, in _coalesce
    for ev, item in stream:
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/serialization.py",
line 477, in inject_meta_tags
    for ev, item in stream:
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/parser.py",
line 179, in _track
    for p in stream:
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/filter.py",
line 32, in apply_matches
    item = stream.expand()
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/parser.py",
line 108, in expand
    for ev, item in self._iter:
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/parser.py",
line 179, in _track
    for p in stream:
  File "/usr/lib/python2.5/site-packages/kid-0.9.6-py2.5.egg/kid/parser.py",
line 221, in _coalesce
    for ev, item in stream:
  File "/TG_web/fantomas/templates/zasobniky.py", line 207, in _pull
  File "<string>", line 1, in <lambda>
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 1154, in _SO_foreignKey
    return joinClass.get(id, connection=self._connection)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 882, in get
    val._init(id, connection, selectResults)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 924, in _init
    self._SO_selectInit(selectResults)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/main.py",
line 1130, in _SO_selectInit
    colValue = col.to_python(colValue, self._SO_validatorState)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/col.py",
line 513, in to_python
    return value.encode(dbEncoding)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u010d' in
position 8: ordinal not in range(128)
Error location in template file '/TG_web/fantomas/templates/zasobniky.kid'
between line 26, column 8 and line 27, column 8:
        <td align="left" py:content="zasobnik.ciselnik.nazev"/>

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/

_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.