Compilers should be static when they're just functions; when they're callable objects, they control their own instance of 'self'.
This commit is contained in:
parent
0cfa023bc1
commit
c5f63db5f0
|
@ -2,6 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import marshal
|
import marshal
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
import types
|
||||||
import _imp
|
import _imp
|
||||||
|
|
||||||
if sys.version_info[0:2] in [(3, 3), (3, 4)]:
|
if sys.version_info[0:2] in [(3, 3), (3, 4)]:
|
||||||
|
@ -143,8 +144,12 @@ class PolyFileFinder(FileFinder):
|
||||||
|
|
||||||
newloaderclassname = (suffixes[0].lower().capitalize() +
|
newloaderclassname = (suffixes[0].lower().capitalize() +
|
||||||
str(_PolySourceFileLoader).rpartition('.')[2][1:])
|
str(_PolySourceFileLoader).rpartition('.')[2][1:])
|
||||||
newloader = type(newloaderclassname, (_PolySourceFileLoader,),
|
if isinstance(compiler, types.FunctionType):
|
||||||
dict(_compiler = compiler))
|
newloader = type(newloaderclassname, (_PolySourceFileLoader,),
|
||||||
|
dict(_compiler = staticmethod(compiler)))
|
||||||
|
else:
|
||||||
|
newloader = type(newloaderclassname, (_PolySourceFileLoader,),
|
||||||
|
dict(_compiler = compiler))
|
||||||
cls._custom_loaders += [(EXS + suffix, newloader) for suffix in suffixset]
|
cls._custom_loaders += [(EXS + suffix, newloader) for suffix in suffixset]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -208,7 +213,6 @@ class PolyFileFinder(FileFinder):
|
||||||
def path_hook_for_PolyFileFinder(path):
|
def path_hook_for_PolyFileFinder(path):
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
raise ImportError("only directories are supported", path=path)
|
raise ImportError("only directories are supported", path=path)
|
||||||
print("Returning PolyFileFinder")
|
|
||||||
return PolyFileFinder(path)
|
return PolyFileFinder(path)
|
||||||
return path_hook_for_PolyFileFinder
|
return path_hook_for_PolyFileFinder
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ class Compiler:
|
||||||
self.pt = pt
|
self.pt = pt
|
||||||
|
|
||||||
def __call__(self, source_text, filename, *extra):
|
def __call__(self, source_text, filename, *extra):
|
||||||
print(type(source_text))
|
|
||||||
return compile("result='Success for %s: %s'" %
|
return compile("result='Success for %s: %s'" %
|
||||||
(self.pt, source_text.decode('utf-8').rstrip()), filename, "exec")
|
(self.pt, source_text.decode('utf-8').rstrip()), filename, "exec")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue