def do_GET(self): try: # Say we are at an https port so that OAuth package doesn't complain. This isn't a security concern because # it is just so that the authorization code is correctly parsed. authorization_callback("https://localhost" + self.path) self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() content = """ <html><head><title>Success!</title></head> <body><p>You successfully authorized the application, and your authorization url is: {}</p> <p>You may close this tab.</p> </body></html> """.format(self.path) self.wfile.write(sendable(content)) except BaseException as e: self.send_response(500) self.send_header("Content-type", "text/html") self.end_headers() content = """ <html><head><title>Error!</title></head> <body><p>Something happened and here is what we know: {}</p> <p>You may close this tab.</p> </body></html> """.format(e) self.wfile.write(sendable(content)) import threading assassin = threading.Thread(target=self.server.shutdown) assassin.daemon = True assassin.start()
def do_POST(self): content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length) unquoted_s = "" if six.PY2: import urllib unquoted_s = urllib.unquote(body) elif six.PY3: unquoted_s = body.decode('utf-8') data = json.loads(unquoted_s) from onshape_client.oas.models import BTDocumentParams bt_document_params = BTDocumentParams(name=data["doc_name"]) new_doc_response = Client.get_client().documents_api.create11( bt_document_params, _preload_content=False) did = get_field(new_doc_response, "id") wid = get_field(new_doc_response, "defaultWorkspace")["id"] # Use a fake eid because it isn't used later. eid = "00000000000000" self.onshape_element = OnshapeElement.create_from_ids( did, "w", wid, eid) if "import_items" in data: for import_item in data["import_items"]: self.import_item(import_item) self.send_response(200) self.send_header('Content-type', 'application/json') self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() content = { "document_href": self.onshape_element.get_url(url_type="document") } self.wfile.write(sendable(json.dumps(content)))
def do_GET(self): try: # Say we are at an https port so that OAuth package doesn't complain. This isn't a security concern because # it is just so that the authorization code is correctly parsed. self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() content = open(os.path.dirname(__file__) + "/assets/form.html", 'r').read() self.wfile.write(sendable(content)) except BaseException as e: self.send_response(500) self.send_header('Content-type', 'text/html') self.end_headers() content = ''' <html><head><title>Error!</title></head> <body><p>Something happened and here is what we know: {}</p> <p>You may close this tab.</p> </body></html> '''.format(e) self.wfile.write(sendable(content))