Exemple #1
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(fapws.base)
    evwsgi.wsgi_cb(("", generic))
    evwsgi.set_debug(0)
    print "libev ABI version:%i.%i" % evwsgi.libev_version()
    evwsgi.run()
Exemple #2
0
def start():
    if socket_server:
        evwsgi.start("\0/org/fapws3/server", "unix")
    else:
        evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(mybase)

    evwsgi.wsgi_cb(("/env", env))
    evwsgi.wsgi_cb(("/helloclass", helloclass("!!!")))
    evwsgi.wsgi_cb(("/hello", hello))
    evwsgi.wsgi_cb(("/tuplehello", tuplehello))
    evwsgi.wsgi_cb(("/iterhello", iteration))
    evwsgi.wsgi_cb(("/longzipped", staticlongzipped))
    evwsgi.wsgi_cb(("/long", staticlong))
    evwsgi.wsgi_cb(("/elong", embedlong))
    evwsgi.wsgi_cb(("/short", staticshort))
    staticform = views.Staticfile("test.html")
    evwsgi.wsgi_cb(("/staticform", staticform))
    evwsgi.wsgi_cb(("/testpost", testpost))
    evwsgi.wsgi_cb(("/badscript", badscript))
    evwsgi.wsgi_cb(("/returnnone", returnnone))
    evwsgi.wsgi_cb(("/returnnull", returnnull))
    evwsgi.wsgi_cb(("/returniternull", returniternull))

    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #3
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(base)
    
    def hello(environ, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return ["hello world!!"]

    @log.Log()
    def staticlong(environ, start_response):
        try:
            f=open("long.txt", "rb")
        except:
            f=["Page not found"]
        start_response('200 OK', [('Content-Type','text/html')])
        return f
    def embedlong(environ, start_response):
        try:
            c=open("long.txt", "rb").read()
        except:
            c=["Page not found"]
        start_response('200 OK', [('Content-Type','text/html')])
        return base.split_len(c,32768)
    def staticshort(environ, start_response):
        f=open("short.txt", "rb")
        start_response('200 OK', [('Content-Type','text/html')])
        return f
    def testpost(environ, start_response):
        print environ
        print "INPUT DATA",environ["wsgi.input"].getvalue()
        return ["OK. params are:%s" % (environ["fapws.params"])]

    @log.Log()
    @zip.Gzip()    
    def staticlongzipped(environ, start_response):
        try:
            f=open("long.txt", "rb")
        except:
            f=["Page not found"]
        start_response('200 OK', [('Content-Type','text/html')])
        return f
    def iteration(environ, start_response):
        start_response('200 OK', [('Content-Type','text/plain')])
        yield "hello"
        yield " "
        yield "worlds!!"

    
    evwsgi.wsgi_cb(("/hello", hello))
    evwsgi.wsgi_cb(("/iterhello", iteration))
    evwsgi.wsgi_cb(("/longzipped", staticlongzipped))
    evwsgi.wsgi_cb(("/long", staticlong))
    evwsgi.wsgi_cb(("/elong", embedlong))
    evwsgi.wsgi_cb(("/short", staticshort))
    staticform=views.Staticfile("test.html")
    evwsgi.wsgi_cb(("/staticform", staticform))
    evwsgi.wsgi_cb(("/testpost", testpost))

    evwsgi.set_debug(0)    
    evwsgi.run()
Exemple #4
0
def start():
    evwsgi.start(
        os.getenv('FAVIEW_IP', '0.0.0.0'),
        os.getenv('FAVIEW_PORT', '8080'),
    )
    evwsgi.set_base_module(base)

    for local_path, real_path in MEDIA_PREFIX.iteritems():
        media_dir = ServeStatic(
            settings.MEDIA_ROOT + local_path,
            real_path,
            maxage = 2629000,
        )
        evwsgi.wsgi_cb((
            settings.MEDIA_URL + local_path,
            media_dir,
        ))

    def generic(environ, start_response):
        res = django_handler.handler(environ, start_response)
        return [res]

    evwsgi.wsgi_cb(('', generic))
    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #5
0
def run_server(app, host, port):
    from fapws import base
    from fapws._evwsgi import start, set_base_module, wsgi_cb, run
    start(host, str(port))
    set_base_module(base)
    wsgi_cb(('/', app))
    run()
def start():
	evwsgi.start('0.0.0.0', '80') 
	evwsgi.set_base_module(base)
	
	#TODO - should read /etc/cobbler/settings and provide
	#any global parameters
	#settings = open(fileloc, 'r')
	#parse the file
	#settings.close()
	
	def sysname(environ, start_response):
		#you might need to strip fully qualified domain
		#if you don't have them in your cobbler install
		hostname = str(environ['PATH_INFO']).split('.')[0]

		fileloc = '/var/lib/cobbler/config/systems.d/' \
			+ hostname + '.json'
		out = {}
		try:	
			sys = open(fileloc, 'r')
			system = json.load(sys)
			sys.close()
			mp = system['mgmt_parameters']
			km = system['ks_meta']
			mp.update(km)
			out['parameters'] = mp
			out['classes'] = system['mgmt_classes']
			out['classes'] = system['mgmt_classes']
		except IOError, e:
			out['parameters'] = []
			out['classes'] = []
			
		outprint = yaml.safe_dump(out, default_flow_style=True)
		start_response('200 OK', [('Content-Type','text/html')])
		return[outprint]
Exemple #7
0
def fork_main(child_no=1):
	print 'parent:', os.getpid()

	def create_shared():
		return {'name': 'realtime'}

	channels = create_shared()
	posh.share(channels)

	evwsgi.start('0.0.0.0', '8080')
	evwsgi.set_base_module(base)

	child = list()
	for i in range(child_no):
		child.append(posh.forkcall(start, i, channels))

	def on_interrupt(signum, frame):
		print 'terminating %i children' % len(child)
		for pid in child:
			print 'kill(%i)' % pid
			os.kill(pid, signal.SIGINT)
	signal.signal(signal.SIGINT, on_interrupt)

	print 'forked %i childs' % len(child)
	posh.waitall()
Exemple #8
0
def start():
    if socket_server:
        evwsgi.start("\0/org/fapws3/server", "unix")
    else:
        evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(mybase)
    
 
    evwsgi.wsgi_cb(("/env", env))
    evwsgi.wsgi_cb(("/helloclass", helloclass("!!!")))
    evwsgi.wsgi_cb(("/hello", hello))
    evwsgi.wsgi_cb(("/tuplehello", tuplehello))
    evwsgi.wsgi_cb(("/iterhello", iteration))
    evwsgi.wsgi_cb(("/longzipped", staticlongzipped))
    evwsgi.wsgi_cb(("/long", staticlong))
    evwsgi.wsgi_cb(("/elong", embedlong))
    evwsgi.wsgi_cb(("/short", staticshort))
    staticform=views.Staticfile("test.html")
    evwsgi.wsgi_cb(("/staticform", staticform))
    evwsgi.wsgi_cb(("/testpost", testpost))
    evwsgi.wsgi_cb(("/badscript", badscript))
    evwsgi.wsgi_cb(("/returnnone", returnnone))
    evwsgi.wsgi_cb(("/returnnull", returnnull))
    evwsgi.wsgi_cb(("/returniternull", returniternull))

    evwsgi.set_debug(0)    
    evwsgi.run()
Exemple #9
0
def start():
	evwsgi.start('0.0.0.0', '8080') 
	evwsgi.set_base_module(base)

	def proxy(baseurl):
		def f(environ, start_response):
			try:
				import urllib2
				resp = urllib2.urlopen(baseurl + environ["PATH_INFO"] + ("?" + environ["QUERY_STRING"] if environ["QUERY_STRING"] != "" else ""))
				if resp.code == 200:
					start_response('200 OK', [('Content-Type', resp.info().gettype())])
					return [resp.read()]
			except:
				start_response('403 ERROR', [('Content-Type', 'text/plain')])
				return ['Error loading request.']
		return f

	evwsgi.wsgi_cb(('/boundaries/', proxy("http://gis.govtrack.us/boundaries/")))
	evwsgi.wsgi_cb(('/map/tiles/', proxy("http://gis.govtrack.us/map/tiles/")))
	evwsgi.wsgi_cb(('/static/rep_photos/', proxy("http://www.govtrack.us/data/photos/")))
	
	staticfile = views.Staticfile('static', maxage=2629000)
	evwsgi.wsgi_cb(('/static', staticfile))

	staticfile = views.Staticfile('your_new_district.html', maxage=2629000)
	evwsgi.wsgi_cb(('/', staticfile))

	evwsgi.set_debug(0)	   
	evwsgi.run()
Exemple #10
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(fapws.base)
    evwsgi.wsgi_cb(("",generic))
    evwsgi.set_debug(0)    
    print "libev ABI version:%i.%i" % evwsgi.libev_version()
    evwsgi.run()
Exemple #11
0
def start():
    evwsgi.start(
        os.getenv('FAVIEW_IP', '0.0.0.0'),
        os.getenv('FAVIEW_PORT', '8080'),
    )
    evwsgi.set_base_module(base)

    for local_path, real_path in MEDIA_PREFIX.iteritems():
        media_dir = ServeStatic(
            settings.MEDIA_ROOT + local_path,
            real_path,
            maxage=2629000,
        )
        evwsgi.wsgi_cb((
            settings.MEDIA_URL + local_path,
            media_dir,
        ))

    def generic(environ, start_response):
        res = django_handler.handler(environ, start_response)
        return [res]

    evwsgi.wsgi_cb(('', generic))
    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #12
0
def start():
	evwsgi.start(db_link_host, str(db_link_port)) 
	evwsgi.set_base_module(base)

	evwsgi.wsgi_cb(('', application))

	evwsgi.set_debug(0)	   
	evwsgi.run()
Exemple #13
0
 def run(self):
     from blog import Blog
     self.update()
     self.blog = Blog(self.config)
     evwsgi.start(self.config['host'], self.config['port'])
     evwsgi.set_base_module(base)
     self.loadWebPath()
     evwsgi.run()
Exemple #14
0
def start():
    evwsgi.start(HOST, str(PORT))
    evwsgi.set_base_module(base)

    evwsgi.wsgi_cb(('/static', views.Staticfile(STATIC_PATH)))
    evwsgi.wsgi_cb(('/broadcast', broadcast))

    evwsgi.set_debug(0)
    evwsgi.run()
def start_server():
    evwsgi.start("0.0.0.0", "5747")
    evwsgi.set_base_module(fapws.base)
    stats_app = AnyStat()
    evwsgi.wsgi_cb(("/stats/", stats_app))
    commit = lambda: stats_app.cache.commit()
    evwsgi.add_timer(10, commit)
    #evwsgi.set_debug(1)
    evwsgi.run()
Exemple #16
0
    def start(self):
        self.silence_spurious_logging()

        evwsgi.start(self.interface, self.port)
        evwsgi.set_base_module(base)
        evwsgi.wsgi_cb(("/", wsgi_dispatcher))
        evwsgi.set_debug(0)
        self.logger.info('%r running...' % (self,))
        evwsgi.run()
Exemple #17
0
def run_with_fapws3(config):
    import fapws._evwsgi as evwsgi
    from fapws import base, config

    evwsgi.start(config['host'], config['port'])
    evwsgi.set_base_module(base)
    evwsgi.wsgi_cb(('', config['request_handler']))
    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #18
0
 def run(self, handler):
     import fapws._evwsgi as evwsgi
     from fapws import base
     evwsgi.start(self.host, self.port)
     evwsgi.set_base_module(base)
     def app(environ, start_response):
         environ['wsgi.multiprocess'] = False
         return handler(environ, start_response)
     evwsgi.wsgi_cb(('',app))
     evwsgi.run()
Exemple #19
0
 def fapws(app,address, **options):
     import fapws._evwsgi as evwsgi
     from fapws import base
     evwsgi.start(address[0],str(address[1]))
     evwsgi.set_base_module(base)
     def app(environ, start_response):
         environ['wsgi.multiprocess'] = False
         return app(environ, start_response)
     evwsgi.wsgi_cb(('',app))
     evwsgi.run()
Exemple #20
0
def start():
    evwsgi.start("0.0.0.0", "5000")
    evwsgi.set_base_module(base)
    
    def app(environ, start_response):
        environ['wsgi.multiprocess'] = False
        return wsgi_app(environ, start_response)

    evwsgi.wsgi_cb(('',app))
    evwsgi.run()
Exemple #21
0
 def fapws(app,address, **options):
     import fapws._evwsgi as evwsgi
     from fapws import base
     evwsgi.start(address[0],str(address[1]))
     evwsgi.set_base_module(base)
     def app(environ, start_response):
         environ['wsgi.multiprocess'] = False
         return app(environ, start_response)
     evwsgi.wsgi_cb(('',app))
     evwsgi.run()
def start(host, port):
	"""Fapws3 WSGI application"""

	evwsgi.start(host or '127.0.0.1', port or '8000')
	evwsgi.set_base_module(fapws.base)

	evwsgi.wsgi_cb(("/api", web.application.init_memcached()))

	evwsgi.set_debug(0)
	evwsgi.run()
Exemple #23
0
def start():
    evwsgi.start("0.0.0.0", "8080")

    evwsgi.set_base_module(base)

    hello = cgiapp.CGIApplication("./test.cgi")
    evwsgi.wsgi_cb(("/hellocgi", hello))
    testphp = cgiapp.CGIApplication("/tmp/test.php")
    evwsgi.wsgi_cb(("/testphp", testphp))

    evwsgi.run()
Exemple #24
0
def start():
    evwsgi.start("0.0.0.0", 8080)
    
    evwsgi.set_base_module(base)
    
    hello=cgiapp.CGIApplication("./test.cgi")
    evwsgi.wsgi_cb(("/hellocgi",hello))
    testphp=cgiapp.CGIApplication("/tmp/test.php")
    evwsgi.wsgi_cb(("/testphp",testphp))
    
        
    evwsgi.run()
def start(name):
    print "started server at "+str(host)+":"+str(port)
    if name =="meinheld":
        from meinheld import server
        server.set_access_logger(None)
        server.set_error_logger(None)
        server.listen((host, port))
        server.run(app)
    elif name =="gevent":
        #from gevent import wsgi 
        #wsgi.WSGIServer((host, port), application=app.application, log=None).serve_forever() 
        from gevent.pywsgi import WSGIServer
        WSGIServer((host, port), app, log=None).serve_forever()
    elif name =="bjoern":
        import bjoern
        bjoern.listen(app, host, port)
        bjoern.run() 
    elif name =="eventlet":
        import eventlet
        from eventlet import wsgi
        #worker_pool = eventlet.GreenPool(2000)
        #wsgi.server(eventlet.listen(('', port)), app, custom_pool=worker_pool, log=file('/dev/null', 'w'))
        # max_size
        wsgi.server(eventlet.listen(('', port)), app, max_size=10000, log=file('/dev/null', 'w'))
    elif name =="fapws":
        import fapws._evwsgi as evwsgi
        from fapws import base
        evwsgi.start(host, str(port)) 
        evwsgi.set_base_module(base)
        evwsgi.wsgi_cb(('/', app))
        evwsgi.set_debug(0)        
        evwsgi.run()
    elif name=="uwsgi":
        print ("""Enter this command in the console
                \nsudo uwsgi --http :8000 --master --disable-logging --pythonpath /home/a/g --wsgi-file w.py --listen 2  --buffer-size 2048 --async 10000 --ugreen -p 4
            """)
        #  http://osdir.com/ml/python-wsgi-uwsgi-general/2011-02/msg00136.html
        # 
        #  Re: strange SIGPIPE: writing to a closed pipe/socket/fd on image requested from facebook -msg#00136
        """
SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /1 (ip 127.0.0.1) !!!
uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 260]
IOError: write error
        """
        cmd_txt = "sudo uwsgi --http :8000 --master --harakiri 1 --harakiri-verbose --close-on-exec --disable-logging --pythonpath /home/a/todo/test --wsgi-file w2.py --listen 2  --buffer-size 2048 --async 10000 --ugreen -p 4"
        cmd(cmd_txt)
    elif name=="pycgi":
        from wsgiref.handlers import CGIHandler 
        CGIHandler().run(app)
    elif name=="pystandard":
        from wsgiref.simple_server import make_server
        make_server(host, port, app).serve_forever()
Exemple #26
0
def start():
    evwsgi.start("0.0.0.0", 8080)
    evwsgi.set_base_module(base)
    
    @trace.Trace()
    def hello(environ, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return ["hello world!!"]

    evwsgi.wsgi_cb(("/hello", hello))

    evwsgi.set_debug(0)    
    evwsgi.run()
Exemple #27
0
 def start(self):
     evwsgi.start(self.host, self.port)
     evwsgi.set_base_module(base)
     
     #def app(environ, start_response):
     #    environ['wsgi.multiprocess'] = False
     #    return wsgi_app(environ, start_response)
 
     evwsgi.wsgi_cb(('',self.app))
     #evwsgi.set_debug(1)#开启调试
     evwsgi.set_debug(0)        
     print "libev ABI version:%i.%i" % evwsgi.libev_version()
     evwsgi.run()
Exemple #28
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(base)

    @trace.Trace()
    def hello(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/html')])
        return ["hello world!!"]

    evwsgi.wsgi_cb(("/hello", hello))

    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #29
0
    def run(self, handler):  # 重写 run() 函数.
        import fapws._evwsgi as evwsgi
        from fapws import base
        import sys

        evwsgi.start(self.host, self.port)
        evwsgi.set_base_module(base)

        def app(environ, start_response):  # 函数嵌套定义,特别注意.
            environ['wsgi.multiprocess'] = False
            return handler(environ, start_response)

        evwsgi.wsgi_cb(('', app))  # 调用内嵌的 app()函数
        evwsgi.run()
Exemple #30
0
    def run(self, handler):  # 重写 run() 函数.
        import fapws._evwsgi as evwsgi
        from fapws import base
        import sys

        evwsgi.start(self.host, self.port)
        evwsgi.set_base_module(base)

        def app(environ, start_response):  # 函数嵌套定义,特别注意.
            environ['wsgi.multiprocess'] = False
            return handler(environ, start_response)

        evwsgi.wsgi_cb(('', app))  # 调用内嵌的 app()函数
        evwsgi.run()
Exemple #31
0
def start():
    evwsgi.start("0.0.0.0", "8080")

    evwsgi.set_base_module(base)

    def generic(environ, start_response):
        res = django_handler.handler(environ, start_response)
        return [res]

    mediafile = views.Staticfile(django.__path__[0] + "/contrib/admin/media/", maxage=2629000)
    evwsgi.wsgi_cb(("/media/", mediafile))
    evwsgi.wsgi_cb(("", generic))

    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #32
0
 def run(self):
     try:
         # since we don't use threads, internal checks are no more required
         sys.setcheckinterval = 100000
         # fapws evwsgi.start() seems to ignore the port
         # if it's a number and requires it to be a string,
         # so we cast it here to get it to work correctly.
         host, port = self.config.bind_addr
         evwsgi.start(host, str(port))
         evwsgi.set_base_module(base)
         evwsgi.wsgi_cb(('', self.config.app))
         evwsgi.set_debug(0)
         evwsgi.run()
     except KeyboardInterrupt:
         self.stop()
Exemple #33
0
    def run(self, handler):  # pragma: no cover
        import fapws._evwsgi as evwsgi
        from fapws import base, config
        port = self.port
        if float(config.SERVER_IDENT[-2:]) > 0.4:
            # fapws3 silently changed its API in 0.5
            port = str(port)
        evwsgi.start(self.host, port)
        evwsgi.set_base_module(base)

        def app(environ, start_response):
            environ['wsgi.multiprocess'] = False
            return handler(environ, start_response)

        evwsgi.wsgi_cb(('', app))
        evwsgi.run()
Exemple #34
0
    def run(self, handler):
        import fapws._evwsgi as evwsgi
        from fapws import base
        evwsgi.start(self.host, self.port)
        evwsgi.set_base_module(base)

        def app(environ, start_response):
            environ['wsgi.multiprocess'] = False
            result = handler(environ, start_response)
            if isinstance(result, basestring):
                # fapws doesn't handle strings correctly
                return iter(result)
            else:
                return result

        evwsgi.wsgi_cb(('', app))
        evwsgi.run()
Exemple #35
0
    def run(self, handler): # pragma: no cover
        import fapws._evwsgi as evwsgi
        from fapws import base, config

        port = self.port
        if float(config.SERVER_IDENT[-2:]) > 0.4:
            # fapws3 silently changed its API in 0.5
            port = str(port)
        evwsgi.start(self.host, port)
        evwsgi.set_base_module(base)

        def app(environ, start_response):
            environ['wsgi.multiprocess'] = False
            return handler(environ, start_response)

        evwsgi.wsgi_cb(('', app))
        evwsgi.run()
Exemple #36
0
    def serve(self, filename, conf, error):
        """Run the publisher

        In:
          -  ``filename`` -- the path to the configuration file
          - ``conf`` -- the ``ConfigObj`` object, created from the configuration file
          - ``error`` -- the function to call in case of configuration errors
        """
        host, port, conf = self._validate_conf(filename, conf, error)

        # The publisher is an events based server so call once the ``on_new_process()`` method
        self.on_new_process()

        evwsgi.start(host, str(port))
        evwsgi.set_base_module(fapws.base)
        evwsgi.wsgi_cb(self.urls)
        evwsgi.run()
Exemple #37
0
def start():
    handler = Handler(Config({
        'pool_max_runners': 5,
        'provider_appdir': os.path.join(os.path.dirname(__file__), '../../tests'),
        'router_domain': 'example.com'
    }))

    evwsgi.start("0.0.0.0", "8080")

    evwsgi.set_base_module(base)

    evwsgi.wsgi_cb(('', handler))

    evwsgi.set_debug(0)
    evwsgi.run()

    handler.free()
Exemple #38
0
    def serve(self, filename, conf, error):
        """Run the publisher

        In:
          -  ``filename`` -- the path to the configuration file
          - ``conf`` -- the ``ConfigObj`` object, created from the configuration file
          - ``error`` -- the function to call in case of configuration errors
        """
        (host, port, conf) = self._validate_conf(filename, conf, error)

        # The publisher is an events based server so call once the ``on_new_process()`` method
        self.on_new_process()

        evwsgi.start(host, str(port))
        evwsgi.set_base_module(fapws.base)
        evwsgi.wsgi_cb(self.urls)
        evwsgi.run()
def server_http():
    lid = LanguageIdentifier(model)
    headers = [('Content-type', 'text/javascript; charset=utf-8')]
    status = '200 OK'

    def application(environ, start_response):
        params = parse_qs(environ['QUERY_STRING'])
        text = params['q'][0]
        normalize = params['normalize'][0] == 'true'
        pred, conf = lid.classify(text, normalize=normalize)
        start_response(status, headers)
        return [pred + ' ' + str(conf)]

    evwsgi.start('127.0.0.1', '10000')
    evwsgi.set_base_module(base)
    evwsgi.wsgi_cb(('', application))
    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #40
0
 def run(self, handler): # pragma: no cover
     import fapws._evwsgi as evwsgi
     from fapws import base, config
     port = self.port
     if float(config.SERVER_IDENT[-2:]) > 0.4:
         # fapws3 silently changed its API in 0.5
         port = str(port)
     evwsgi.start(self.host, port)
     # fapws3 never releases the GIL. Complain upstream. I tried. No luck.
     if 'MOLE_CHILD' in os.environ and not self.quiet:
         print "WARNING: Auto-reloading does not work with Fapws3."
         print "         (Fapws3 breaks python thread support)"
     evwsgi.set_base_module(base)
     def app(environ, start_response):
         environ['wsgi.multiprocess'] = False
         return handler(environ, start_response)
     evwsgi.wsgi_cb(('', app))
     evwsgi.run()
Exemple #41
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(base)
    
 
    evwsgi.wsgi_cb(("/env", env))
    evwsgi.wsgi_cb(("/hello", hello))
    evwsgi.wsgi_cb(("/iterhello", iteration))
    evwsgi.wsgi_cb(("/longzipped", staticlongzipped))
    evwsgi.wsgi_cb(("/long", staticlong))
    evwsgi.wsgi_cb(("/elong", embedlong))
    evwsgi.wsgi_cb(("/short", staticshort))
    staticform=views.Staticfile("test.html")
    evwsgi.wsgi_cb(("/staticform", staticform))
    evwsgi.wsgi_cb(("/testpost", testpost))
    evwsgi.wsgi_cb(("/badscript", badscript))

    evwsgi.set_debug(0)    
    evwsgi.run()
Exemple #42
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(mybase)

    evwsgi.wsgi_cb(("/env", env))
    evwsgi.wsgi_cb(("/hello", hello))
    evwsgi.wsgi_cb(("/tuplehello", tuplehello))
    evwsgi.wsgi_cb(("/iterhello", iteration))
    evwsgi.wsgi_cb(("/longzipped", staticlongzipped))
    evwsgi.wsgi_cb(("/long", staticlong))
    evwsgi.wsgi_cb(("/elong", embedlong))
    evwsgi.wsgi_cb(("/short", staticshort))
    staticform = views.Staticfile("test.html")
    evwsgi.wsgi_cb(("/staticform", staticform))
    evwsgi.wsgi_cb(("/testpost", testpost))
    evwsgi.wsgi_cb(("/badscript", badscript))

    evwsgi.set_debug(0)
    evwsgi.run()
Exemple #43
0
    def run(self, handler):  # pragma: no cover
        import fapws._evwsgi as evwsgi
        from fapws import base, config
        port = self.port
        if float(config.SERVER_IDENT[-2:]) > 0.4:
            # fapws3 silently changed its API in 0.5
            port = str(port)
        evwsgi.start(self.host, port)
        # fapws3 never releases the GIL. Complain upstream. I tried. No luck.
        if 'MOLE_CHILD' in os.environ and not self.quiet:
            print "WARNING: Auto-reloading does not work with Fapws3."
            print "         (Fapws3 breaks python thread support)"
        evwsgi.set_base_module(base)

        def app(environ, start_response):
            environ['wsgi.multiprocess'] = False
            return handler(environ, start_response)

        evwsgi.wsgi_cb(('', app))
        evwsgi.run()
Exemple #44
0
def start():
    evwsgi.start("/tmp/hello_unix.sock", "unix")
    evwsgi.set_base_module(base)
    
    def hello(environ, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return ["hello world!!"]

    def iteration(environ, start_response):
        start_response('200 OK', [('Content-Type','text/plain')])
        yield "hello"
        yield " "
        yield "world!!"

    
    evwsgi.wsgi_cb(("/hello", hello))
    evwsgi.wsgi_cb(("/iterhello", iteration))

    evwsgi.set_debug(0)    
    evwsgi.run()
Exemple #45
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(base)

    def return_file(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/html')])
        return open('big-file')

    def return_tuple(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/plain')])
        return ('Hello,', " it's me ", 'Bob!')

    def return_rfc_time(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/plain')])
        return [evwsgi.rfc1123_date(time())]

    evwsgi.wsgi_cb(("/file", return_file))
    evwsgi.wsgi_cb(("/tuple", return_tuple))
    evwsgi.wsgi_cb(("/time", return_rfc_time))

    evwsgi.run()
Exemple #46
0
def start():
    evwsgi.start("0.0.0.0", "8080")
    evwsgi.set_base_module(base)

    def return_file(environ, start_response):
        start_response('200 OK', [('Content-Type','text/html')])
        return open('big-file')

    def return_tuple(environ, start_response):
        start_response('200 OK', [('Content-Type','text/plain')])
        return ('Hello,', " it's me ", 'Bob!')

    def return_rfc_time(environ, start_response):
        start_response('200 OK', [('Content-Type','text/plain')])
        return [evwsgi.rfc1123_date(time())]

    evwsgi.wsgi_cb(("/file", return_file))
    evwsgi.wsgi_cb(("/tuple", return_tuple))
    evwsgi.wsgi_cb(("/time", return_rfc_time))

    evwsgi.run()
Exemple #47
0
def start():
    evwsgi.start("0.0.0.0", "8085")

    evwsgi.set_base_module(fapws.base)

    #def generic(environ, start_response):
    #    return ["page not found"]

    def index(environ, start_response):
        print "GET:", environ['fapws.uri']
        return views.index(environ, start_response)

    def display(environ, start_response):
        print "GET:", environ['fapws.uri']
        return views.display(environ, start_response)

    def edit(environ, start_response):
        #print environ['fapws.params']
        print "GET:", environ['fapws.uri']
        r = views.Edit()
        return r(environ, start_response)

    favicon = fapws.contrib.views.Staticfile("static/img/favicon.ico")

    def mystatic(environ, start_response):
        print "GET:", environ['fapws.uri']
        s = fapws.contrib.views.Staticfile("static/")
        return s(environ, start_response)

    evwsgi.wsgi_cb(("/display/", display))
    evwsgi.wsgi_cb(("/edit", edit))
    evwsgi.wsgi_cb(("/new", edit))
    evwsgi.wsgi_cb(("/static/", mystatic))
    #evwsgi.wsgi_cb(('/favicon.ico',favicon)),

    evwsgi.wsgi_cb(("/", index))
    #evhttp.gen_http_cb(generic)
    evwsgi.set_debug(0)
    print "libev ABI version:%i.%i" % evwsgi.libev_version()
    evwsgi.run()
Exemple #48
0
         server = WSGIServer(("0.0.0.0", port),
                             wsgifunc,
                             request_queue_size=40)
         try:
             server.start()
         except KeyboardInterrupt:
             server.stop()
     elif sname == "gevent":
         from gevent.wsgi import WSGIServer
         server = WSGIServer(("0.0.0.0", port), wsgifunc, log=None)
         server.serve_forever()
     elif sname == "fapws3":
         import fapws._evwsgi as evwsgi
         from fapws import base
         evwsgi.start("0.0.0.0", str(port))
         evwsgi.set_base_module(base)
         evwsgi.wsgi_cb(("", wsgifunc))
         evwsgi.set_debug(0)
         evwsgi.run()
     else:
         usage()
 elif len(argv) == 0:
     from flup.server.fcgi import WSGIServer
     server = WSGIServer(wsgifunc,
                         bindAddress=None,
                         multiplexed=False,
                         multithreaded=False)
     server.run()
     #web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
     #app.run()
 else:
Exemple #49
0
def main():
    global identifier

    parser = optparse.OptionParser()
    parser.add_option('-s',
                      '--serve',
                      action='store_true',
                      default=False,
                      dest='serve',
                      help='launch web service')
    parser.add_option('--host',
                      default=HOST,
                      dest='host',
                      help='host/ip to bind to')
    parser.add_option('--port',
                      default=PORT,
                      dest='port',
                      help='port to listen on')
    parser.add_option('-v',
                      action='count',
                      dest='verbosity',
                      help='increase verbosity (repeat for greater effect)')
    parser.add_option('-m', dest='model', help='load model from file')
    parser.add_option(
        '-l',
        '--langs',
        dest='langs',
        help='comma-separated set of target ISO639 language codes (e.g en,de)')
    parser.add_option('-r',
                      '--remote',
                      action="store_true",
                      default=False,
                      help='auto-detect IP address for remote access')
    parser.add_option('-b',
                      '--batch',
                      action="store_true",
                      default=False,
                      help='specify a list of files on the command line')
    parser.add_option('--demo',
                      action="store_true",
                      default=False,
                      help='launch an in-browser demo application')
    parser.add_option('-d',
                      '--dist',
                      action='store_true',
                      default=False,
                      help='show full distribution over languages')
    parser.add_option('-u', '--url', help='langid of URL')
    parser.add_option(
        '--line',
        action="store_true",
        default=False,
        help='process pipes line-by-line rather than as a document')
    parser.add_option('-n',
                      '--normalize',
                      action='store_true',
                      default=False,
                      help='normalize confidence scores to probability values')
    options, args = parser.parse_args()

    if options.verbosity:
        logging.basicConfig(level=max((5 - options.verbosity) * 10, 0))
    else:
        logging.basicConfig()

    if options.batch and options.serve:
        parser.error("cannot specify both batch and serve at the same time")

    # unpack a model
    if options.model:
        try:
            identifier = LanguageIdentifier.from_modelpath(
                options.model, norm_probs=options.normalize)
            logger.info("Using external model: %s", options.model)
        except IOError as e:
            logger.warning("Failed to load %s: %s" % (options.model, e))

    if identifier is None:
        identifier = LanguageIdentifier.from_modelstring(
            model, norm_probs=options.normalize)
        logger.info("Using internal model")

    if options.langs:
        langs = options.langs.split(",")
        identifier.set_languages(langs)

    def _process(text):
        """
    Set up a local function to do output, configured according to our settings.
    """
        if options.dist:
            payload = identifier.rank(text)
        else:
            payload = identifier.classify(text)

        return payload

    if options.url:
        import contextlib
        import urllib.request, urllib.error, urllib.parse
        try:
            from urllib.request import urlopen
        except ImportError:
            from urllib2 import urlopen
        with contextlib.closing(urlopen(options.url)) as url:
            text = url.read()
            output = _process(text)
            print(options.url, len(text), output)

    elif options.serve or options.demo:
        # from http://stackoverflow.com/questions/166506/finding-local-ip-addresses-in-python
        if options.remote and options.host is None:
            # resolve the external ip address
            import socket
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(("google.com", 80))
            hostname = s.getsockname()[0]
        elif options.host is None:
            # resolve the local hostname
            import socket
            hostname = socket.gethostbyname(socket.gethostname())
        else:
            hostname = options.host

        if options.demo:
            import webbrowser
            webbrowser.open('http://{0}:{1}/demo'.format(
                hostname, options.port))
        try:
            if FORCE_WSGIREF: raise ImportError
            # Use fapws3 if available
            import fapws._evwsgi as evwsgi
            from fapws import base
            evwsgi.start(hostname, str(options.port))
            evwsgi.set_base_module(base)
            evwsgi.wsgi_cb(('', application))
            evwsgi.set_debug(0)
            evwsgi.run()
        except ImportError:
            print("Listening on %s:%d" % (hostname, int(options.port)))
            print("Press Ctrl+C to exit")
            httpd = make_server(hostname, int(options.port), application)
            try:
                httpd.serve_forever()
            except KeyboardInterrupt:
                pass
    elif options.batch:
        # Start in batch mode - interpret input as paths rather than content
        # to classify.
        import sys, os, csv
        import multiprocessing as mp

        def generate_paths():
            for line in sys.stdin:
                path = line.strip()
                if path:
                    if os.path.isfile(path):
                        yield path
                    else:
                        # No such path
                        pass

        writer = csv.writer(sys.stdout)
        pool = mp.Pool()
        if options.dist:
            writer.writerow(['path'] + nb_classes)
            for path, ranking in pool.imap_unordered(rank_path,
                                                     generate_paths()):
                ranking = dict(ranking)
                row = [path] + [ranking[c] for c in nb_classes]
                writer.writerow(row)
        else:
            for path, (lang,
                       conf) in pool.imap_unordered(cl_path, generate_paths()):
                writer.writerow((path, lang, conf))
    else:
        import sys
        if sys.stdin.isatty():
            # Interactive mode
            while True:
                try:
                    print(">>>", end=' ')
                    text = input()
                except Exception as e:
                    print(e)
                    break
                print(_process(text))
        else:
            # Redirected
            if options.line:
                for line in sys.stdin:
                    print(_process(line))
            else:
                print(_process(sys.stdin.read()))