fixes issue 6 by reverting back to issuing attributeerror
--HG-- branch : trunk
This commit is contained in:
parent
8182d341a5
commit
b7fe3ee2b3
|
@ -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():
|
for priority in "LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE LOG_INFO LOG_DEBUG".split():
|
||||||
try:
|
try:
|
||||||
exec("%s = py.std.syslog.%s" % (priority, priority))
|
exec("%s = py.std.syslog.%s" % (priority, priority))
|
||||||
except ImportError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __init__(self, priority = None):
|
def __init__(self, priority = None):
|
||||||
|
|
|
@ -2,11 +2,18 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class Std(object):
|
class Std(object):
|
||||||
""" lazily import standard modules """
|
""" makes all standard python modules available as a lazily
|
||||||
|
computed attribute.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__dict__ = sys.modules
|
self.__dict__ = sys.modules
|
||||||
|
|
||||||
def __getattr__(self, name):
|
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()
|
std = Std()
|
||||||
|
|
|
@ -6,7 +6,7 @@ def test_os():
|
||||||
assert py.std.os is os
|
assert py.std.os is os
|
||||||
|
|
||||||
def test_import_error_converts_to_attributeerror():
|
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():
|
def test_std_gets_it():
|
||||||
for x in py.std.sys.modules:
|
for x in py.std.sys.modules:
|
||||||
|
|
Loading…
Reference in New Issue