Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1671 (closed defect: wontfix)

Opened 11 years ago

Last modified 11 years ago

formencode/turbogears gettext incompatibility

Reported by: fetchinson Owned by: Chris Arndt
Priority: normal Milestone: 1.0.x bugfix
Component: TurboGears Version:
Severity: normal Keywords:

Description (last modified by Chris Arndt) (diff)

The second call in the following raises a TypeError: ugettext() got an unexpected keyword argument 'domain' exception in a Python shell:

import turbogears

However only the legitimate Invalid exception is raised if executed from a script.

The following on the other hand works as expected in both a Python shell and from a script:

import formencode

See the thread  http://groups.google.com/group/turbogears/browse_thread/thread/93b7d5f608801652

Change History

comment:1 Changed 11 years ago by Chris Arndt

  • Milestone changed from 1.0.4 to 1.0.x bugfix

comment:2 Changed 11 years ago by Chris Arndt

  • Description modified (diff)

comment:3 Changed 11 years ago by amit

We have seen similar problem. We found that this is due to the replacement of __builtins__['_']. The replacement was caused by the xpath module.

# this will replace the __builtins__['_'] with the standard `gettext` function
from xml import xpath

# so reinstall it
from turbogears.i18n import tg_gettext

Might be the same case with the Python shell.

comment:4 Changed 11 years ago by Chris Arndt

  • Owner changed from anonymous to Chris Arndt
  • Status changed from new to assigned

comment:5 Changed 11 years ago by Chris Arndt

  • Status changed from assigned to closed
  • Resolution set to wontfix

The interactive Python shell sets _ to the result of the last expression entered if it is not None.

So, in the above example we have the following chain of events:

  • _ gets set to 5 after the second line, overwriting the turbgears.i18n.gettext.
  • In the next line, FormEncode throws an Invalid exception and tries to translate the error message,
  • validators.Int.message gets the translation function from __builtins__._
  • it recognizes _ is not a callable
  • and therefor uses its standard translation function formencode.api._stdtrans.
  • turbogears.validators sets formencode.gettextargs to include domain=... but stdtrans does not recognize this keyword arg and we get the TypeError?` exception.

In the second example Validator.gettextargs never gets set, so _stdtrans works, even if _ has been overwritten.

So this really only happens with the interactive shell, because of the name clash around _, this is not an issue when running your TG app. If you really need this to work in the interactive shell, a workaround would be:

>>> import turbogears
>>> state = turbogears.util.Bunch(_=_)
>>> turbogears.validators.Int().to_python('5', state)
>>> turbogears.validators.Int().to_python('x', state)

Or you can just use the IPython shell, which leaves _ alone.

Note: See TracTickets for help on using tickets.