1. youngking
  2. flask-actions

Commits

Young King  committed 1c865e7

add runtwisted

  • Participants
  • Parent commits 35b7ba8
  • Branches default

Comments (0)

Files changed (2)

File flaskext/actions/actions.py

View file
  • Ignore whitespace
 
     return action
 
+def run_twisted_server(app):
+    def action(port=('p', 8000), reactor_type=('r', 1)):
+        """run application use twisted http server
+        @reactor_type: [default 1]
+            1       epoll   reactor
+            2       poll    reactor
+            3       kqueue  reactor
+            4       iocp    reactor
+            other   select  reactor
+        """
+        try:
+            if reactor_type == 1:
+                from twisted.internet import epollreactor
+                epollreactor.install()
+            elif reactor_type == 2:
+                from twisted.internet import pollreactor
+                pollreactor.install()
+            elif reactor_type == 3:
+                from twisted.internet import kqreactor
+                kqreactor.install()
+            elif reactor_type == 4:
+                from twisted.internet import iocpreactor
+                iocpreactor.install()
+            from twisted.internet import reactor
+            from twisted.application import internet, service
+            from twisted.web import server, wsgi
+        except ImportError:
+            print "You need to install twisted"
+            sys.exit()
+
+        application = service.Application('twisted-wsgi') # call this anything you like
+        resource = wsgi.WSGIResource(reactor, reactor.getThreadPool(), app)
+        factory = server.Site(resource)
+        reactor.listenTCP(int(port),factory)
+        reactor.run()
+
+    return action
+
+
 def bshell(app):
     def action():
         """run shell use bpython
                                     use_reloader=True, threaded=True, hostname='0.0.0.0',
                                     port=7777, use_debugger=True),
                 'bshell'    :   bshell(application),
+                'runtwisted'  :   run_twisted_server(application),
+
         }
 
-    def add_action(self, name, action):
-        self._actions[name] = action
+    def add_action(self, name, func):
+        self._actions[name] = func(self.application)
 
     def run(self):
         script.run(self._actions, '')

File setup.py

View file
  • Ignore whitespace
 
 setup(
     name='Flask-Actions',
-    version='0.3',
+    version='0.4',
     url='http://blog.flyzen.com',
     license='BSD',
     author='Young King',