本文整理汇总了Python中webdav.urn.Urn.quote方法的典型用法代码示例。如果您正苦于以下问题:Python Urn.quote方法的具体用法?Python Urn.quote怎么用?Python Urn.quote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webdav.urn.Urn
的用法示例。
在下文中一共展示了Urn.quote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_property
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def set_property(self, remote_path, option):
def data(option):
root_node = etree.Element("propertyupdate", xmlns="DAV:")
root_node.set('xmlns:u', option.get('namespace', ""))
set_node = etree.SubElement(root_node, "set")
prop_node = etree.SubElement(set_node, "prop")
opt_node = etree.SubElement(prop_node, "{namespace}:{name}".format(namespace='u', name=option['name']))
opt_node.text = option.get('value', "")
tree = etree.ElementTree(root_node)
buff = BytesIO()
tree.write(buff)
return buff.getvalue()
try:
urn = Urn(remote_path)
if not self.check(urn.path()):
raise RemoteResourceNotFound(urn.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['set_metadata'],
'HTTPHEADER': self.get_header('get_metadata'),
'POSTFIELDS': data(option)
}
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例2: is_dir
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def is_dir(self, remote_path):
def parse(response, path):
try:
response_str = response.getvalue()
tree = etree.fromstring(response_str)
resps = tree.findall("{DAV:}response")
for resp in resps:
href = resp.findtext("{DAV:}href")
urn = unquote(href)
if path[-1] == Urn.separate:
if not path == urn:
continue
else:
path_with_sep = "{path}{sep}".format(path=path, sep=Urn.separate)
if not path == urn and not path_with_sep == urn:
continue
type = resp.find(".//{DAV:}resourcetype")
if type is None:
raise MethodNotSupported(name="is_dir", server=self.webdav.hostname)
dir_type = type.find("{DAV:}collection")
return True if dir_type is not None else False
raise RemoteResourceNotFound(path)
except etree.XMLSyntaxError:
raise MethodNotSupported(name="is_dir", server=self.webdav.hostname)
try:
urn = Urn(remote_path)
parent_urn = Urn(urn.parent())
if not self.check(urn.path()) and not self.check(Urn(remote_path, directory=True).path()):
raise RemoteResourceNotFound(remote_path)
response = BytesIO()
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': parent_urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['info'],
'HTTPHEADER': self.get_header('info'),
'WRITEDATA': response,
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
path = "{root}{path}".format(root=self.webdav.root, path=urn.path())
return parse(response, path)
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例3: get_property
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def get_property(self, remote_path, option):
def parse(response, option):
response_str = response.getvalue()
tree = etree.fromstring(response_str)
xpath = "{xpath_prefix}{xpath_exp}".format(xpath_prefix=".//", xpath_exp=option['name'])
return tree.findtext(xpath)
def data(option):
root = etree.Element("propfind", xmlns="DAV:")
prop = etree.SubElement(root, "prop")
etree.SubElement(prop, option.get('name', ""), xmlns=option.get('namespace', ""))
tree = etree.ElementTree(root)
buff = BytesIO()
tree.write(buff)
return buff.getvalue()
try:
urn = Urn(remote_path)
if not self.check(urn.path()):
raise RemoteResourceNotFound(urn.path())
response = BytesIO()
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['get_metadata'],
'HTTPHEADER': self.get_header('get_metadata'),
'POSTFIELDS': data(option),
'WRITEDATA': response,
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
return parse(response, option)
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例4: unpublish
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def unpublish(self, remote_path):
def data(for_server):
root = etree.Element("propertyupdate", xmlns="DAV:")
remove = etree.SubElement(root, "remove")
prop = etree.SubElement(remove, "prop")
xmlns = Client.meta_xmlns.get(for_server, "")
etree.SubElement(prop, "public_url", xmlns=xmlns)
tree = etree.ElementTree(root)
buff = BytesIO()
tree.write(buff)
return buff.getvalue()
try:
urn = Urn(remote_path)
if not self.check(urn.path()):
raise RemoteResourceNotFound(urn.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['unpublish'],
'HTTPHEADER': self.get_header('unpublish'),
'POSTFIELDS': data(for_server=self.webdav.hostname)
}
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例5: info
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def info(self, remote_path):
def parse(response, path):
try:
response_str = response.getvalue()
tree = etree.fromstring(response_str)
find_attributes = {
'created': ".//{DAV:}creationdate",
'name': ".//{DAV:}displayname",
'size': ".//{DAV:}getcontentlength",
'modified': ".//{DAV:}getlastmodified"
}
resps = tree.findall("{DAV:}response")
for resp in resps:
href = resp.findtext("{DAV:}href")
urn = unquote(href)
if path[-1] == Urn.separate:
if not path == urn:
continue
else:
path_with_sep = "{path}{sep}".format(path=path, sep=Urn.separate)
if not path == urn and not path_with_sep == urn:
continue
info = dict()
for (name, value) in find_attributes.items():
info[name] = resp.findtext(value)
return info
raise RemoteResourceNotFound(path)
except etree.XMLSyntaxError:
raise MethodNotSupported(name="info", server=self.webdav.hostname)
try:
urn = Urn(remote_path)
response = BytesIO()
if not self.check(urn.path()) and not self.check(Urn(remote_path, directory=True).path()):
raise RemoteResourceNotFound(remote_path)
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['info'],
'HTTPHEADER': self.get_header('info'),
'WRITEDATA': response,
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
path = "{root}{path}".format(root=self.webdav.root, path=urn.path())
return parse(response, path)
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例6: clean
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def clean(self, remote_path):
try:
urn = Urn(remote_path)
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['clean'],
'HTTPHEADER': self.get_header('clean')
}
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例7: publish
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def publish(self, remote_path):
def parse(response):
try:
response_str = response.getvalue()
tree = etree.fromstring(response_str)
result = tree.xpath("//*[local-name() = 'public_url']")
public_url = result[0]
return public_url.text
except IndexError:
raise MethodNotSupported(name="publish", server=self.webdav.hostname)
except etree.XMLSyntaxError:
return ""
def data(for_server):
root_node = etree.Element("propertyupdate", xmlns="DAV:")
set_node = etree.SubElement(root_node, "set")
prop_node = etree.SubElement(set_node, "prop")
xmlns = Client.meta_xmlns.get(for_server, "")
public_url = etree.SubElement(prop_node, "public_url", xmlns=xmlns)
public_url.text = "true"
tree = etree.ElementTree(root_node)
buff = BytesIO()
tree.write(buff)
return buff.getvalue()
try:
urn = Urn(remote_path)
if not self.check(urn.path()):
raise RemoteResourceNotFound(urn.path())
response = BytesIO()
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['publish'],
'HTTPHEADER': self.get_header('publish'),
'POSTFIELDS': data(for_server=self.webdav.hostname),
'WRITEDATA': response,
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
return parse(response)
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例8: upload_file
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def upload_file(self, remote_path, local_path, progress=None):
try:
if not os.path.exists(local_path):
raise LocalResourceNotFound(local_path)
urn = Urn(remote_path)
if urn.is_dir():
raise OptionNotValid(name="remote_path", value=remote_path)
if os.path.isdir(local_path):
raise OptionNotValid(name="local_path", value=local_path)
if not os.path.exists(local_path):
raise LocalResourceNotFound(local_path)
if not self.check(urn.parent()):
raise RemoteParentNotFound(urn.path())
with open(local_path, "rb") as local_file:
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'HTTPHEADER': self.get_header('upload_file'),
'UPLOAD': 1,
'READFUNCTION': local_file.read,
'NOPROGRESS': 0 if progress else 1
}
if progress:
options["PROGRESSFUNCTION"] = progress
file_size = os.path.getsize(local_path)
if file_size > self.large_size:
options['INFILESIZE_LARGE'] = file_size
else:
options['INFILESIZE'] = file_size
request = self.Request(options=options)
request.perform()
code = request.getinfo(pycurl.HTTP_CODE)
if code == "507":
raise NotEnoughSpace()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例9: move
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def move(self, remote_path_from, remote_path_to):
def header(remote_path_to):
path = Urn(remote_path_to).path()
destination = "{root}{path}".format(root=self.webdav.root, path=path)
header_item = "Destination: {destination}".format(destination=destination)
header = self.get_header('move')
header.append(header_item)
return header
try:
urn_from = Urn(remote_path_from)
if not self.check(urn_from.path()):
raise RemoteResourceNotFound(urn_from.path())
urn_to = Urn(remote_path_to)
if not self.check(urn_to.parent()):
raise RemoteParentNotFound(urn_to.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn_from.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['move'],
'HTTPHEADER': header(remote_path_to)
}
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例10: download_file
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def download_file(self, remote_path, local_path, progress=None):
try:
urn = Urn(remote_path)
if self.is_dir(urn.path()):
raise OptionNotValid(name="remote_path", value=remote_path)
if os.path.isdir(local_path):
raise OptionNotValid(name="local_path", value=local_path)
if not self.check(urn.path()):
raise RemoteResourceNotFound(urn.path())
with open(local_path, 'wb') as local_file:
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'HTTPHEADER': self.get_header('download_file'),
'WRITEDATA': local_file,
'NOPROGRESS': 0 if progress else 1,
'NOBODY': 0
}
if progress:
options["PROGRESSFUNCTION"] = progress
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例11: upload_from
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def upload_from(self, buff, remote_path):
try:
urn = Urn(remote_path)
if urn.is_dir():
raise OptionNotValid(name="remote_path", value=remote_path)
if not self.check(urn.parent()):
raise RemoteParentNotFound(urn.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'HTTPHEADER': self.get_header('upload_from'),
'UPLOAD': 1,
'READFUNCTION': buff.read,
}
request = self.Request(options=options)
request.perform()
code = request.getinfo(pycurl.HTTP_CODE)
if code == "507":
raise NotEnoughSpace()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例12: download_to
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def download_to(self, buff, remote_path):
try:
urn = Urn(remote_path)
if self.is_dir(urn.path()):
raise OptionNotValid(name="remote_path", value=remote_path)
if not self.check(urn.path()):
raise RemoteResourceNotFound(urn.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'WRITEFUNCTION': buff.write,
'HTTPHEADER': self.get_header('download_to'),
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例13: mkdir
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def mkdir(self, remote_path):
try:
directory_urn = Urn(remote_path, directory=True)
if not self.check(directory_urn.parent()):
raise RemoteParentNotFound(directory_urn.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': directory_urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['mkdir'],
'HTTPHEADER': self.get_header('mkdir')
}
request = self.Request(options=options)
request.perform()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例14: check
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def check(self, remote_path=root):
def parse(response, path):
try:
response_str = response.getvalue()
tree = etree.fromstring(response_str)
resps = tree.findall("{DAV:}response")
for resp in resps:
href = resp.findtext("{DAV:}href")
urn = unquote(href)
if path.endswith(Urn.separate):
if path == urn or path[:-1] == urn:
return True
else:
if path == urn:
return True
return False
except etree.XMLSyntaxError:
raise MethodNotSupported(name="check", server=self.webdav.hostname)
try:
urn = Urn(remote_path)
parent_urn = Urn(urn.parent())
response = BytesIO()
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': parent_urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['info'],
'HTTPHEADER': self.get_header('info'),
'WRITEDATA': response,
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
path = "{root}{path}".format(root=self.webdav.root, path=urn.path())
return parse(response, path)
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例15: list
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import quote [as 别名]
def list(self, remote_path=root):
def parse(response):
try:
response_str = response.getvalue()
tree = etree.fromstring(response_str)
hrees = [unquote(hree.text) for hree in tree.findall(".//{DAV:}href")]
return [Urn(hree) for hree in hrees]
except etree.XMLSyntaxError:
return list()
try:
directory_urn = Urn(remote_path, directory=True)
if directory_urn.path() != Client.root:
if not self.check(directory_urn.path()):
raise RemoteResourceNotFound(directory_urn.path())
response = BytesIO()
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': directory_urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'CUSTOMREQUEST': Client.requests['list'],
'HTTPHEADER': self.get_header('list'),
'WRITEDATA': response,
'NOBODY': 0
}
request = self.Request(options=options)
request.perform()
request.close()
urns = parse(response)
path = "{root}{path}".format(root=self.webdav.root, path=directory_urn.path())
return [urn.filename() for urn in urns if urn.path() != path and urn.path() != path[:-1]]
except pycurl.error:
raise NotConnection(self.webdav.hostname)