示例#1
0
 def __init__(self, port=8090):
     self.mappings = {}
     self.port = port
     self.server = CherryPyWSGIServer(("0.0.0.0", port), self, server_name="localhost")
     self.started = False
     self.t = threading.Thread(target=self._start)
     self.t.start()
     time.sleep(0.1)
示例#2
0
class HTTPServer:
    def __init__(self, port=8090):
        self.mappings = {}
        self.port = port
        self.server = CherryPyWSGIServer(("0.0.0.0", port), self, server_name="localhost")        
        self.started = False
        self.t = threading.Thread(target=self._start)
        self.t.start()
        time.sleep(0.1)
        
    def _start(self):
        try:
            self.server.start()
        except Exception, e:
            print 'ERROR: failed to start server', str(e)
示例#3
0
文件: api.py 项目: jvy1106/webpyutils
 def WSGIServer(server_address, wsgi_app):
     '''increase threads in pool and ignore any ssl support'''
     from web.wsgiserver import CherryPyWSGIServer
     return CherryPyWSGIServer(server_address,
                               wsgi_app,
                               numthreads=threads,
                               server_name=self._server_name)
示例#4
0
 def __init__(self, port=8090):
     self.mappings = {}
     self.port = port
     self.server = CherryPyWSGIServer(("0.0.0.0", port), self, server_name="localhost")
     self.started = False
     self.t = threading.Thread(target=self._start)
     self.t.start()
     time.sleep(0.1)
示例#5
0
class HTTPServer:
    def __init__(self, port=8090):
        self.mappings = {}
        self.port = port
        self.server = CherryPyWSGIServer(("0.0.0.0", port),
                                         self,
                                         server_name="localhost")
        self.started = False
        self.t = threading.Thread(target=self._start)
        self.t.start()
        time.sleep(0.1)

    def _start(self):
        try:
            self.server.start()
        except Exception, e:
            print 'ERROR: failed to start server', str(e)
示例#6
0
class HTTPServer:
    def __init__(self, port=8090):
        self.mappings = {}
        self.port = port
        self.server = CherryPyWSGIServer(("0.0.0.0", port), self, server_name="localhost")
        self.started = False
        self.t = threading.Thread(target=self._start)
        self.t.start()
        time.sleep(0.1)

    def _start(self):
        try:
            self.server.start()
        except Exception as e:
            print('ERROR: failed to start server', str(e))

    def stop(self):
        self.server.stop()
        self.t.join()

    def request(self, path, method='GET', query={}):
        response = Respose()

        if isinstance(query, dict):
            query = urllib.parse.urlencode(query)

        self.mappings[path, method, query] = response
        return response

    def __call__(self, environ, start_response):
        _method = environ.get('REQUEST_METHOD', 'GET')
        _path = environ.get('PATH_INFO')

        for (path, method, query_string), response in self.mappings.items():
            if _path == path and _method == method:
                return response(start_response)

        return Respose()(start_response)
示例#7
0
class HTTPServer:
    def __init__(self, port=8090):
        self.mappings = {}
        self.port = port
        self.server = CherryPyWSGIServer(("0.0.0.0", port), self, server_name="localhost")
        self.started = False
        self.t = threading.Thread(target=self._start)
        self.t.start()
        time.sleep(0.1)

    def _start(self):
        try:
            self.server.start()
        except Exception as e:
            print('ERROR: failed to start server', str(e))

    def stop(self):
        self.server.stop()
        self.t.join()

    def request(self, path, method='GET', query={}):
        response = Respose()

        if isinstance(query, dict):
            query = urllib.urlencode(query)

        self.mappings[path, method, query] = response
        return response

    def __call__(self, environ, start_response):
        _method = environ.get('REQUEST_METHOD', 'GET')
        _path = environ.get('PATH_INFO')

        for (path, method, query_string), response in self.mappings.items():
            if _path == path and _method == method:
                return response(start_response)

        return Respose()(start_response)
示例#8
0
urls = ("^/([^/]+)/([^/]+)$", "ServeHTTP")
app = web.application(urls, globals())
wsgifunc = app.wsgifunc()

if __name__ == "__main__":

    def usage():
        print "Usage: %s [{cherrypy|gevent|fapws3} PORT]" % argv[0]

    if len(argv) > 2:
        sname = argv[1]
        port = int(argv[2])
        if sname == "cherrypy":
            from web.wsgiserver import CherryPyWSGIServer as WSGIServer
            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))
示例#9
0
web.config.debug = False
urls = ("^/([^/]+)/([^/]+)$", "ServeHTTP")
app = web.application(urls, globals())
wsgifunc = app.wsgifunc()


if __name__ == "__main__":
    def usage():
        print "Usage: %s [{cherrypy|gevent|fapws3} PORT]" % argv[0]

    if len(argv) > 2:
        sname = argv[1]
        port = int(argv[2])
        if sname == "cherrypy":
            from web.wsgiserver import CherryPyWSGIServer as WSGIServer
            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)
示例#10
0
if __name__ == '__main__':
    host = DEFAULT_HOST_IP
    port = DEFAULT_PORT_NO
    try:
        options, args = getopt.getopt(sys.argv[1:], "",
                                      ["help", "port=", "host="])
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err)  # will print something like "option -a not recognized"
        usageguide()
        sys.exit(2)
    for op, arg1 in options:
        if op == "--help":
            usageguide()
            sys.exit(2)
        elif op == "--host":
            host = arg1
        elif op == "--port":
            port = int(arg1)

    urls = ("/.*", "app")
    apps = web.application(urls, globals())
    server = CherryPyWSGIServer((host, port), app, server_name='localhost')
    print "The server is hosted on host:port", (host, port)

    try:
        server.start()
#apps.run(port)
    except KeyboardInterrupt:
        server.stop()
示例#11
0
The function provides login mechanism to a developer user during development phase
'''
@app.route('/devlogin', methods=['POST'])
def devlogin():
    user=request.form['username']
    Responsemsg="Correct Credentials"
    data = {"message" : Responsemsg, "user": user}
    print makejson(data)
    return makejson(data)

if __name__ == '__main__':
    port = DEFAULT_PORT_NO
    options, args = getopt.getopt(sys.argv[1:], "", ["help", "port="])
    for op, arg1 in options:
	if op == "--help":
            usageguide()
            sys.exit(2)
        elif op == "--port":
            port = int(arg1)

    urls = ("/.*", "app")
    apps = web.application(urls, globals())
    server = CherryPyWSGIServer(("0.0.0.0", port),app,server_name='localhost')
    print "The server is hosted on port:",(port)
    
    try:
        server.start()
	#apps.run(port)
    except KeyboardInterrupt:
        server.stop()