Google App Engine’s Python Exception Syntax

Remember, Python 2.5 has this exception syntax:

try:
    raise FooException("Darn!")
except FooException, e
    print("Error: %s" % e)
The newer syntax is:
try:
    raise FooException("Darn!")
except FooException as e
    print("Error: %s" % e)
I ran into this when uploading an application to Google App Engine, which then produced this cryptic error:
<type 'exceptions.SyntaxError'>: invalid syntax (main.py, line 64)
Where line 64 is the line containing the not-yet-implemented as keyword.

Mac OS X 10.7 “Lion” Seems to Have a Broken Python easy_install

One of the first things I needed after upgrading to Mac OS X 10.7 (Lion) was to make some Python scripts work. However easy_install seemed to be broken:

$ easy_install psycopg2
Traceback (most recent call last):
  File "/usr/local/bin/easy_install", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2607, in <module>
    parse_requirements(requires), Environment()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: setuptools==0.6c12dev-r88795
I fixed this by installing Distribute and then the new Mac OS X Developer Tools.

 

ReferenceField can not be searchable

Under Archectypes 1.3 (final), I had a ReferenceField setup with searchable=True and this caused a TypeError when saving the object:

Traceback (innermost last):
  Module ZPublisher.Publish, line 100, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 40, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 98, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 39, in _call
  Module Products.CMFFormController.ControllerBase, line 191, in getNext
  Module Products.CMFFormController.Actions.TraverseTo, line 36, in __call__
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 40, in call_object
  Module Products.CMFFormController.FSControllerPythonScript, line 105, in __call__
  Module Products.CMFFormController.Script, line 141, in __call__
  Module Products.CMFCore.FSPythonScript, line 104, in __call__
  Module Shared.DC.Scripts.Bindings, line 306, in __call__
  Module Shared.DC.Scripts.Bindings, line 343, in _bindAndExec
  Module Products.CMFCore.FSPythonScript, line 160, in _exec
  Module None, line 11, in content_edit
   - <fscontrollerpythonscript at /plone1/content_edit used for /plone1/organization.2004-10-04.8620291094>
   - Line 11
  Module Products.Archetypes.BaseObject, line 573, in processForm
  Module Products.Archetypes.BaseObject, line 566, in _processForm
   - __traceback_info__: (<organization at /plone1/organization.2004-10-04.8620291094>, <field Notes(text:rw)>, <bound method Organization.setNotes of <organization at /plone1/organization.2004-10-04.8620291094>>)
  Module Products.Archetypes.CatalogMultiplex, line 60, in reindexObject
  Module Products.CMFMember.CatalogTool, line 51, in catalog_object
  Module Products.ZCatalog.ZCatalog, line 513, in catalog_object
  Module Products.ZCatalog.Catalog, line 381, in catalogObject
  Module Products.ZCTextIndex.ZCTextIndex, line 163, in index_object
  Module Products.ZCTextIndex.ZCTextIndex, line 173, in _index_object
  Module Products.Archetypes.BaseObject, line 475, in SearchableText
  Module Products.Archetypes.BaseObject, line 475, in <lambda>
  Module Products.Archetypes.utils, line 276, in getValue
TypeError: DisplayList keys must be strings or ints, got <extension class Acquisition.ImplicitAcquirerWrapper at 775140>

The only reference to this that I’ve found is on the list. Setting searchable=False avoids the issue. I do not know if this is an actual bug.