X-Git-Url: https://git.tokkee.org/?p=nagixsc.git;a=blobdiff_plain;f=nagixsc.py;h=56c4cf3ead117ca047a818085912232a5ad514d4;hp=191d26e2f0a1e90b9f6197f450a8c2f53cc61ac4;hb=06da2e7c92fffdccdfa3ca89c1e3aaaac37e9eff;hpb=828e84c4800e2ea294178630755f8428230fa49d diff --git a/nagixsc.py b/nagixsc.py index 191d26e..56c4cf3 100644 --- a/nagixsc.py +++ b/nagixsc.py @@ -4,6 +4,7 @@ import SocketServer import base64 import datetime import libxml2 +import mimetools import os import random import shlex @@ -386,6 +387,28 @@ def reset_future_timestamp(timestamp, now): ############################################################################## +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: