@@ -1032,9 +1032,25 @@ def find_module(self, fullname, path=None):
1032
1032
finally :
1033
1033
del _tls .running
1034
1034
1035
+ blacklisted_msg = (
1036
+ '%r is present in the Mitogen importer blacklist, therefore this '
1037
+ 'context will not attempt to request it from the master, as the '
1038
+ 'request will always be refused.'
1039
+ )
1040
+ pkg_resources_msg = (
1041
+ 'pkg_resources is prohibited from importing __main__, as it causes '
1042
+ 'problems in applications whose main module is not designed to be '
1043
+ 're-imported by children.'
1044
+ )
1045
+ absent_msg = (
1046
+ 'The Mitogen master process was unable to serve %r. It may be a '
1047
+ 'native Python extension, or it may be missing entirely. Check the '
1048
+ 'importer debug logs on the master for more information.'
1049
+ )
1050
+
1035
1051
def _refuse_imports (self , fullname ):
1036
1052
if is_blacklisted_import (self , fullname ):
1037
- raise ImportError ('Refused: ' + fullname )
1053
+ raise ImportError (self . blacklisted_msg % ( fullname ,) )
1038
1054
1039
1055
f = sys ._getframe (2 )
1040
1056
requestee = f .f_globals ['__name__' ]
@@ -1046,7 +1062,7 @@ def _refuse_imports(self, fullname):
1046
1062
# breaks any app that is not expecting its __main__ to suddenly be
1047
1063
# sucked over a network and injected into a remote process, like
1048
1064
# py.test.
1049
- raise ImportError ('Refused' )
1065
+ raise ImportError (self . pkg_resources_msg )
1050
1066
1051
1067
if fullname == 'pbr' :
1052
1068
# It claims to use pkg_resources to read version information, which
@@ -1106,7 +1122,7 @@ def load_module(self, fullname):
1106
1122
1107
1123
ret = self ._cache [fullname ]
1108
1124
if ret [2 ] is None :
1109
- raise ImportError ('Master does not have %r' % (fullname ,))
1125
+ raise ImportError (self . absent_msg % (fullname ,))
1110
1126
1111
1127
pkg_present = ret [1 ]
1112
1128
mod = sys .modules .setdefault (fullname , imp .new_module (fullname ))
@@ -1139,14 +1155,14 @@ def get_filename(self, fullname):
1139
1155
# reveals the module can't be loaded, and so load_module()
1140
1156
# throws ImportError, on Python 3.x it is still possible for
1141
1157
# the loader to be called to fetch metadata.
1142
- raise ImportError ('master cannot serve %r' % (fullname ,))
1158
+ raise ImportError (self . absent_msg % (fullname ,))
1143
1159
return u'master:' + self ._cache [fullname ][2 ]
1144
1160
1145
1161
def get_source (self , fullname ):
1146
1162
if fullname in self ._cache :
1147
1163
compressed = self ._cache [fullname ][3 ]
1148
1164
if compressed is None :
1149
- raise ImportError ('master cannot serve %r' % (fullname ,))
1165
+ raise ImportError (self . absent_msg % (fullname ,))
1150
1166
1151
1167
source = zlib .decompress (self ._cache [fullname ][3 ])
1152
1168
if PY3 :
0 commit comments