MCPcopy Create free account
hub / github.com/CloudPolis/webdav-client-python / publish

Method publish

webdav/client.py:646–702  ·  view source on GitHub ↗
(self, remote_path)

Source from the content-addressed store, hash-verified

644 raise NotConnection(self.webdav.hostname)
645
646 def publish(self, remote_path):
647
648 def parse(response):
649
650 try:
651 response_str = response.getvalue()
652 tree = etree.fromstring(response_str)
653 result = tree.xpath("//*[local-name() = 'public_url']")
654 public_url = result[0]
655 return public_url.text
656 except IndexError:
657 raise MethodNotSupported(name="publish", server=self.webdav.hostname)
658 except etree.XMLSyntaxError:
659 return ""
660
661 def data(for_server):
662
663 root_node = etree.Element("propertyupdate", xmlns="DAV:")
664 set_node = etree.SubElement(root_node, "set")
665 prop_node = etree.SubElement(set_node, "prop")
666 xmlns = Client.meta_xmlns.get(for_server, "")
667 public_url = etree.SubElement(prop_node, "public_url", xmlns=xmlns)
668 public_url.text = "true"
669 tree = etree.ElementTree(root_node)
670
671 buff = BytesIO()
672 tree.write(buff)
673
674 return buff.getvalue()
675
676 try:
677 urn = Urn(remote_path)
678
679 if not self.check(urn.path()):
680 raise RemoteResourceNotFound(urn.path())
681
682 response = BytesIO()
683
684 url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
685 options = {
686 'URL': "{hostname}{root}{path}".format(**url),
687 'CUSTOMREQUEST': Client.requests['publish'],
688 'HTTPHEADER': self.get_header('publish'),
689 'POSTFIELDS': data(for_server=self.webdav.hostname),
690 'WRITEDATA': response,
691 'NOBODY': 0
692 }
693
694 request = self.Request(options=options)
695
696 request.perform()
697 request.close()
698
699 return parse(response)
700
701 except pycurl.error:
702 raise NotConnection(self.webdav.hostname)
703

Callers 1

publishMethod · 0.45

Calls 8

checkMethod · 0.95
pathMethod · 0.95
quoteMethod · 0.95
get_headerMethod · 0.95
RequestMethod · 0.95
UrnClass · 0.90
NotConnectionClass · 0.85

Tested by

no test coverage detected