[go: up one dir, main page]

Skip to content

Commit

Permalink
made the AppEngine dev_appserver.py work with StaticPython by prevent…
Browse files Browse the repository at this point in the history
…ing the import of the google.appengine.dist.py_zipimport module
  • Loading branch information
Peter Szabo committed Jan 5, 2012
1 parent 24cf0b9 commit 1937e5b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions site.2.7.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ def setencoding():
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !

def fix_appengine_py_zimpimport():
class StaticPythonImporter(object):
@classmethod
def find_module(cls, fullmodname, path=None):
# Cancel the effect of the py_zipimport module in Google
# AppEngine. py_zipimport installs a .zip import handler which
# can't properly import from /proc/self/exe . The default
# zipimporter is just fine.
if fullmodname == 'google.appengine.dist.py_zipimport':
return cls # Replace it with an empty module.
return None
@classmethod
def load_module(self, fullmodname):
mod = type(sys)(fullmodname)
mod.__name__ = fullmodname
return mod
sys.meta_path[:0] = [StaticPythonImporter]


def main():
setquit()
Expand All @@ -169,6 +187,7 @@ def main():
# this module is run as a script, because this code is executed twice.
if hasattr(sys, "setdefaultencoding"):
del sys.setdefaultencoding
fix_appengine_py_zimpimport()

main()

Expand Down

0 comments on commit 1937e5b

Please sign in to comment.