def __str__(self):
     """
     __str__: Magic method:
         This is meant to produce a human readable representation
         of the object. This will alter the internal xml slightly
         in oreder to pretty print the xml.
     """
     pretty_print(self.request_xml.getroot())
     return etree.tostring(self.request_xml.getroot())
 def __repr__(self):
     """
     __repr__: Magic method:
         This is meant to produce a machine readable representation of
         the object. Note, however, that if __str__ was called previously
         that the xml will have been altered in order to pretty print the
         xml and this will be pretty printed as well.
     """
     return etree.tostring(self.request_xml.getroot())
 def send(self, secure=True):
     """
     send: public function
         This function sends self.request_xml to self._url using self._creds
         for authentication and authorization. Currently only basic auth is
         supported.
     """
     import ssl
     context = ssl.create_default_context()
     if not secure:
         context.check_hostname = False
         context.verify_mode = ssl.CERT_NONE
     xml = etree.tostring(self.request_xml.getroot(), encoding="UTF-8")
     req = urllib2.Request(url=self._url, data=xml)
     creds = self._credentials.strip()
     req.add_header('Authorization', 'Basic %s' % (creds))
     response_xml = urllib2.urlopen(req, timeout=self._timeout, context=context)
     response_xml = response_xml.read()
     return response_xml
Exemplo n.º 4
0
	options.path = '/'+options.path


conn = httplib.HTTPConnection("localhost:29392")
conn.request(method,options.action+options.path)

resp = conn.getresponse()

data = resp.read()

if options.action == '/download':
	print sys.getsizeof(data)
	exit()

parser = ET.XMLTreeBuilder()
parser.feed(data)

tree = ET.ElementTree(parser.close())

root = tree.getroot()
#print root.text
ET.dump(tree)

if options.action == '/list' and method == "GET":
	print "File listing: "
	file_listing(options.path, root)

if options.action == '/tagdata' and method == "GET":
	print "Tag Data: "
	tag_data("/", root, options)
def pprint(xml_str):
    tree = etree.fromstring(xml_str)
    pretty_print(tree)
    return etree.tostring(tree)