コード例 #1
0
    def do_PATCH(self):

        print("Just received a PATCH request")

        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={
                                    'REQUEST_METHOD': 'PATCH',
                                    'CONTENT_TYPE':
                                    self.headers['Content-Type'],
                                })
        args = {}

        for i in form:
            args[i] = form.getvalue(i)

        sp = ServicesProvider()
        contents = sp.get('router').do_PATCH(self.path, args)

        if (contents != False):
            self.send_response(200)
            self.end_headers()
            self.wfile.write(contents)
        else:
            self.send_response(404)
            self.end_headers()
コード例 #2
0
class SentencesServer(HTTPServer, object):

    def __init__(self, port, update_callback = None):
        super(SentencesServer, self).__init__(('0.0.0.0', port), SentencesHTTPHandler)
        self.sp = ServicesProvider(self)
        self.update_callback = update_callback

    def start(self):
        thread = threading.Thread(target = self.serve_forever)
        thread.daemon = True
        thread.start()

    def stop(self):
        self.shutdown()

    def on_update(self):
        if callable(self.update_callback):
            self.update_callback(self.sp.get('sentences_list').serialize())

    def get_sentences(self):
        return self.sp.get('sentences_list').serialize()
コード例 #3
0
    def do_DELETE(self):

        print("Just received a DELETE request")

        try:
            sp = ServicesProvider()
            contents = sp.get('back.router').do_DELETE(self.path)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(contents)
        except RestfulServerException as e:
            print 'HTTP error : {}'.format(e.get_message())
            self.send_response(e.get_code())
            self.end_headers()
            self.wfile.write('HTTP error : {}'.format(e.get_message()))
コード例 #4
0
    def do_GET(self):

        path  = urlparse(self.path).path
        print("GET " + path)
        
        try:
            sp = ServicesProvider()
            contents = sp.get('back.router').do_GET(path)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(contents)
        except RestfulServerException as e:
            print 'HTTP error : {}'.format(e.get_message())
            self.send_response(e.get_code())
            self.end_headers()
            self.wfile.write('HTTP error : {}'.format(e.get_message()))
コード例 #5
0
    def do_PUT(self):

        print("Just received a PUT request")

        args = cgi.FieldStorage(fp      = self.rfile,
                                headers = self.headers,
                                environ = {'REQUEST_METHOD' : 'PUT'})

        try:
            sp = ServicesProvider()
            contents = sp.get('router').do_PUT(self.path, args)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(contents)
        except RestfulServerException as e:
            print 'HTTP error : {}'.format(e.get_message())
            self.send_response(e.get_code())
            self.end_headers()
            self.wfile.write('HTTP error : {}'.format(e.get_message()))
コード例 #6
0
    def do_GET(self):

        path  = urlparse(self.path).path
        print("GET " + path)

        query = urlparse(self.path).query
        args = dict()

        if len(query) > 0:
            for qc in query.split("&"):
                args[qc.split("=")[0]] = qc.split("=")[1]

        sp = ServicesProvider()
        contents = sp.get('http_server_router').do_GET(path, args)

        if (contents != False):
            self.send_response(200)
            self.end_headers()
            self.wfile.write(contents)
        else:
            self.send_response(404)
            self.end_headers()