def setup_project():
    from .utils import have_appserver, on_production_server
    if have_appserver:
        # This fixes a pwd import bug for os.path.expanduser()
        env_ext['HOME'] = PROJECT_DIR

    # The dev_appserver creates a sandbox which restricts access to certain
    # modules and builtins in order to emulate the production environment.
    # Here we get the subprocess module back into the dev_appserver sandbox.
    # This module is just too important for development.
    # Also we add the compiler/parser module back and enable https connections
    # (seem to be broken on Windows because the _ssl module is disallowed).
    if not have_appserver:
        from google.appengine.tools import dev_appserver
        try:
            # Backup os.environ. It gets overwritten by the dev_appserver,
            # but it's needed by the subprocess module.
            env = dev_appserver.DEFAULT_ENV
            dev_appserver.DEFAULT_ENV = os.environ.copy()
            dev_appserver.DEFAULT_ENV.update(env)
            # Backup the buffer() builtin. The subprocess in Python 2.5 on
            # Linux and OS X uses needs it, but the dev_appserver removes it.
            dev_appserver.buffer = buffer
        except __HOLE__:
            logging.warn('Could not patch the default environment. '
                         'The subprocess module will not work correctly.')

        try:
            # Allow importing compiler/parser, _ssl (for https),
            # _io for Python 2.7 io support on OS X
            dev_appserver.HardenedModulesHook._WHITE_LIST_C_MODULES.extend(
                ('parser', '_ssl', '_io'))
        except AttributeError:
            logging.warn('Could not patch modules whitelist. '
                         'The compiler and parser modules will not work and '
                         'SSL support is disabled.')
    elif not on_production_server:
        try:
            # Restore the real subprocess module
            from google.appengine.api.mail_stub import subprocess
            sys.modules['subprocess'] = subprocess
            # Re-inject the buffer() builtin into the subprocess module
            from google.appengine.tools import dev_appserver
            subprocess.buffer = dev_appserver.buffer
        except Exception, e:
            logging.warn('Could not add the subprocess module to the sandbox: %s' % e)

    os.environ.update(env_ext)

    extra_paths = [PROJECT_DIR, os.path.join(os.path.dirname(__file__), 'lib')]
    zip_packages_dir = os.path.join(PROJECT_DIR, 'zip-packages')

    # We support zipped packages in the common and project folders.
    if os.path.isdir(zip_packages_dir):
        for zip_package in os.listdir(zip_packages_dir):
            extra_paths.append(os.path.join(zip_packages_dir, zip_package))

    # App Engine causes main.py to be reloaded if an exception gets raised
    # on the first request of a main.py instance, so don't call setup_project()
    # multiple times. We ensure this indirectly by checking if we've already
    # modified sys.path, already.
    if len(sys.path) < len(extra_paths) or \
            sys.path[:len(extra_paths)] != extra_paths:
        for path in extra_paths:
            while path in sys.path:
                sys.path.remove(path)
        sys.path = extra_paths + sys.path
dataset/ETHPy150Open adieu/djangoappengine/boot.py/setup_project