Function
ZODB.broken.find_global

Signature

find_global(modulename, globalname, Broken=<class 'ZODB.broken.Broken'>, type=<type 'type'>)

Documentation String

Find a global object, returning a broken class if it can't be found.

This function looks up global variable in modules:

  >>> import sys
  >>> find_global('sys', 'path') is sys.path
  True

If an object can't be found, a broken class is returned:

  >>> broken = find_global('ZODB.not.there', 'atall')
  >>> issubclass(broken, Broken)
  True
  >>> broken.__module__
  'ZODB.not.there'
  >>> broken.__name__
  'atall'

Broken classes are cached:

  >>> find_global('ZODB.not.there', 'atall') is broken
  True

If we "repair" a missing global:

  >>> class ZODBnotthere:
  ...     atall = []

  >>> sys.modules['ZODB.not'] = ZODBnotthere
  >>> sys.modules['ZODB.not.there'] = ZODBnotthere

we can then get the repaired value:

  >>> find_global('ZODB.not.there', 'atall') is ZODBnotthere.atall
  True

Of course, if we beak it again:

  >>> del sys.modules['ZODB.not']
  >>> del sys.modules['ZODB.not.there']

we get the broken value:

  >>> find_global('ZODB.not.there', 'atall') is broken
  True

Cleanup:

  >>> broken_cache.clear()