# Path: pypot/server/server.py
# class AbstractServer(object):
#     def __init__(self, robot, host, port):
#         self.restful_robot = RESTRobot(robot)
#         self.host, self.port = host, port
# 
#     def run(self):
#         raise NotImplementedError


import json
import socket
import errno
import numpy
import logging
		import socket
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler
from tornado.web import Application
from .server import AbstractServer

class MyJSONEncoder(json.JSONEncoder):
	""" JSONEncoder which tries to call a json property before using the encoding default function. """

	def default(self, obj):
		if hasattr(obj, 'json'):
			return obj.json

		if isinstance(obj, numpy.ndarray):
			return list(obj)

		if isinstance(obj, numpy.integer):
			return int(obj)

		return json.JSONEncoder.default(self, obj)


class PoppyRequestHandler(RequestHandler):
	"""Custom request handler.

	Automatically sets CORS and cache headers, and manages
	every OPTIONS request."""

	def set_default_headers(self):
		self.set_header('Cache-control', 'no-store')
		self.set_header('Access-Control-Allow-Origin', '*')
		self.set_header('Access-Control-Allow-Headers', 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token')
		self.set_header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')

	def options(self, *args, **kwargs):

# Path: pypot/server/server.py
# class AbstractServer(object):
#     def __init__(self, robot, host, port):
#         self.restful_robot = RESTRobot(robot)
#         self.host, self.port = host, port
# 
#     def run(self):
#         raise NotImplementedError


# Path: pypot/server/httpserver.py
import json
import socket
import errno
import numpy
import logging
		import socket
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler
from tornado.web import Application
from .server import AbstractServer


class MyJSONEncoder(json.JSONEncoder):
	""" JSONEncoder which tries to call a json property before using the encoding default function. """

	def default(self, obj):
		if hasattr(obj, 'json'):
			return obj.json

		if isinstance(obj, numpy.ndarray):
			return list(obj)

		if isinstance(obj, numpy.integer):
			return int(obj)

		return json.JSONEncoder.default(self, obj)


class PoppyRequestHandler(RequestHandler):
	"""Custom request handler.

	Automatically sets CORS and cache headers, and manages
	every OPTIONS request."""

	def set_default_headers(self):
		self.set_header('Cache-control', 'no-store')
		self.set_header('Access-Control-Allow-Origin', '*')
		self.set_header('Access-Control-Allow-Headers', 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token')
		self.set_header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')

	def options(self, *args, **kwargs):

		self.set_status(204)