# Path: vcontrol/rest/helpers/get_allowed.py
# def get_allowed():
#     rest_url = ""
#     if "ALLOW_ORIGIN" in os.environ:
#         allow_origin = os.environ["ALLOW_ORIGIN"]
#         host_port = allow_origin.split("//")[1]
#         host = host_port.split(":")[0]
#         port = str(int(host_port.split(":")[1])+1)
#         rest_url = host+":"+port
#     else:
#         allow_origin = ""
#     return allow_origin, rest_url
# 
# Path: vcontrol/rest/helpers/json_yield.py
# def json_yield_none(fn):
#     def _(self, key, *o, **k):
# def json_yield_one(fn):
#     def _(self, arg, key, *o, **k):
# def json_yield_two(fn):
#     def _(self, arg1, arg2, key, *o, **k):


from ..helpers import get_allowed
from ..helpers import json_yield
import ast
import base64
import json
import os
import re
import subprocess
import uuid
import web
        return self.POST(o_type)

    def POST(self, o_type):
        web.header('Access-Control-Allow-Origin', self.allow_origin)
        web.header('Access-Control-Allow-Headers', "Content-type")
        data = web.data()
        payload = {}
        try:
            payload = ast.literal_eval(data)
            if type(payload) != dict:
                payload = ast.literal_eval(json.loads(data))
        except:
            return "malformed json body"

        client_session_id = uuid.uuid4().hex
        out = ""
        if o_type == 'a':
            out = self.INDEX_HTML%(client_session_id, payload) + \
                  self.INDEX_HTML_TYPE_A + \
                  self.INDEX_HTML_END
        elif o_type == 'b':
            out = self.INDEX_HTML%(client_session_id, payload) + \
                  self.INDEX_HTML_TYPE_B + \
                  self.INDEX_HTML_END
        return out

class CreateMachineOutputR:
    """
    This endpoint is for rendering the output of creating a new Vent machine.
    """

# Path: vcontrol/rest/helpers/get_allowed.py
# def get_allowed():
#     rest_url = ""
#     if "ALLOW_ORIGIN" in os.environ:
#         allow_origin = os.environ["ALLOW_ORIGIN"]
#         host_port = allow_origin.split("//")[1]
#         host = host_port.split(":")[0]
#         port = str(int(host_port.split(":")[1])+1)
#         rest_url = host+":"+port
#     else:
#         allow_origin = ""
#     return allow_origin, rest_url
# 
# Path: vcontrol/rest/helpers/json_yield.py
# def json_yield_none(fn):
#     def _(self, key, *o, **k):
# def json_yield_one(fn):
#     def _(self, arg, key, *o, **k):
# def json_yield_two(fn):
#     def _(self, arg1, arg2, key, *o, **k):


# Path: vcontrol/rest/machines/create.py
from ..helpers import get_allowed
from ..helpers import json_yield
import ast
import base64
import json
import os
import re
import subprocess
import uuid
import web

        return self.POST(o_type)

    def POST(self, o_type):
        web.header('Access-Control-Allow-Origin', self.allow_origin)
        web.header('Access-Control-Allow-Headers', "Content-type")
        data = web.data()
        payload = {}
        try:
            payload = ast.literal_eval(data)
            if type(payload) != dict:
                payload = ast.literal_eval(json.loads(data))
        except:
            return "malformed json body"

        client_session_id = uuid.uuid4().hex
        out = ""
        if o_type == 'a':
            out = self.INDEX_HTML%(client_session_id, payload) + \
                  self.INDEX_HTML_TYPE_A + \
                  self.INDEX_HTML_END
        elif o_type == 'b':
            out = self.INDEX_HTML%(client_session_id, payload) + \
                  self.INDEX_HTML_TYPE_B + \
                  self.INDEX_HTML_END
        return out

class CreateMachineOutputR:
    """
    This endpoint is for rendering the output of creating a new Vent machine.
    """

    json_yield = json_yield.json_yield_none