diff --git a/nagixsc.py b/nagixsc.py
index 191d26e2f0a1e90b9f6197f450a8c2f53cc61ac4..56c4cf3ead117ca047a818085912232a5ad514d4 100644 (file)
--- a/nagixsc.py
+++ b/nagixsc.py
import base64
import datetime
import libxml2
+import mimetools
import os
import random
import shlex
##############################################################################
+def encode_multipart(xmldoc, httpuser, httppasswd):
+ BOUNDARY = mimetools.choose_boundary()
+ CRLF = '\r\n'
+ L = []
+ L.append('--' + BOUNDARY)
+ L.append('Content-Disposition: form-data; name="xmlfile"; filename="xmlfile"')
+ L.append('Content-Type: application/xml')
+ L.append('')
+ L.append(xmldoc.serialize())
+ L.append('--' + BOUNDARY + '--')
+ L.append('')
+ body = CRLF.join(L)
+ content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
+ headers = {'Content-Type': content_type, 'Content-Length': str(len(body))}
+
+ if httpuser and httppasswd:
+ headers['Authorization'] = 'Basic %s' % base64.b64encode(':'.join([httpuser, httppasswd]))
+
+ return (headers, body)
+
+##############################################################################
+
class MyHTTPServer(BaseHTTPServer.HTTPServer):
def __init__(self, server_address, HandlerClass, ssl=False, sslpemfile=None):
if ssl: