# Path: pylm/remote/server.py
# class RequestHandler(object):
#     def __init__(self, environ):
#         self.environ = environ
#         length = int(environ.get('CONTENT_LENGTH'), 0)
#         self.request = Request(method=environ.get('REQUEST_METHOD'),
#                                data=environ.get('wsgi.input').read(length))
#         self.message = None
# 
#     def handle(self):
#         if self.request.method == 'POST':
#             try:
#                 message = PalmMessage()
#                 message.ParseFromString(self.request.data)
# 
#                 # This exports the message information
#                 self.message = message
#                 instruction = message.function.split('.')[1]
#                 result = getattr(self, instruction)(message.payload)
#                 message.payload = result
#                 response_body = message.SerializeToString()
#                 status = '200 OK'
# 
#             except Exception as exc:
#                 status = '500 Internal Server Error'
#                 response_body = b''
#         else:
#             status = '405 Method not allowed'
#             response_body = b''
# 
#         return status, response_body
# 
# class DebugServer(object):
#     def __init__(self, host, port, handler):
#         my_application = WSGIApplication(handler)
#         self.httpd = make_server(host, port, my_application)
# 
#     def serve_forever(self):
#         self.httpd.serve_forever()
# 
#     def handle_request(self):
#         self.httpd.handle_request()
# 
# class WSGIApplication(object):
#     def __init__(self, handler):
#         self.handler = handler
# 
#     def __call__(self, environ, start_response):
#         my_handler = self.handler(environ)
#         status, response = my_handler.handle()
#         response_headers = [
#             ('Content-Type', 'application/octet-stream'),
#             ('Content-Length', str(len(response)))
#         ]
# 
#         start_response(status, response_headers)
#         yield response


from pylm.remote.server import RequestHandler, DebugServer, WSGIApplication


class MyHandler(RequestHandler):
    def foo(self, payload):
        return payload + b' processed online'
    
app = WSGIApplication(MyHandler)


# Path: pylm/remote/server.py
# class RequestHandler(object):
#     def __init__(self, environ):
#         self.environ = environ
#         length = int(environ.get('CONTENT_LENGTH'), 0)
#         self.request = Request(method=environ.get('REQUEST_METHOD'),
#                                data=environ.get('wsgi.input').read(length))
#         self.message = None
# 
#     def handle(self):
#         if self.request.method == 'POST':
#             try:
#                 message = PalmMessage()
#                 message.ParseFromString(self.request.data)
# 
#                 # This exports the message information
#                 self.message = message
#                 instruction = message.function.split('.')[1]
#                 result = getattr(self, instruction)(message.payload)
#                 message.payload = result
#                 response_body = message.SerializeToString()
#                 status = '200 OK'
# 
#             except Exception as exc:
#                 status = '500 Internal Server Error'
#                 response_body = b''
#         else:
#             status = '405 Method not allowed'
#             response_body = b''
# 
#         return status, response_body
# 
# class DebugServer(object):
#     def __init__(self, host, port, handler):
#         my_application = WSGIApplication(handler)
#         self.httpd = make_server(host, port, my_application)
# 
#     def serve_forever(self):
#         self.httpd.serve_forever()
# 
#     def handle_request(self):
#         self.httpd.handle_request()
# 
# class WSGIApplication(object):
#     def __init__(self, handler):
#         self.handler = handler
# 
#     def __call__(self, environ, start_response):
#         my_handler = self.handler(environ)
#         status, response = my_handler.handle()
#         response_headers = [
#             ('Content-Type', 'application/octet-stream'),
#             ('Content-Length', str(len(response)))
#         ]
# 
#         start_response(status, response_headers)
#         yield response


# Path: examples/http/web_worker.py
from pylm.remote.server import RequestHandler, DebugServer, WSGIApplication



class MyHandler(RequestHandler):
    def foo(self, payload):
        return payload + b' processed online'
    
app = WSGIApplication(MyHandler)


if __name__ == '__main__':