We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
add PYTHONSTARTUP support to pshell
Currently pshell does not source any `.pystartup` file pointed to by the `PYTHONSTARTUP` environment variable. It'd be nice to support this.

https://docs.python.org/2/tutorial/interpreter.html#the-interactive-startup-file


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyramid/scripts/pshell.py`
Content:
```
1 from code import interact
2 import optparse
3 import sys
4 import textwrap
5 
6 from pyramid.compat import configparser
7 from pyramid.util import DottedNameResolver
8 from pyramid.paster import bootstrap
9 
10 from pyramid.paster import setup_logging
11 
12 from pyramid.scripts.common import parse_vars
13 
14 def main(argv=sys.argv, quiet=False):
15     command = PShellCommand(argv, quiet)
16     return command.run()
17 
18 class PShellCommand(object):
19     usage = '%prog config_uri'
20     description = """\
21     Open an interactive shell with a Pyramid app loaded.  This command
22     accepts one positional argument named "config_uri" which specifies the
23     PasteDeploy config file to use for the interactive shell. The format is
24     "inifile#name". If the name is left off, the Pyramid default application
25     will be assumed.  Example: "pshell myapp.ini#main"
26 
27     If you do not point the loader directly at the section of the ini file
28     containing your Pyramid application, the command will attempt to
29     find the app for you. If you are loading a pipeline that contains more
30     than one Pyramid application within it, the loader will use the
31     last one.
32     """
33     bootstrap = (bootstrap,) # for testing
34 
35     parser = optparse.OptionParser(
36         usage,
37         description=textwrap.dedent(description)
38         )
39     parser.add_option('-p', '--python-shell',
40                       action='store', type='string', dest='python_shell',
41                       default='', help='ipython | bpython | python')
42     parser.add_option('--setup',
43                       dest='setup',
44                       help=("A callable that will be passed the environment "
45                             "before it is made available to the shell. This "
46                             "option will override the 'setup' key in the "
47                             "[pshell] ini section."))
48 
49     ConfigParser = configparser.ConfigParser # testing
50 
51     loaded_objects = {}
52     object_help = {}
53     setup = None
54 
55     def __init__(self, argv, quiet=False):
56         self.quiet = quiet
57         self.options, self.args = self.parser.parse_args(argv[1:])
58 
59     def pshell_file_config(self, filename):
60         config = self.ConfigParser()
61         config.read(filename)
62         try:
63             items = config.items('pshell')
64         except configparser.NoSectionError:
65             return
66 
67         resolver = DottedNameResolver(None)
68         self.loaded_objects = {}
69         self.object_help = {}
70         self.setup = None
71         for k, v in items:
72             if k == 'setup':
73                 self.setup = v
74             else:
75                 self.loaded_objects[k] = resolver.maybe_resolve(v)
76                 self.object_help[k] = v
77 
78     def out(self, msg): # pragma: no cover
79         if not self.quiet:
80             print(msg)
81 
82     def run(self, shell=None):
83         if not self.args:
84             self.out('Requires a config file argument')
85             return 2
86         config_uri = self.args[0]
87         config_file = config_uri.split('#', 1)[0]
88         setup_logging(config_file)
89         self.pshell_file_config(config_file)
90 
91         # bootstrap the environ
92         env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:]))
93 
94         # remove the closer from the env
95         closer = env.pop('closer')
96 
97         # setup help text for default environment
98         env_help = dict(env)
99         env_help['app'] = 'The WSGI application.'
100         env_help['root'] = 'Root of the default resource tree.'
101         env_help['registry'] = 'Active Pyramid registry.'
102         env_help['request'] = 'Active request object.'
103         env_help['root_factory'] = (
104             'Default root factory used to create `root`.')
105 
106         # override use_script with command-line options
107         if self.options.setup:
108             self.setup = self.options.setup
109 
110         if self.setup:
111             # store the env before muddling it with the script
112             orig_env = env.copy()
113 
114             # call the setup callable
115             resolver = DottedNameResolver(None)
116             setup = resolver.maybe_resolve(self.setup)
117             setup(env)
118 
119             # remove any objects from default help that were overidden
120             for k, v in env.items():
121                 if k not in orig_env or env[k] != orig_env[k]:
122                     env_help[k] = v
123 
124         # load the pshell section of the ini file
125         env.update(self.loaded_objects)
126 
127         # eliminate duplicates from env, allowing custom vars to override
128         for k in self.loaded_objects:
129             if k in env_help:
130                 del env_help[k]
131 
132         # generate help text
133         help = ''
134         if env_help:
135             help += 'Environment:'
136             for var in sorted(env_help.keys()):
137                 help += '\n  %-12s %s' % (var, env_help[var])
138 
139         if self.object_help:
140             help += '\n\nCustom Variables:'
141             for var in sorted(self.object_help.keys()):
142                 help += '\n  %-12s %s' % (var, self.object_help[var])
143 
144         if shell is None:
145             shell = self.make_shell()
146 
147         try:
148             shell(env, help)
149         finally:
150             closer()
151 
152     def make_shell(self):
153         shell = None
154         user_shell = self.options.python_shell.lower()
155         if not user_shell:
156             shell = self.make_ipython_shell()
157             if shell is None:
158                 shell = self.make_bpython_shell()
159 
160         elif user_shell == 'ipython':
161             shell = self.make_ipython_shell()
162 
163         elif user_shell == 'bpython':
164             shell = self.make_bpython_shell()
165 
166         if shell is None:
167             shell = self.make_default_shell()
168 
169         return shell
170 
171     def make_default_shell(self, interact=interact):
172         def shell(env, help):
173             cprt = 'Type "help" for more information.'
174             banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt)
175             banner += '\n\n' + help + '\n'
176             interact(banner, local=env)
177         return shell
178 
179     def make_bpython_shell(self, BPShell=None):
180         if BPShell is None: # pragma: no cover
181             try:
182                 from bpython import embed
183                 BPShell = embed
184             except ImportError:
185                 return None
186         def shell(env, help):
187             BPShell(locals_=env, banner=help + '\n')
188         return shell
189 
190     def make_ipython_shell(self):
191         shell = self.make_ipython_v1_1_shell()
192         if shell is None:
193             shell = self.make_ipython_v0_11_shell()
194         if shell is None:
195             shell = self.make_ipython_v0_10_shell()
196         return shell
197 
198     def make_ipython_v1_1_shell(self, IPShellFactory=None):
199         if IPShellFactory is None: # pragma: no cover
200             try:
201                 from IPython.terminal.embed import (
202                     InteractiveShellEmbed)
203                 IPShellFactory = InteractiveShellEmbed
204             except ImportError:
205                 return None
206         def shell(env, help):
207             IPShell = IPShellFactory(banner2=help + '\n', user_ns=env)
208             IPShell()
209         return shell
210 
211     def make_ipython_v0_11_shell(self, IPShellFactory=None):
212         if IPShellFactory is None: # pragma: no cover
213             try:
214                 from IPython.frontend.terminal.embed import (
215                     InteractiveShellEmbed)
216                 IPShellFactory = InteractiveShellEmbed
217             except ImportError:
218                 return None
219         def shell(env, help):
220             IPShell = IPShellFactory(banner2=help + '\n', user_ns=env)
221             IPShell()
222         return shell
223 
224     def make_ipython_v0_10_shell(self, IPShellFactory=None):
225         if IPShellFactory is None: # pragma: no cover
226             try:
227                 from IPython.Shell import IPShellEmbed
228                 IPShellFactory = IPShellEmbed
229             except ImportError:
230                 return None
231         def shell(env, help):
232             IPShell = IPShellFactory(argv=[], user_ns=env)
233             IPShell.set_banner(IPShell.IP.BANNER + '\n' + help + '\n')
234             IPShell()
235         return shell
236 
237 if __name__ == '__main__': # pragma: no cover
238     sys.exit(main() or 0)
239
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py
--- a/pyramid/scripts/pshell.py
+++ b/pyramid/scripts/pshell.py
@@ -1,9 +1,11 @@
 from code import interact
 import optparse
