Last active
August 1, 2016 02:59
-
-
Save fuglu/6be08d158750c0d1856f864e2c5e9452 to your computer and use it in GitHub Desktop.
python3 sipgate.io server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.4 | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
import urllib.parse | |
import logging | |
from xml.dom.minidom import Document | |
logging.basicConfig(level=logging.DEBUG) | |
class MegaAwesomePythonServer(BaseHTTPRequestHandler): | |
def do_POST(self): | |
length = int(self.headers['Content-Length']) | |
data = urllib.parse.parse_qs(self.rfile.read(length).decode('utf-8')) | |
logging.debug("from: " + data.get("from")[0]) | |
logging.debug("to: " + data.get("to")[0]) | |
logging.debug("direction: " + data.get("direction")[0]) | |
doc = Document() | |
response = doc.createElement('Response') | |
reject = doc.createElement('Reject') | |
reject.setAttribute('reason', 'busy') | |
response.appendChild(reject) | |
doc.appendChild(response) | |
self.send_response(200) | |
self.send_header('Content-Type', 'application/xml') | |
self.end_headers() | |
self.wfile.write(doc.toxml().encode('utf-8')) | |
server = HTTPServer(('', 9000), MegaAwesomePythonServer) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment