diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py
index c47c0ea64ae85accf780046295bd1048b1461834..03884e36b9f22df2a4cda5d51ede2c410382fe4d 100644 (file)
--- a/nagixsc/__init__.py
+++ b/nagixsc/__init__.py
import string
import subprocess
import sys
+import urllib2
def debug(level, verb, string):
if level <= verb:
def read_xml(options):
if options.url != None:
- import urllib2
if options.httpuser and options.httppasswd:
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
return libxml2.parseDoc(content)
+def write_xml(xmldoc, outfile, httpuser=None, httppasswd=None):
+ if outfile.startswith('http'):
+ (headers, body) = encode_multipart(xmldoc, httpuser, httppasswd)
+
+ try:
+ response = urllib2.urlopen(urllib2.Request(outfile, body, headers)).read()
+ except urllib2.HTTPError, error:
+ print error
+ sys.exit(11)
+ except urllib2.URLError, error:
+ print error.reason[1]
+ sys.exit(12)
+
+ print response
+
+ elif outfile == '-':
+ xmldoc.saveFormatFile('-', format=1)
+
+ else:
+ xmldoc.saveFile(outfile)
+
+
##############################################################################
def xml_check_version(xmldoc):
##############################################################################
-def encode_multipart(xmldoc, httpuser, httppasswd):
+def encode_multipart(xmldoc, httpuser=None, httppasswd=None):
BOUNDARY = mimetools.choose_boundary()
CRLF = '\r\n'
L = []