Commits

Fabio Montefuscolo committed 1f3d664 Merge

workaround in flask-script command to run in ipython 0.10 and 0.11

  • Participants
  • Parent commits 2256d29, 7d91132

Comments (0)

Files changed (3)

File MoinMoin/converter/_tests/test_include.py

 import pytest
 
 from MoinMoin.converter.include import *
+from MoinMoin.items import MoinWiki
+from MoinMoin.config import CONTENTTYPE
+from MoinMoin._tests import wikiconfig, update_item
 
-def test_XPointer():
-    x = XPointer('a')
-    assert len(x) == 1
-    e = x[0]
-    assert e.name == 'a'
-    assert e.data is None
+class TestInclude(object):
+    class Config(wikiconfig.Config):
+        """
+        we just have this so the test framework creates a new app with empty backends for us.
+        """
 
-    x = XPointer('a(b)')
-    assert len(x) == 1
-    e = x[0]
-    assert e.name == 'a'
-    assert e.data == 'b'
+    def test_XPointer(self):
+        x = XPointer('a')
+        assert len(x) == 1
+        e = x[0]
+        assert e.name == 'a'
+        assert e.data is None
 
-    x = XPointer('a(^(b^)^^)')
-    assert len(x) == 1
-    e = x[0]
-    assert e.name == 'a'
-    assert e.data == '^(b^)^^'
-    assert e.data_unescape == '(b)^'
+        x = XPointer('a(b)')
+        assert len(x) == 1
+        e = x[0]
+        assert e.name == 'a'
+        assert e.data == 'b'
 
-    x = XPointer('a(b)c(d)')
-    assert len(x) == 2
-    e = x[0]
-    assert e.name == 'a'
-    assert e.data == 'b'
-    e = x[1]
-    assert e.name == 'c'
-    assert e.data == 'd'
+        x = XPointer('a(^(b^)^^)')
+        assert len(x) == 1
+        e = x[0]
+        assert e.name == 'a'
+        assert e.data == '^(b^)^^'
+        assert e.data_unescape == '(b)^'
 
-    x = XPointer('a(b) c(d)')
-    assert len(x) == 2
-    e = x[0]
-    assert e.name == 'a'
-    assert e.data == 'b'
-    e = x[1]
-    assert e.name == 'c'
-    assert e.data == 'd'
+        x = XPointer('a(b)c(d)')
+        assert len(x) == 2
+        e = x[0]
+        assert e.name == 'a'
+        assert e.data == 'b'
+        e = x[1]
+        assert e.name == 'c'
+        assert e.data == 'd'
 
-    x = XPointer('a(a(b))')
-    assert len(x) == 1
-    e = x[0]
-    assert e.name == 'a'
-    assert e.data == 'a(b)'
+        x = XPointer('a(b) c(d)')
+        assert len(x) == 2
+        e = x[0]
+        assert e.name == 'a'
+        assert e.data == 'b'
+        e = x[1]
+        assert e.name == 'c'
+        assert e.data == 'd'
 
+        x = XPointer('a(a(b))')
+        assert len(x) == 1
+        e = x[0]
+        assert e.name == 'a'
+        assert e.data == 'a(b)'
+
+    def test_IncludeHandlesCircularRecursion(self):
+        # issue #80
+        # we choosed MoinWiki items so tests get simpler
+        update_item(u'page1', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page2}}')
+        update_item(u'page2', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page3}}')
+        update_item(u'page3', {CONTENTTYPE: u'text/x.moin.wiki'}, u'{{page1}}')
+
+        page1 = MoinWiki.create(u'page1')
+
+        page1._render_data()

File MoinMoin/script/__init__.py

     manager.add_command("import19", ImportMoin19())
 
     from MoinMoin.script.maint.moinshell import MoinShell
-    manager.add_command("moinshell", MoinShell())
+    manager.add_command("shell", MoinShell())
 
     return manager.run(default_command=default_command)
 

File MoinMoin/script/maint/moinshell.py

 from flaskext.script import Command, Option
 
 from MoinMoin import user
+from MoinMoin.app import before_wiki
 from MoinMoin.util.clock import Clock
 
 class MoinShell(Command):
-
     """
     Runs a Python shell inside Flask application context.
 
                         line by passing the **--no-ipython** flag.
     """
 
-    banner = ''
+    banner = u'Objects "flaskg" and "app" is in context.'
 
     description = 'Runs a Python shell inside Flask application context.'
-    
+
     def __init__(self, banner=None, make_context=None, use_ipython=True):
 
 
 
         if make_context is None:
             def make_context():
-                app = _request_ctx_stack.top.app
-                flaskg.unprotected_storage = app.storage
-                flaskg.groups = app.cfg.groups()
-                flaskg.storage = app.storage
-                flaskg.user = user.User()
-                flaskg.clock = Clock()
+                before_wiki()
                 return dict(app=app, flaskg=flaskg)
 
         self.make_context = make_context
-    
+
     def get_options(self):
 
         return (
                        default=not(self.use_ipython)),)
 
     def get_context(self):
-        
         """
         Returns a dict of context variables added to the shell namespace.
         """
         Runs the shell. Unless no_ipython is True or use_python is False
         then runs IPython shell if that is installed.
         """
-        
+        context = self.get_context()
+        if not no_ipython:
+            try:
+                # IPython < 0.11
+                import IPython
+                sh = IPython.Shell.IPShellEmbed(banner=self.banner)
+                sh(global_ns=dict(), local_ns=context)
+                return
+            except ImportError:
+                # IPython = 0.11
+                import IPython
+                sh = IPython.embed(banner2=self.banner, user_ns=context)
+                sh()
+            finally:
+                pass
 
-        context = self.get_context()
-
-        from IPython import embed
-
-        embed()
-
+        code.interact(self.banner, local=context)