+import os
 import sys
 import textwrap
 
 from pyramid.compat import configparser
+from pyramid.compat import exec_
 from pyramid.util import DottedNameResolver
 from pyramid.paster import bootstrap
 
@@ -51,6 +53,7 @@
     loaded_objects = {}
     object_help = {}
     setup = None
+    pystartup = os.environ.get('PYTHONSTARTUP')
 
     def __init__(self, argv, quiet=False):
         self.quiet = quiet
@@ -144,6 +147,12 @@
         if shell is None:
             shell = self.make_shell()
 
+        if self.pystartup and os.path.isfile(self.pystartup):
+            with open(self.pystartup, 'rb') as fp:
+                exec_(fp.read().decode('utf-8'), env)
+            if '__builtins__' in env:
+                del env['__builtins__']
+
         try:
             shell(env, help)
         finally:

{"golden_diff": "diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py\n--- a/pyramid/scripts/pshell.py\n+++ b/pyramid/scripts/pshell.py\n@@ -1,9 +1,11 @@\n from code import interact\n import optparse\n+import os\n import sys\n import textwrap\n \n from pyramid.compat import configparser\n+from pyramid.compat import exec_\n from pyramid.util import DottedNameResolver\n from pyramid.paster import bootstrap\n \n@@ -51,6 +53,7 @@\n     loaded_objects = {}\n     object_help = {}\n     setup = None\n+    pystartup = os.environ.get('PYTHONSTARTUP')\n \n     def __init__(self, argv, quiet=False):\n         self.quiet = quiet\n@@ -144,6 +147,12 @@\n         if shell is None:\n             shell = self.make_shell()\n \n+        if self.pystartup and os.path.isfile(self.pystartup):\n+            with open(self.pystartup, 'rb') as fp:\n+                exec_(fp.read().decode('utf-8'), env)\n+            if '__builtins__' in env:\n+                del env['__builtins__']\n+\n         try:\n             shell(env, help)\n         finally:\n", "issue": "add PYTHONSTARTUP support to pshell\nCurrently pshell does not source any `.pystartup` file pointed to by the `PYTHONSTARTUP` environment variable. It'd be nice to support this.\n\nhttps://docs.python.org/2/tutorial/interpreter.html#the-interactive-startup-file\n\n", "before_files": [{"content": "from code import interact\nimport optparse\nimport sys\nimport textwrap\n\nfrom pyramid.compat import configparser\nfrom pyramid.util import DottedNameResolver\nfrom pyramid.paster import bootstrap\n\nfrom pyramid.paster import setup_logging\n\nfrom pyramid.scripts.common import parse_vars\n\ndef main(argv=sys.argv, quiet=False):\n    command = PShellCommand(argv, quiet)\n    return command.run()\n\nclass PShellCommand(object):\n    usage = '%prog config_uri'\n    description = \"\"\"\\\n    Open an interactive shell with a Pyramid app loaded.  This command\n    accepts one positional argument named \"config_uri\" which specifies the\n    PasteDeploy config file to use for the interactive shell. The format is\n    \"inifile#name\". If the name is left off, the Pyramid default application\n    will be assumed.  Example: \"pshell myapp.ini#main\"\n\n    If you do not point the loader directly at the section of the ini file\n    containing your Pyramid application, the command will attempt to\n    find the app for you. If you are loading a pipeline that contains more\n    than one Pyramid application within it, the loader will use the\n    last one.\n    \"\"\"\n    bootstrap = (bootstrap,) # for testing\n\n    parser = optparse.OptionParser(\n        usage,\n        description=textwrap.dedent(description)\n        )\n    parser.add_option('-p', '--python-shell',\n                      action='store', type='string', dest='python_shell',\n                      default='', help='ipython | bpython | python')\n    parser.add_option('--setup',\n                      dest='setup',\n                      help=(\"A callable that will be passed the environment \"\n                            \"before it is made available to the shell. This \"\n                            \"option will override the 'setup' key in the \"\n                            \"[pshell] ini section.\"))\n\n    ConfigParser = configparser.ConfigParser # testing\n\n    loaded_objects = {}\n    object_help = {}\n    setup = None\n\n    def __init__(self, argv, quiet=False):\n        self.quiet = quiet\n        self.options, self.args = self.parser.parse_args(argv[1:])\n\n    def pshell_file_config(self, filename):\n        config = self.ConfigParser()\n        config.read(filename)\n        try:\n            items = config.items('pshell')\n        except configparser.NoSectionError:\n            return\n\n        resolver = DottedNameResolver(None)\n        self.loaded_objects = {}\n        self.object_help = {}\n        self.setup = None\n        for k, v in items:\n            if k == 'setup':\n                self.setup = v\n            else:\n                self.loaded_objects[k] = resolver.maybe_resolve(v)\n                self.object_help[k] = v\n\n    def out(self, msg): # pragma: no cover\n        if not self.quiet:\n            print(msg)\n\n    def run(self, shell=None):\n        if not self.args:\n            self.out('Requires a config file argument')\n            return 2\n        config_uri = self.args[0]\n        config_file = config_uri.split('#', 1)[0]\n        setup_logging(config_file)\n        self.pshell_file_config(config_file)\n\n        # bootstrap the environ\n        env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:]))\n\n        # remove the closer from the env\n        closer = env.pop('closer')\n\n        # setup help text for default environment\n        env_help = dict(env)\n        env_help['app'] = 'The WSGI application.'\n        env_help['root'] = 'Root of the default resource tree.'\n        env_help['registry'] = 'Active Pyramid registry.'\n        env_help['request'] = 'Active request object.'\n        env_help['root_factory'] = (\n            'Default root factory used to create `root`.')\n\n        # override use_script with command-line options\n        if self.options.setup:\n            self.setup = self.options.setup\n\n        if self.setup:\n            # store the env before muddling it with the script\n            orig_env = env.copy()\n\n            # call the setup callable\n            resolver = DottedNameResolver(None)\n            setup = resolver.maybe_resolve(self.setup)\n            setup(env)\n\n            # remove any objects from default help that were overidden\n            for k, v in env.items():\n                if k not in orig_env or env[k] != orig_env[k]:\n                    env_help[k] = v\n\n        # load the pshell section of the ini file\n        env.update(self.loaded_objects)\n\n        # eliminate duplicates from env, allowing custom vars to override\n        for k in self.loaded_objects:\n            if k in env_help:\n                del env_help[k]\n\n        # generate help text\n        help = ''\n        if env_help:\n            help += 'Environment:'\n            for var in sorted(env_help.keys()):\n                help += '\\n  %-12s %s' % (var, env_help[var])\n\n        if self.object_help:\n            help += '\\n\\nCustom Variables:'\n            for var in sorted(self.object_help.keys()):\n                help += '\\n  %-12s %s' % (var, self.object_help[var])\n\n        if shell is None:\n            shell = self.make_shell()\n\n        try:\n            shell(env, help)\n        finally:\n            closer()\n\n    def make_shell(self):\n        shell = None\n        user_shell = self.options.python_shell.lower()\n        if not user_shell:\n            shell = self.make_ipython_shell()\n            if shell is None:\n                shell = self.make_bpython_shell()\n\n        elif user_shell == 'ipython':\n            shell = self.make_ipython_shell()\n\n        elif user_shell == 'bpython':\n            shell = self.make_bpython_shell()\n\n        if shell is None:\n            shell = self.make_default_shell()\n\n        return shell\n\n    def make_default_shell(self, interact=interact):\n        def shell(env, help):\n            cprt = 'Type \"help\" for more information.'\n            banner = \"Python %s on %s\\n%s\" % (sys.version, sys.platform, cprt)\n            banner += '\\n\\n' + help + '\\n'\n            interact(banner, local=env)\n        return shell\n\n    def make_bpython_shell(self, BPShell=None):\n        if BPShell is None: # pragma: no cover\n            try:\n                from bpython import embed\n                BPShell = embed\n            except ImportError:\n                return None\n        def shell(env, help):\n            BPShell(locals_=env, banner=help + '\\n')\n        return shell\n\n    def make_ipython_shell(self):\n        shell = self.make_ipython_v1_1_shell()\n        if shell is None:\n            shell = self.make_ipython_v0_11_shell()\n        if shell is None:\n            shell = self.make_ipython_v0_10_shell()\n        return shell\n\n    def make_ipython_v1_1_shell(self, IPShellFactory=None):\n        if IPShellFactory is None: # pragma: no cover\n            try:\n                from IPython.terminal.embed import (\n                    InteractiveShellEmbed)\n                IPShellFactory = InteractiveShellEmbed\n            except ImportError:\n                return None\n        def shell(env, help):\n            IPShell = IPShellFactory(banner2=help + '\\n', user_ns=env)\n            IPShell()\n        return shell\n\n    def make_ipython_v0_11_shell(self, IPShellFactory=None):\n        if IPShellFactory is None: # pragma: no cover\n            try:\n                from IPython.frontend.terminal.embed import (\n                    InteractiveShellEmbed)\n                IPShellFactory = InteractiveShellEmbed\n            except ImportError:\n                return None\n        def shell(env, help):\n            IPShell = IPShellFactory(banner2=help + '\\n', user_ns=env)\n            IPShell()\n        return shell\n\n    def make_ipython_v0_10_shell(self, IPShellFactory=None):\n        if IPShellFactory is None: # pragma: no cover\n            try:\n                from IPython.Shell import IPShellEmbed\n                IPShellFactory = IPShellEmbed\n            except ImportError:\n                return None\n        def shell(env, help):\n            IPShell = IPShellFactory(argv=[], user_ns=env)\n            IPShell.set_banner(IPShell.IP.BANNER + '\\n' + help + '\\n')\n            IPShell()\n        return shell\n\nif __name__ == '__main__': # pragma: no cover\n    sys.exit(main() or 0)\n", "path": "pyramid/scripts/pshell.py"}], "after_files": [{"content": "from code import interact\nimport optparse\nimport os\nimport sys\nimport textwrap\n\nfrom pyramid.compat import configparser\nfrom pyramid.compat import exec_\nfrom pyramid.util import DottedNameResolver\nfrom pyramid.paster import bootstrap\n\nfrom pyramid.paster import setup_logging\n\nfrom pyramid.scripts.common import parse_vars\n\ndef main(argv=sys.argv, quiet=False):\n    command = PShellCommand(argv, quiet)\n    return command.run()\n\nclass PShellCommand(object):\n    usage = '%prog config_uri'\n    description = \"\"\"\\\n    Open an interactive shell with a Pyramid app loaded.  This command\n    accepts one positional argument named \"config_uri\" which specifies the\n    PasteDeploy config file to use for the interactive shell. The format is\n    \"inifile#name\". If the name is left off, the Pyramid default application\n    will be assumed.  Example: \"pshell myapp.ini#main\"\n\n    If you do not point the loader directly at the section of the ini file\n    containing your Pyramid application, the command will attempt to\n    find the app for you. If you are loading a pipeline that contains more\n    than one Pyramid application within it, the loader will use the\n    last one.\n    \"\"\"\n    bootstrap = (bootstrap,) # for testing\n\n    parser = optparse.OptionParser(\n        usage,\n        description=textwrap.dedent(description)\n        )\n    parser.add_option('-p', '--python-shell',\n                      action='store', type='string', dest='python_shell',\n                      default='', help='ipython | bpython | python')\n    parser.add_option('--setup',\n                      dest='setup',\n                      help=(\"A callable that will be passed the environment \"\n                            \"before it is made available to the shell. This \"\n                            \"option will override the 'setup' key in the \"\n                            \"[pshell] ini section.\"))\n\n    ConfigParser = configparser.ConfigParser # testing\n\n    loaded_objects = {}\n    object_help = {}\n    setup = None\n    pystartup = os.environ.get('PYTHONSTARTUP')\n\n    def __init__(self, argv, quiet=False):\n        self.quiet = quiet\n        self.options, self.args = self.parser.parse_args(argv[1:])\n\n    def pshell_file_config(self, filename):\n        config = self.ConfigParser()\n        config.read(filename)\n        try:\n            items = config.items('pshell')\n        except configparser.NoSectionError:\n            return\n\n        resolver = DottedNameResolver(None)\n        self.loaded_objects = {}\n        self.object_help = {}\n        self.setup = None\n        for k, v in items:\n            if k == 'setup':\n                self.setup = v\n            else:\n                self.loaded_objects[k] = resolver.maybe_resolve(v)\n                self.object_help[k] = v\n\n    def out(self, msg): # pragma: no cover\n        if not self.quiet:\n            print(msg)\n\n    def run(self, shell=None):\n        if not self.args:\n            self.out('Requires a config file argument')\n            return 2\n        config_uri = self.args[0]\n        config_file = config_uri.split('#', 1)[0]\n        setup_logging(config_file)\n        self.pshell_file_config(config_file)\n\n        # bootstrap the environ\n        env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:]))\n\n        # remove the closer from the env\n        closer = env.pop('closer')\n\n        # setup help text for default environment\n        env_help = dict(env)\n        env_help['app'] = 'The WSGI application.'\n        env_help['root'] = 'Root of the default resource tree.'\n        env_help['registry'] = 'Active Pyramid registry.'\n        env_help['request'] = 'Active request object.'\n        env_help['root_factory'] = (\n            'Default root factory used to create `root`.')\n\n        # override use_script with command-line options\n        if self.options.setup:\n            self.setup = self.options.setup\n\n        if self.setup:\n            # store the env before muddling it with the script\n            orig_env = env.copy()\n\n            # call the setup callable\n            resolver = DottedNameResolver(None)\n            setup = resolver.maybe_resolve(self.setup)\n            setup(env)\n\n            # remove any objects from default help that were overidden\n            for k, v in env.items():\n                if k not in orig_env or env[k] != orig_env[k]:\n                    env_help[k] = v\n\n        # load the pshell section of the ini file\n        env.update(self.loaded_objects)\n\n        # eliminate duplicates from env, allowing custom vars to override\n        for k in self.loaded_objects:\n            if k in env_help:\n                del env_help[k]\n\n        # generate help text\n        help = ''\n        if env_help:\n            help += 'Environment:'\n            for var in sorted(env_help.keys()):\n                help += '\\n  %-12s %s' % (var, env_help[var])\n\n        if self.object_help:\n            help += '\\n\\nCustom Variables:'\n            for var in sorted(self.object_help.keys()):\n                help += '\\n  %-12s %s' % (var, self.object_help[var])\n\n        if shell is None:\n            shell = self.make_shell()\n\n        if self.pystartup and os.path.isfile(self.pystartup):\n            with open(self.pystartup, 'rb') as fp:\n                exec_(fp.read().decode('utf-8'), env)\n            if '__builtins__' in env:\n                del env['__builtins__']\n\n        try:\n            shell(env, help)\n        finally:\n            closer()\n\n    def make_shell(self):\n        shell = None\n        user_shell = self.options.python_shell.lower()\n        if not user_shell:\n            shell = self.make_ipython_shell()\n            if shell is None:\n                shell = self.make_bpython_shell()\n\n        elif user_shell == 'ipython':\n            shell = self.make_ipython_shell()\n\n        elif user_shell == 'bpython':\n            shell = self.make_bpython_shell()\n\n        if shell is None:\n            shell = self.make_default_shell()\n\n        return shell\n\n    def make_default_shell(self, interact=interact):\n        def shell(env, help):\n            cprt = 'Type \"help\" for more information.'\n            banner = \"Python %s on %s\\n%s\" % (sys.version, sys.platform, cprt)\n            banner += '\\n\\n' + help + '\\n'\n            interact(banner, local=env)\n        return shell\n\n    def make_bpython_shell(self, BPShell=None):\n        if BPShell is None: # pragma: no cover\n            try:\n                from bpython import embed\n                BPShell = embed\n            except ImportError:\n                return None\n        def shell(env, help):\n            BPShell(locals_=env, banner=help + '\\n')\n        return shell\n\n    def make_ipython_shell(self):\n        shell = self.make_ipython_v1_1_shell()\n        if shell is None:\n            shell = self.make_ipython_v0_11_shell()\n        if shell is None:\n            shell = self.make_ipython_v0_10_shell()\n        return shell\n\n    def make_ipython_v1_1_shell(self, IPShellFactory=None):\n        if IPShellFactory is None: # pragma: no cover\n            try:\n                from IPython.terminal.embed import (\n                    InteractiveShellEmbed)\n                IPShellFactory = InteractiveShellEmbed\n            except ImportError:\n                return None\n        def shell(env, help):\n            IPShell = IPShellFactory(banner2=help + '\\n', user_ns=env)\n            IPShell()\n        return shell\n\n    def make_ipython_v0_11_shell(self, IPShellFactory=None):\n        if IPShellFactory is None: # pragma: no cover\n            try:\n                from IPython.frontend.terminal.embed import (\n                    InteractiveShellEmbed)\n                IPShellFactory = InteractiveShellEmbed\n            except ImportError:\n                return None\n        def shell(env, help):\n            IPShell = IPShellFactory(banner2=help + '\\n', user_ns=env)\n            IPShell()\n        return shell\n\n    def make_ipython_v0_10_shell(self, IPShellFactory=None):\n        if IPShellFactory is None: # pragma: no cover\n            try:\n                from IPython.Shell import IPShellEmbed\n                IPShellFactory = IPShellEmbed\n            except ImportError:\n                return None\n        def shell(env, help):\n            IPShell = IPShellFactory(argv=[], user_ns=env)\n            IPShell.set_banner(IPShell.IP.BANNER + '\\n' + help + '\\n')\n            IPShell()\n        return shell\n\nif __name__ == '__main__': # pragma: no cover\n    sys.exit(main() or 0)\n", "path": "pyramid/scripts/pshell.py"}]}