fixes issue 6 by reverting back to issuing attributeerror

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-07 19:07:22 +02:00
parent 8182d341a5
commit b7fe3ee2b3
3 changed files with 11 additions and 4 deletions

View File

@ -49,7 +49,7 @@ class Syslog:
for priority in "LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE LOG_INFO LOG_DEBUG".split():
try:
exec("%s = py.std.syslog.%s" % (priority, priority))
except ImportError:
except AttributeError:
pass
def __init__(self, priority = None):

View File

@ -2,11 +2,18 @@
import sys
class Std(object):
""" lazily import standard modules """
""" makes all standard python modules available as a lazily
computed attribute.
"""
def __init__(self):
self.__dict__ = sys.modules
def __getattr__(self, name):
return __import__(name)
try:
m = __import__(name)
except ImportError:
raise AttributeError("py.std: could not import %s" % name)
return m
std = Std()

View File

@ -6,7 +6,7 @@ def test_os():
assert py.std.os is os
def test_import_error_converts_to_attributeerror():
py.test.raises(ImportError, "py.std.xyzalskdj")
py.test.raises(AttributeError, "py.std.xyzalskdj")
def test_std_gets_it():
for x in py.std.sys.modules: