<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string encoding="cdata"><![CDATA[

from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
  raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/json; class=slapos.org.hosting_subscription\'\n
\n
if REQUEST.other[\'method\'] != "POST":\n
  response.setStatus(405)\n
  return ""\n
elif type != context.Base_getRequestHeader(\'Content-Type\'):\n
  response.setStatus(406)\n
  return ""\n
elif context.getPortalType() != "Person":\n
  response.setStatus(403)\n
  return ""\n
else:\n
  import json\n
  try:\n
    data_dict = json.loads(context.Base_getRequestBody())\n
  except (TypeError, ValueError):\n
    response.setStatus(400)\n
    return ""\n
  else:\n
\n
    def dictToXml(dict_data):\n
      assert same_type(dict_data, {})\n
      result = "<?xml version=\'1.0\' encoding=\'utf-8\'?><instance>\\n"\n
      for key, value in dict_data.items():\n
        result += """  <parameter id="%s">%s</parameter>\\n""" % (key.encode("UTF-8"), value.encode("UTF-8"))\n
      result += "</instance>"\n
      return result\n
\n
    try:\n
      parameter_kw = {\n
        \'software_release\': data_dict[\'software_release\'].encode("UTF-8"),\n
        \'software_title\': data_dict[\'title\'].encode("UTF-8"),\n
        \'software_type\': data_dict[\'software_type\'].encode("UTF-8"),\n
        \'instance_xml\': dictToXml(data_dict[\'parameter\']),\n
        \'sla_xml\': dictToXml(data_dict[\'sla\']),\n
        \'shared\': data_dict[\'slave\'],\n
        \'state\': data_dict[\'status\'].encode("UTF-8"),\n
      }\n
    except KeyError:\n
      response.setStatus(400)\n
      return ""\n
    else:\n
\n
      context.requestSoftwareInstance(**parameter_kw)\n
      # XXX Return hosting subscription link\n
      response.setStatus(201)\n
      return ""\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>REQUEST=None</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Person_requestHateoasHostingSubscription</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
